schemantic 0.1.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +21 -0
  3. package/README.md +827 -0
  4. package/dist/__tests__/setup.d.ts +6 -0
  5. package/dist/__tests__/setup.d.ts.map +1 -0
  6. package/dist/__tests__/setup.js +30 -0
  7. package/dist/__tests__/setup.js.map +1 -0
  8. package/dist/__tests__/test-config.d.ts +36 -0
  9. package/dist/__tests__/test-config.d.ts.map +1 -0
  10. package/dist/__tests__/test-config.js +563 -0
  11. package/dist/__tests__/test-config.js.map +1 -0
  12. package/dist/cli/index.d.ts +118 -0
  13. package/dist/cli/index.d.ts.map +1 -0
  14. package/dist/cli/index.js +657 -0
  15. package/dist/cli/index.js.map +1 -0
  16. package/dist/core/index.d.ts +5 -0
  17. package/dist/core/index.d.ts.map +1 -0
  18. package/dist/core/index.js +21 -0
  19. package/dist/core/index.js.map +1 -0
  20. package/dist/core/schemantic.d.ts +95 -0
  21. package/dist/core/schemantic.d.ts.map +1 -0
  22. package/dist/core/schemantic.js +543 -0
  23. package/dist/core/schemantic.js.map +1 -0
  24. package/dist/generators/api-client-generator.d.ts +145 -0
  25. package/dist/generators/api-client-generator.d.ts.map +1 -0
  26. package/dist/generators/api-client-generator.js +856 -0
  27. package/dist/generators/api-client-generator.js.map +1 -0
  28. package/dist/generators/base.d.ts +117 -0
  29. package/dist/generators/base.d.ts.map +1 -0
  30. package/dist/generators/base.js +232 -0
  31. package/dist/generators/base.js.map +1 -0
  32. package/dist/generators/enum-generator.d.ts +52 -0
  33. package/dist/generators/enum-generator.d.ts.map +1 -0
  34. package/dist/generators/enum-generator.js +178 -0
  35. package/dist/generators/enum-generator.js.map +1 -0
  36. package/dist/generators/factory.d.ts +59 -0
  37. package/dist/generators/factory.d.ts.map +1 -0
  38. package/dist/generators/factory.js +127 -0
  39. package/dist/generators/factory.js.map +1 -0
  40. package/dist/generators/hook-generator.d.ts +36 -0
  41. package/dist/generators/hook-generator.d.ts.map +1 -0
  42. package/dist/generators/hook-generator.js +495 -0
  43. package/dist/generators/hook-generator.js.map +1 -0
  44. package/dist/generators/index.d.ts +10 -0
  45. package/dist/generators/index.d.ts.map +1 -0
  46. package/dist/generators/index.js +26 -0
  47. package/dist/generators/index.js.map +1 -0
  48. package/dist/generators/object-generator.d.ts +48 -0
  49. package/dist/generators/object-generator.d.ts.map +1 -0
  50. package/dist/generators/object-generator.js +280 -0
  51. package/dist/generators/object-generator.js.map +1 -0
  52. package/dist/generators/primitive-generator.d.ts +40 -0
  53. package/dist/generators/primitive-generator.d.ts.map +1 -0
  54. package/dist/generators/primitive-generator.js +150 -0
  55. package/dist/generators/primitive-generator.js.map +1 -0
  56. package/dist/index.d.ts +17 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +42 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/parsers/base.d.ts +101 -0
  61. package/dist/parsers/base.d.ts.map +1 -0
  62. package/dist/parsers/base.js +77 -0
  63. package/dist/parsers/base.js.map +1 -0
  64. package/dist/parsers/factory.d.ts +64 -0
  65. package/dist/parsers/factory.d.ts.map +1 -0
  66. package/dist/parsers/factory.js +116 -0
  67. package/dist/parsers/factory.js.map +1 -0
  68. package/dist/parsers/index.d.ts +7 -0
  69. package/dist/parsers/index.d.ts.map +1 -0
  70. package/dist/parsers/index.js +23 -0
  71. package/dist/parsers/index.js.map +1 -0
  72. package/dist/parsers/openapi.d.ts +52 -0
  73. package/dist/parsers/openapi.d.ts.map +1 -0
  74. package/dist/parsers/openapi.js +396 -0
  75. package/dist/parsers/openapi.js.map +1 -0
  76. package/dist/plugins/branded-types.d.ts +28 -0
  77. package/dist/plugins/branded-types.d.ts.map +1 -0
  78. package/dist/plugins/branded-types.js +568 -0
  79. package/dist/plugins/branded-types.js.map +1 -0
  80. package/dist/plugins/builtin.d.ts +38 -0
  81. package/dist/plugins/builtin.d.ts.map +1 -0
  82. package/dist/plugins/builtin.js +283 -0
  83. package/dist/plugins/builtin.js.map +1 -0
  84. package/dist/plugins/index.d.ts +7 -0
  85. package/dist/plugins/index.d.ts.map +1 -0
  86. package/dist/plugins/index.js +23 -0
  87. package/dist/plugins/index.js.map +1 -0
  88. package/dist/plugins/loader.d.ts +92 -0
  89. package/dist/plugins/loader.d.ts.map +1 -0
  90. package/dist/plugins/loader.js +245 -0
  91. package/dist/plugins/loader.js.map +1 -0
  92. package/dist/plugins/manager.d.ts +99 -0
  93. package/dist/plugins/manager.d.ts.map +1 -0
  94. package/dist/plugins/manager.js +233 -0
  95. package/dist/plugins/manager.js.map +1 -0
  96. package/dist/plugins/performance-monitoring.d.ts +98 -0
  97. package/dist/plugins/performance-monitoring.d.ts.map +1 -0
  98. package/dist/plugins/performance-monitoring.js +596 -0
  99. package/dist/plugins/performance-monitoring.js.map +1 -0
  100. package/dist/plugins/request-deduplication.d.ts +27 -0
  101. package/dist/plugins/request-deduplication.d.ts.map +1 -0
  102. package/dist/plugins/request-deduplication.js +650 -0
  103. package/dist/plugins/request-deduplication.js.map +1 -0
  104. package/dist/plugins/zod-validation.d.ts +63 -0
  105. package/dist/plugins/zod-validation.d.ts.map +1 -0
  106. package/dist/plugins/zod-validation.js +743 -0
  107. package/dist/plugins/zod-validation.js.map +1 -0
  108. package/dist/types/core.d.ts +203 -0
  109. package/dist/types/core.d.ts.map +1 -0
  110. package/dist/types/core.js +24 -0
  111. package/dist/types/core.js.map +1 -0
  112. package/dist/types/index.d.ts +7 -0
  113. package/dist/types/index.d.ts.map +1 -0
  114. package/dist/types/index.js +23 -0
  115. package/dist/types/index.js.map +1 -0
  116. package/dist/types/openapi.d.ts +250 -0
  117. package/dist/types/openapi.d.ts.map +1 -0
  118. package/dist/types/openapi.js +8 -0
  119. package/dist/types/openapi.js.map +1 -0
  120. package/dist/types/schema.d.ts +68 -0
  121. package/dist/types/schema.d.ts.map +1 -0
  122. package/dist/types/schema.js +22 -0
  123. package/dist/types/schema.js.map +1 -0
  124. package/docs/ADVANCED_PLUGINS_IMPLEMENTATION.md +355 -0
  125. package/docs/ADVANCED_PLUGIN_DEVELOPMENT.md +309 -0
  126. package/docs/API.md +600 -0
  127. package/docs/CONFIGURATION.md +722 -0
  128. package/docs/FASTAPI_TUTORIAL.md +1497 -0
  129. package/docs/PLUGINS.md +683 -0
  130. package/docs/PLUGIN_DEVELOPMENT.md +720 -0
  131. package/package.json +90 -0
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ /**
3
+ * Built-in plugins for common transformations and enhancements
4
+ * Provides standard plugins that can be used out of the box
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.strictModePlugin = exports.reactHooksPlugin = exports.validationPlugin = exports.jsdocPlugin = void 0;
11
+ exports.getBuiltinPlugins = getBuiltinPlugins;
12
+ exports.getBasicBuiltinPlugins = getBasicBuiltinPlugins;
13
+ exports.getAdvancedBuiltinPlugins = getAdvancedBuiltinPlugins;
14
+ exports.getBuiltinPlugin = getBuiltinPlugin;
15
+ const schema_1 = require("../types/schema");
16
+ // Import advanced plugins
17
+ const zod_validation_1 = __importDefault(require("./zod-validation"));
18
+ const performance_monitoring_1 = __importDefault(require("./performance-monitoring"));
19
+ const request_deduplication_1 = __importDefault(require("./request-deduplication"));
20
+ const branded_types_1 = __importDefault(require("./branded-types"));
21
+ /**
22
+ * Built-in plugin for adding JSDoc comments
23
+ */
24
+ exports.jsdocPlugin = {
25
+ name: "jsdoc",
26
+ version: "1.0.0",
27
+ description: "Adds JSDoc comments to generated types and methods",
28
+ beforeTypeGeneration: async (_typeName, schema, _context) => {
29
+ // Add description to schema if not present
30
+ if ((0, schema_1.isOpenAPISchemaObject)(schema) && !schema.description && schema.title) {
31
+ schema.description = `Type definition for ${schema.title}`;
32
+ }
33
+ },
34
+ afterTypeGeneration: async (typeName, generatedType, _context) => {
35
+ // Add JSDoc comment if not present
36
+ if (!generatedType.content.includes("/**")) {
37
+ const description = (0, schema_1.isOpenAPISchemaObject)(generatedType.sourceSchema)
38
+ ? generatedType.sourceSchema.description
39
+ : undefined;
40
+ const comment = `/**\n * ${description || `Generated type: ${typeName}`}\n */\n`;
41
+ generatedType.content = comment + generatedType.content;
42
+ }
43
+ },
44
+ afterClientGeneration: async (generatedClient, context) => {
45
+ // Add JSDoc comment to client class
46
+ if (!generatedClient.content.includes("/**")) {
47
+ const comment = `/**\n * Generated API client\n * @description ${context.schema.info?.description || "Auto-generated from OpenAPI schema"}\n */\n`;
48
+ generatedClient.content = comment + generatedClient.content;
49
+ }
50
+ },
51
+ };
52
+ /**
53
+ * Built-in plugin for adding validation decorators
54
+ */
55
+ exports.validationPlugin = {
56
+ name: "validation",
57
+ version: "1.0.0",
58
+ description: "Adds validation decorators to generated types",
59
+ transformSchema: (schema, _context) => {
60
+ // Add validation metadata to schema
61
+ if ((0, schema_1.isOpenAPISchemaObject)(schema) && schema.properties) {
62
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
63
+ if (typeof propSchema === "object" &&
64
+ propSchema !== null &&
65
+ (0, schema_1.isOpenAPISchemaObject)(propSchema)) {
66
+ // Add validation metadata
67
+ const meta = {
68
+ required: schema.required?.includes(propName) || false,
69
+ };
70
+ if (propSchema.minLength !== undefined)
71
+ meta.minLength = propSchema.minLength;
72
+ if (propSchema.maxLength !== undefined)
73
+ meta.maxLength = propSchema.maxLength;
74
+ if (propSchema.minimum !== undefined)
75
+ meta.minimum = propSchema.minimum;
76
+ if (propSchema.maximum !== undefined)
77
+ meta.maximum = propSchema.maximum;
78
+ if (propSchema.pattern !== undefined)
79
+ meta.pattern = propSchema.pattern;
80
+ if (propSchema.format !== undefined)
81
+ meta.format = propSchema.format;
82
+ propSchema._validationMetadata = meta;
83
+ }
84
+ }
85
+ }
86
+ return schema;
87
+ },
88
+ afterTypeGeneration: async (_typeName, generatedType, _context) => {
89
+ // Add validation decorators to generated type
90
+ if (generatedType.isInterface &&
91
+ (0, schema_1.isOpenAPISchemaObject)(generatedType.sourceSchema) &&
92
+ generatedType.sourceSchema.properties) {
93
+ let content = generatedType.content;
94
+ // Add validation imports
95
+ const validationImports = `import { IsString, IsNumber, IsBoolean, IsOptional, IsNotEmpty, MinLength, MaxLength, Min, Max, Matches } from 'class-validator';\n\n`;
96
+ // Add validation decorators to properties
97
+ const lines = content.split("\n");
98
+ const newLines = [];
99
+ for (let i = 0; i < lines.length; i++) {
100
+ const line = lines[i];
101
+ newLines.push(line);
102
+ // Check if this is a property line
103
+ if (line.includes(":") &&
104
+ !line.includes("export") &&
105
+ !line.includes("interface")) {
106
+ const propName = line.split(":")[0]?.trim();
107
+ if (propName) {
108
+ const validationDecorators = generateValidationDecorators(propName, generatedType.sourceSchema);
109
+ if (validationDecorators) {
110
+ newLines.push(validationDecorators);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ generatedType.content = validationImports + newLines.join("\n");
116
+ }
117
+ },
118
+ };
119
+ // Helper function to generate validation decorators
120
+ function generateValidationDecorators(propName, schema) {
121
+ if (!(0, schema_1.isOpenAPISchemaObject)(schema) || !schema.properties) {
122
+ return undefined;
123
+ }
124
+ const propSchema = schema.properties[propName];
125
+ if (!propSchema ||
126
+ typeof propSchema !== "object" ||
127
+ !(0, schema_1.isOpenAPISchemaObject)(propSchema)) {
128
+ return undefined;
129
+ }
130
+ const decorators = [];
131
+ // Add type decorators
132
+ if (propSchema.type === "string") {
133
+ decorators.push("@IsString()");
134
+ }
135
+ else if (propSchema.type === "number" || propSchema.type === "integer") {
136
+ decorators.push("@IsNumber()");
137
+ }
138
+ else if (propSchema.type === "boolean") {
139
+ decorators.push("@IsBoolean()");
140
+ }
141
+ // Add validation decorators
142
+ if (propSchema.minLength !== undefined) {
143
+ decorators.push(`@MinLength(${propSchema.minLength})`);
144
+ }
145
+ if (propSchema.maxLength !== undefined) {
146
+ decorators.push(`@MaxLength(${propSchema.maxLength})`);
147
+ }
148
+ if (propSchema.minimum !== undefined) {
149
+ decorators.push(`@Min(${propSchema.minimum})`);
150
+ }
151
+ if (propSchema.maximum !== undefined) {
152
+ decorators.push(`@Max(${propSchema.maximum})`);
153
+ }
154
+ if (propSchema.pattern) {
155
+ decorators.push(`@Matches(/${propSchema.pattern}/)`);
156
+ }
157
+ // Add optional decorator
158
+ if (propSchema._validationMetadata?.required === false) {
159
+ decorators.push("@IsOptional()");
160
+ }
161
+ else {
162
+ decorators.push("@IsNotEmpty()");
163
+ }
164
+ return decorators.map((d) => ` ${d}`).join("\n");
165
+ }
166
+ /**
167
+ * Built-in plugin for adding React hooks generation
168
+ */
169
+ exports.reactHooksPlugin = {
170
+ name: "react-hooks",
171
+ version: "1.0.0",
172
+ description: "Generates React hooks for API endpoints",
173
+ customClientGenerators: {
174
+ "react-hooks": (context) => {
175
+ const schema = context.schema;
176
+ const clientName = "ApiHooks";
177
+ // Generate React hooks for each endpoint
178
+ const hooks = generateReactHooks(schema, context);
179
+ const content = `import { useQuery, useMutation, useQueryClient } from 'react-query';\nimport { ApiClient } from './api-client';\n\n${hooks}`;
180
+ return {
181
+ name: clientName,
182
+ content,
183
+ dependencies: ["react-query"],
184
+ exports: [clientName],
185
+ endpoints: [], // Hooks don't have traditional endpoints
186
+ };
187
+ },
188
+ },
189
+ };
190
+ // Helper function to generate React hooks
191
+ function generateReactHooks(_schema, _context) {
192
+ let hooks = "";
193
+ // This would be implemented to generate actual React hooks
194
+ // For now, return a placeholder
195
+ hooks += `export const useApiHooks = (client: ApiClient) => {\n`;
196
+ hooks += ` // Generated hooks will be here\n`;
197
+ hooks += ` return {\n`;
198
+ hooks += ` // Hook methods\n`;
199
+ hooks += ` };\n`;
200
+ hooks += `};\n`;
201
+ return hooks;
202
+ }
203
+ /**
204
+ * Built-in plugin for adding TypeScript strict mode enhancements
205
+ */
206
+ exports.strictModePlugin = {
207
+ name: "strict-mode",
208
+ version: "1.0.0",
209
+ description: "Adds TypeScript strict mode enhancements",
210
+ transformSchema: (schema, _context) => {
211
+ // Add strict type information
212
+ if ((0, schema_1.isOpenAPISchemaObject)(schema) && schema.properties) {
213
+ for (const [propName, propSchema] of Object.entries(schema.properties)) {
214
+ if (typeof propSchema === "object" &&
215
+ propSchema !== null &&
216
+ (0, schema_1.isOpenAPISchemaObject)(propSchema)) {
217
+ // Mark as strict type
218
+ propSchema._isStrictType = true;
219
+ // Add null/undefined handling
220
+ if (propSchema.nullable) {
221
+ propSchema._isNullable = true;
222
+ }
223
+ if (!schema.required?.includes(propName)) {
224
+ propSchema._isOptional = true;
225
+ }
226
+ }
227
+ }
228
+ }
229
+ return schema;
230
+ },
231
+ afterTypeGeneration: async (_typeName, generatedType, _context) => {
232
+ // Add strict type annotations
233
+ if (generatedType.isInterface) {
234
+ let content = generatedType.content;
235
+ // Add strict type imports
236
+ const strictImports = `import { StrictType, Optional, Nullable } from './strict-types';\n\n`;
237
+ // Add strict type annotations
238
+ content = strictImports + content;
239
+ generatedType.content = content;
240
+ }
241
+ },
242
+ };
243
+ /**
244
+ * Get all built-in plugins (including advanced plugins)
245
+ */
246
+ function getBuiltinPlugins() {
247
+ return [
248
+ // Basic plugins
249
+ exports.jsdocPlugin,
250
+ exports.validationPlugin,
251
+ exports.reactHooksPlugin,
252
+ exports.strictModePlugin,
253
+ // Advanced plugins
254
+ zod_validation_1.default,
255
+ performance_monitoring_1.default,
256
+ request_deduplication_1.default,
257
+ branded_types_1.default,
258
+ ];
259
+ }
260
+ /**
261
+ * Get basic built-in plugins only
262
+ */
263
+ function getBasicBuiltinPlugins() {
264
+ return [exports.jsdocPlugin, exports.validationPlugin, exports.reactHooksPlugin, exports.strictModePlugin];
265
+ }
266
+ /**
267
+ * Get advanced built-in plugins only
268
+ */
269
+ function getAdvancedBuiltinPlugins() {
270
+ return [
271
+ zod_validation_1.default,
272
+ performance_monitoring_1.default,
273
+ request_deduplication_1.default,
274
+ branded_types_1.default,
275
+ ];
276
+ }
277
+ /**
278
+ * Get built-in plugin by name
279
+ */
280
+ function getBuiltinPlugin(name) {
281
+ return getBuiltinPlugins().find((plugin) => plugin.name === name);
282
+ }
283
+ //# sourceMappingURL=builtin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin.js","sourceRoot":"","sources":["../../src/plugins/builtin.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAgVH,8CAcC;AAKD,wDAEC;AAKD,8DAOC;AAKD,4CAEC;AAhXD,4CAIyB;AAGzB,0BAA0B;AAC1B,sEAAmD;AACnD,sFAAmE;AACnE,oFAAiE;AACjE,oEAAiD;AAEjD;;GAEG;AACU,QAAA,WAAW,GAAqB;IAC3C,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,oDAAoD;IAEjE,oBAAoB,EAAE,KAAK,EACzB,SAAiB,EACjB,MAAsB,EACtB,QAA2B,EAC3B,EAAE;QACF,2CAA2C;QAC3C,IAAI,IAAA,8BAAqB,EAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAEvE,MACD,CAAC,WAAW,GAAG,uBAAuB,MAAM,CAAC,KAAK,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;IAED,mBAAmB,EAAE,KAAK,EACxB,QAAgB,EAChB,aAA4B,EAC5B,QAA2B,EAC3B,EAAE;QACF,mCAAmC;QACnC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,MAAM,WAAW,GAAG,IAAA,8BAAqB,EAAC,aAAa,CAAC,YAAY,CAAC;gBACnE,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,WAAW;gBACxC,CAAC,CAAC,SAAS,CAAC;YACd,MAAM,OAAO,GAAG,WACd,WAAW,IAAI,mBAAmB,QAAQ,EAC5C,SAAS,CAAC;YACV,aAAa,CAAC,OAAO,GAAG,OAAO,GAAG,aAAa,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AAsB;IACpC,OAAO,CAAC,mBAAW,EAAE,wBAAgB,EAAE,wBAAgB,EAAE,wBAAgB,CAAC,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB;IACvC,OAAO;QACL,wBAAmB;QACnB,gCAA2B;QAC3B,+BAA0B;QAC1B,uBAAkB;KACnB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Plugin module exports
3
+ */
4
+ export * from './manager';
5
+ export * from './loader';
6
+ export * from './builtin';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Plugin module exports
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./manager"), exports);
21
+ __exportStar(require("./loader"), exports);
22
+ __exportStar(require("./builtin"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Plugin loader for dynamic plugin loading
3
+ * Handles loading plugins from various sources (files, packages, etc.)
4
+ */
5
+ import { SchemanticPlugin } from "../types/core";
6
+ /**
7
+ * Plugin loader class
8
+ */
9
+ export declare class PluginLoader {
10
+ private loadedPlugins;
11
+ /**
12
+ * Load plugin from file path
13
+ */
14
+ loadPluginFromFile(filePath: string): Promise<SchemanticPlugin>;
15
+ /**
16
+ * Load plugin from package
17
+ */
18
+ loadPluginFromPackage(packageName: string): Promise<SchemanticPlugin>;
19
+ /**
20
+ * Load plugins from directory
21
+ */
22
+ loadPluginsFromDirectory(directoryPath: string): Promise<SchemanticPlugin[]>;
23
+ /**
24
+ * Load plugin from object
25
+ */
26
+ loadPluginFromObject(plugin: SchemanticPlugin): SchemanticPlugin;
27
+ /**
28
+ * Extract plugin from module
29
+ */
30
+ private extractPluginFromModule;
31
+ /**
32
+ * Check if object is a valid plugin
33
+ */
34
+ private isValidPlugin;
35
+ /**
36
+ * Validate plugin
37
+ */
38
+ private validatePlugin;
39
+ /**
40
+ * Get loaded plugin
41
+ */
42
+ getLoadedPlugin(name: string): SchemanticPlugin | undefined;
43
+ /**
44
+ * Get all loaded plugins
45
+ */
46
+ getAllLoadedPlugins(): SchemanticPlugin[];
47
+ /**
48
+ * Clear loaded plugins
49
+ */
50
+ clear(): void;
51
+ /**
52
+ * Get loading statistics
53
+ */
54
+ getStatistics(): LoadingStatistics;
55
+ }
56
+ /**
57
+ * Loading statistics
58
+ */
59
+ export interface LoadingStatistics {
60
+ loadedPlugins: number;
61
+ pluginNames: string[];
62
+ }
63
+ /**
64
+ * Plugin loading options
65
+ */
66
+ export interface PluginLoadingOptions {
67
+ /**
68
+ * Whether to continue loading other plugins if one fails
69
+ */
70
+ continueOnError?: boolean;
71
+ /**
72
+ * Whether to validate plugins after loading
73
+ */
74
+ validate?: boolean;
75
+ /**
76
+ * Custom validation function
77
+ */
78
+ customValidator?: (plugin: SchemanticPlugin) => boolean;
79
+ }
80
+ /**
81
+ * Convenience function to load plugin from file
82
+ */
83
+ export declare function loadPluginFromFile(filePath: string): Promise<SchemanticPlugin>;
84
+ /**
85
+ * Convenience function to load plugin from package
86
+ */
87
+ export declare function loadPluginFromPackage(packageName: string): Promise<SchemanticPlugin>;
88
+ /**
89
+ * Convenience function to load plugins from directory
90
+ */
91
+ export declare function loadPluginsFromDirectory(directoryPath: string): Promise<SchemanticPlugin[]>;
92
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAA4C;IAEjE;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BrE;;OAEG;IACG,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0B3E;;OAEG;IACG,wBAAwB,CAC5B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,gBAAgB,EAAE,CAAC;IA+B9B;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB;IAUhE;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAwC/B;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,OAAO,CAAC,cAAc;IAmBtB;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI3D;;OAEG;IACH,mBAAmB,IAAI,gBAAgB,EAAE;IAIzC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,aAAa,IAAI,iBAAiB;CAMnC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC;CACzD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAG7B"}
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * Plugin loader for dynamic plugin loading
4
+ * Handles loading plugins from various sources (files, packages, etc.)
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.PluginLoader = void 0;
41
+ exports.loadPluginFromFile = loadPluginFromFile;
42
+ exports.loadPluginFromPackage = loadPluginFromPackage;
43
+ exports.loadPluginsFromDirectory = loadPluginsFromDirectory;
44
+ const fs = __importStar(require("fs/promises"));
45
+ const path = __importStar(require("path"));
46
+ /**
47
+ * Plugin loader class
48
+ */
49
+ class PluginLoader {
50
+ constructor() {
51
+ this.loadedPlugins = new Map();
52
+ }
53
+ /**
54
+ * Load plugin from file path
55
+ */
56
+ async loadPluginFromFile(filePath) {
57
+ try {
58
+ // Check if file exists
59
+ await fs.access(filePath);
60
+ // Load the module
61
+ const pluginModule = await Promise.resolve(`${path.resolve(filePath)}`).then(s => __importStar(require(s)));
62
+ // Extract plugin from module
63
+ const plugin = this.extractPluginFromModule(pluginModule);
64
+ if (!plugin) {
65
+ throw new Error(`No valid plugin found in ${filePath}`);
66
+ }
67
+ // Validate plugin
68
+ this.validatePlugin(plugin);
69
+ // Store loaded plugin
70
+ this.loadedPlugins.set(plugin.name, plugin);
71
+ return plugin;
72
+ }
73
+ catch (error) {
74
+ throw new Error(`Failed to load plugin from ${filePath}: ${error}`);
75
+ }
76
+ }
77
+ /**
78
+ * Load plugin from package
79
+ */
80
+ async loadPluginFromPackage(packageName) {
81
+ try {
82
+ // Load the package
83
+ const pluginModule = await Promise.resolve(`${packageName}`).then(s => __importStar(require(s)));
84
+ // Extract plugin from module
85
+ const plugin = this.extractPluginFromModule(pluginModule);
86
+ if (!plugin) {
87
+ throw new Error(`No valid plugin found in package ${packageName}`);
88
+ }
89
+ // Validate plugin
90
+ this.validatePlugin(plugin);
91
+ // Store loaded plugin
92
+ this.loadedPlugins.set(plugin.name, plugin);
93
+ return plugin;
94
+ }
95
+ catch (error) {
96
+ throw new Error(`Failed to load plugin from package ${packageName}: ${error}`);
97
+ }
98
+ }
99
+ /**
100
+ * Load plugins from directory
101
+ */
102
+ async loadPluginsFromDirectory(directoryPath) {
103
+ try {
104
+ const plugins = [];
105
+ // Read directory contents
106
+ const entries = await fs.readdir(directoryPath, { withFileTypes: true });
107
+ for (const entry of entries) {
108
+ if (entry.isFile() &&
109
+ (entry.name.endsWith(".js") || entry.name.endsWith(".ts"))) {
110
+ const filePath = path.join(directoryPath, entry.name);
111
+ try {
112
+ const plugin = await this.loadPluginFromFile(filePath);
113
+ plugins.push(plugin);
114
+ }
115
+ catch (error) {
116
+ console.warn(`Failed to load plugin from ${filePath}:`, error);
117
+ }
118
+ }
119
+ }
120
+ return plugins;
121
+ }
122
+ catch (error) {
123
+ throw new Error(`Failed to load plugins from directory ${directoryPath}: ${error}`);
124
+ }
125
+ }
126
+ /**
127
+ * Load plugin from object
128
+ */
129
+ loadPluginFromObject(plugin) {
130
+ // Validate plugin
131
+ this.validatePlugin(plugin);
132
+ // Store loaded plugin
133
+ this.loadedPlugins.set(plugin.name, plugin);
134
+ return plugin;
135
+ }
136
+ /**
137
+ * Extract plugin from module
138
+ */
139
+ extractPluginFromModule(module) {
140
+ // Try different export patterns
141
+ if (typeof module === "object" &&
142
+ module !== null &&
143
+ "default" in module &&
144
+ this.isValidPlugin(module.default)) {
145
+ return module.default;
146
+ }
147
+ if (typeof module === "object" &&
148
+ module !== null &&
149
+ "plugin" in module &&
150
+ this.isValidPlugin(module.plugin)) {
151
+ return module.plugin;
152
+ }
153
+ if (this.isValidPlugin(module)) {
154
+ return module;
155
+ }
156
+ // Look for plugin in exports
157
+ if (typeof module === "object" && module !== null) {
158
+ for (const [, value] of Object.entries(module)) {
159
+ if (this.isValidPlugin(value)) {
160
+ return value;
161
+ }
162
+ }
163
+ }
164
+ return undefined;
165
+ }
166
+ /**
167
+ * Check if object is a valid plugin
168
+ */
169
+ isValidPlugin(obj) {
170
+ if (!obj || typeof obj !== "object")
171
+ return false;
172
+ const maybe = obj;
173
+ return (typeof maybe.name === "string" &&
174
+ typeof maybe.version === "string" &&
175
+ typeof maybe.description === "string");
176
+ }
177
+ /**
178
+ * Validate plugin
179
+ */
180
+ validatePlugin(plugin) {
181
+ if (!plugin.name || typeof plugin.name !== "string") {
182
+ throw new Error("Plugin must have a valid name");
183
+ }
184
+ if (!plugin.version || typeof plugin.version !== "string") {
185
+ throw new Error("Plugin must have a valid version");
186
+ }
187
+ if (!plugin.description || typeof plugin.description !== "string") {
188
+ throw new Error("Plugin must have a valid description");
189
+ }
190
+ // Check for duplicate names
191
+ if (this.loadedPlugins.has(plugin.name)) {
192
+ throw new Error(`Plugin with name '${plugin.name}' is already loaded`);
193
+ }
194
+ }
195
+ /**
196
+ * Get loaded plugin
197
+ */
198
+ getLoadedPlugin(name) {
199
+ return this.loadedPlugins.get(name);
200
+ }
201
+ /**
202
+ * Get all loaded plugins
203
+ */
204
+ getAllLoadedPlugins() {
205
+ return Array.from(this.loadedPlugins.values());
206
+ }
207
+ /**
208
+ * Clear loaded plugins
209
+ */
210
+ clear() {
211
+ this.loadedPlugins.clear();
212
+ }
213
+ /**
214
+ * Get loading statistics
215
+ */
216
+ getStatistics() {
217
+ return {
218
+ loadedPlugins: this.loadedPlugins.size,
219
+ pluginNames: Array.from(this.loadedPlugins.keys()),
220
+ };
221
+ }
222
+ }
223
+ exports.PluginLoader = PluginLoader;
224
+ /**
225
+ * Convenience function to load plugin from file
226
+ */
227
+ async function loadPluginFromFile(filePath) {
228
+ const loader = new PluginLoader();
229
+ return loader.loadPluginFromFile(filePath);
230
+ }
231
+ /**
232
+ * Convenience function to load plugin from package
233
+ */
234
+ async function loadPluginFromPackage(packageName) {
235
+ const loader = new PluginLoader();
236
+ return loader.loadPluginFromPackage(packageName);
237
+ }
238
+ /**
239
+ * Convenience function to load plugins from directory
240
+ */
241
+ async function loadPluginsFromDirectory(directoryPath) {
242
+ const loader = new PluginLoader();
243
+ return loader.loadPluginsFromDirectory(directoryPath);
244
+ }
245
+ //# sourceMappingURL=loader.js.map