@powerlines/plugin-openapi 0.2.235 → 0.2.237

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 (33) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.d.cts +1 -2
  3. package/dist/index.d.mts +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
  6. package/dist/powerlines/src/internal/helpers/hooks.d.mts +47 -0
  7. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
  8. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
  9. package/dist/powerlines/src/types/api.d.cts +104 -0
  10. package/dist/powerlines/src/types/api.d.mts +104 -0
  11. package/dist/powerlines/src/types/build.d.cts +185 -0
  12. package/dist/powerlines/src/types/build.d.mts +185 -0
  13. package/dist/powerlines/src/types/commands.d.cts +8 -0
  14. package/dist/powerlines/src/types/commands.d.mts +8 -0
  15. package/dist/powerlines/src/types/config.d.cts +424 -0
  16. package/dist/powerlines/src/types/config.d.mts +424 -0
  17. package/dist/powerlines/src/types/context.d.cts +514 -0
  18. package/dist/powerlines/src/types/context.d.mts +514 -0
  19. package/dist/powerlines/src/types/fs.d.cts +486 -0
  20. package/dist/powerlines/src/types/fs.d.mts +486 -0
  21. package/dist/powerlines/src/types/hooks.d.cts +32 -0
  22. package/dist/powerlines/src/types/hooks.d.mts +32 -0
  23. package/dist/powerlines/src/types/plugin.d.cts +205 -0
  24. package/dist/powerlines/src/types/plugin.d.mts +205 -0
  25. package/dist/powerlines/src/types/resolved.d.cts +93 -0
  26. package/dist/powerlines/src/types/resolved.d.mts +93 -0
  27. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  28. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  29. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  30. package/dist/powerlines/src/types/unplugin.d.mts +22 -0
  31. package/dist/types/plugin.d.cts +3 -3
  32. package/dist/types/plugin.d.mts +3 -3
  33. package/package.json +7 -7
@@ -0,0 +1,514 @@
1
+ import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.mjs";
2
+ import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
3
+ import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
4
+ import { HooksList, InferHooksListItem } from "./hooks.mjs";
5
+ import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
6
+ import { Plugin } from "./plugin.mjs";
7
+ import { NonUndefined } from "@stryke/types/base";
8
+ import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
9
+ import { EnvPaths } from "@stryke/env/get-env-paths";
10
+ import { FetchRequestOptions } from "@stryke/http/fetch";
11
+ import { PackageJson } from "@stryke/types/package-json";
12
+ import { Jiti } from "jiti";
13
+ import { SourceMap } from "magic-string";
14
+ import { ParseResult, ParserOptions } from "oxc-parser";
15
+ import { Range } from "semver";
16
+ import { RequestInfo, Response } from "undici";
17
+
18
+ //#region ../powerlines/src/types/context.d.ts
19
+
20
+ interface MetaInfo {
21
+ /**
22
+ * The checksum generated from the resolved options
23
+ */
24
+ checksum: string;
25
+ /**
26
+ * The build id
27
+ */
28
+ buildId: string;
29
+ /**
30
+ * The release id
31
+ */
32
+ releaseId: string;
33
+ /**
34
+ * The build timestamp
35
+ */
36
+ timestamp: number;
37
+ /**
38
+ * A hash that represents the path to the project root directory
39
+ */
40
+ projectRootHash: string;
41
+ /**
42
+ * A hash that represents the path to the project root directory
43
+ */
44
+ configHash: string;
45
+ }
46
+ interface Resolver extends Jiti {
47
+ plugin: Jiti;
48
+ }
49
+ interface TransformResult$1 {
50
+ code: string;
51
+ map: SourceMap | null;
52
+ }
53
+ interface SelectHooksOptions {
54
+ order?: "pre" | "post" | "normal";
55
+ }
56
+ /**
57
+ * Options for initializing or updating the context with new configuration values
58
+ */
59
+ interface InitContextOptions {
60
+ /**
61
+ * If false, the plugin will be loaded after all other plugins.
62
+ *
63
+ * @defaultValue true
64
+ */
65
+ isHighPriority: boolean;
66
+ }
67
+ /**
68
+ * Options for fetch requests made via the context's {@link Context.fetch} method
69
+ */
70
+ interface FetchOptions extends FetchRequestOptions {
71
+ /**
72
+ * An indicator specifying that the request should bypass any caching
73
+ */
74
+ skipCache?: boolean;
75
+ }
76
+ /**
77
+ * Options for parsing code using [Oxc-Parser](https://github.com/oxc/oxc)
78
+ */
79
+ interface ParseOptions extends ParserOptions {
80
+ /**
81
+ * When true this allows return statements to be outside functions to e.g. support parsing CommonJS code.
82
+ */
83
+ allowReturnOutsideFunction?: boolean;
84
+ }
85
+ interface EmitOptions extends WriteOptions {
86
+ /**
87
+ * The file extension to use when emitting the file
88
+ */
89
+ extension?: string;
90
+ /**
91
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
92
+ */
93
+ emitWithBundler?: boolean;
94
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
95
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
96
+ }
97
+ /**
98
+ * Options for emitting entry virtual files
99
+ */
100
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
101
+ /**
102
+ * The unresolved Powerlines context.
103
+ *
104
+ * @remarks
105
+ * This context is used before the user configuration has been fully resolved after the `config`.
106
+ */
107
+ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
108
+ /**
109
+ * The Storm workspace configuration
110
+ */
111
+ workspaceConfig: WorkspaceConfig;
112
+ /**
113
+ * An object containing the options provided to Powerlines
114
+ */
115
+ config: Omit<TResolvedConfig["userConfig"], "build" | "output"> & Required<Pick<TResolvedConfig["userConfig"], "build" | "output">> & {
116
+ projectRoot: NonUndefined<TResolvedConfig["userConfig"]["root"]>;
117
+ sourceRoot: NonUndefined<TResolvedConfig["userConfig"]["sourceRoot"]>;
118
+ output: TResolvedConfig["output"];
119
+ };
120
+ /**
121
+ * A logging function for the Powerlines engine
122
+ */
123
+ log: LogFn;
124
+ /**
125
+ * A logging function for fatal messages
126
+ */
127
+ fatal: (message: string | UnpluginMessage) => void;
128
+ /**
129
+ * A logging function for error messages
130
+ */
131
+ error: (message: string | UnpluginMessage) => void;
132
+ /**
133
+ * A logging function for warning messages
134
+ */
135
+ warn: (message: string | UnpluginMessage) => void;
136
+ /**
137
+ * A logging function for informational messages
138
+ */
139
+ info: (message: string | UnpluginMessage) => void;
140
+ /**
141
+ * A logging function for debug messages
142
+ */
143
+ debug: (message: string | UnpluginMessage) => void;
144
+ /**
145
+ * A logging function for trace messages
146
+ */
147
+ trace: (message: string | UnpluginMessage) => void;
148
+ /**
149
+ * The metadata information
150
+ */
151
+ meta: MetaInfo;
152
+ /**
153
+ * The metadata information currently written to disk
154
+ */
155
+ persistedMeta?: MetaInfo;
156
+ /**
157
+ * The Powerlines artifacts directory
158
+ */
159
+ artifactsPath: string;
160
+ /**
161
+ * The path to the Powerlines builtin runtime modules directory
162
+ */
163
+ builtinsPath: string;
164
+ /**
165
+ * The path to the Powerlines entry modules directory
166
+ */
167
+ entryPath: string;
168
+ /**
169
+ * The path to the Powerlines TypeScript declaration files directory
170
+ */
171
+ dtsPath: string;
172
+ /**
173
+ * The path to a directory where the reflection data buffers (used by the build processes) are stored
174
+ */
175
+ dataPath: string;
176
+ /**
177
+ * The path to a directory where the project cache (used by the build processes) is stored
178
+ */
179
+ cachePath: string;
180
+ /**
181
+ * The Powerlines environment paths
182
+ */
183
+ envPaths: EnvPaths;
184
+ /**
185
+ * The file system path to the Powerlines package installation
186
+ */
187
+ powerlinesPath: string;
188
+ /**
189
+ * The relative path to the Powerlines workspace root directory
190
+ */
191
+ relativeToWorkspaceRoot: string;
192
+ /**
193
+ * The project's `package.json` file content
194
+ */
195
+ packageJson: PackageJson & Record<string, any>;
196
+ /**
197
+ * The project's `project.json` file content
198
+ */
199
+ projectJson?: Record<string, any>;
200
+ /**
201
+ * The dependency installations required by the project
202
+ */
203
+ dependencies: Record<string, string | Range>;
204
+ /**
205
+ * The development dependency installations required by the project
206
+ */
207
+ devDependencies: Record<string, string | Range>;
208
+ /**
209
+ * The parsed TypeScript configuration from the `tsconfig.json` file
210
+ */
211
+ tsconfig: ParsedTypeScriptConfig;
212
+ /**
213
+ * The entry points of the source code
214
+ */
215
+ entry: ResolvedEntryTypeDefinition[];
216
+ /**
217
+ * The virtual file system manager used during the build process to reference generated runtime files
218
+ */
219
+ fs: VirtualFileSystemInterface;
220
+ /**
221
+ * The Jiti module resolver
222
+ */
223
+ resolver: Resolver;
224
+ /**
225
+ * The builtin module id that exist in the Powerlines virtual file system
226
+ */
227
+ builtins: string[];
228
+ /**
229
+ * The alias mappings for the project used during module resolution
230
+ *
231
+ * @remarks
232
+ * This includes both the built-in module aliases as well as any custom aliases defined in the build configuration.
233
+ */
234
+ alias: Record<string, string>;
235
+ /**
236
+ * A function to perform HTTP fetch requests
237
+ *
238
+ * @remarks
239
+ * This function uses a caching layer to avoid duplicate requests during the Powerlines process.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * const response = await context.fetch("https://api.example.com/data");
244
+ * const data = await response.json();
245
+ * ```
246
+ *
247
+ * @see https://github.com/nodejs/undici
248
+ *
249
+ * @param input - The URL to fetch.
250
+ * @param options - The fetch request options.
251
+ * @returns A promise that resolves to a response returned by the fetch.
252
+ */
253
+ fetch: (input: RequestInfo, options?: FetchOptions) => Promise<Response>;
254
+ /**
255
+ * Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
256
+ *
257
+ * @remarks
258
+ * This function can be used to parse TypeScript code into an AST for further analysis or transformation.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * const ast = context.parse("const x: number = 42;");
263
+ * ```
264
+ *
265
+ * @see https://rollupjs.org/plugin-development/#this-parse
266
+ * @see https://github.com/oxc/oxc
267
+ *
268
+ * @param code - The source code to parse.
269
+ * @param options - The options to pass to the parser.
270
+ * @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
271
+ */
272
+ parse: (code: string, options?: ParseOptions) => Promise<ParseResult>;
273
+ /**
274
+ * A helper function to resolve modules using the Jiti resolver
275
+ *
276
+ * @remarks
277
+ * This function can be used to resolve modules relative to the project root directory.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
282
+ * ```
283
+ *
284
+ * @param id - The module to resolve.
285
+ * @param importer - An optional path to the importer module.
286
+ * @param options - Additional resolution options.
287
+ * @returns A promise that resolves to the resolved module path.
288
+ */
289
+ resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
290
+ /**
291
+ * A helper function to load modules using the Jiti resolver
292
+ *
293
+ * @remarks
294
+ * This function can be used to load modules relative to the project root directory.
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * const module = await context.load("some-module", "/path/to/importer");
299
+ * ```
300
+ *
301
+ * @param id - The module to load.
302
+ * @returns A promise that resolves to the loaded module.
303
+ */
304
+ load: (id: string) => Promise<TransformResult$1 | undefined>;
305
+ /**
306
+ * The Powerlines builtin virtual files
307
+ */
308
+ getBuiltins: () => Promise<VirtualFile[]>;
309
+ /**
310
+ * Resolves a file and writes it to the VFS if it does not already exist
311
+ *
312
+ * @param code - The source code of the file
313
+ * @param path - The path to write the file to
314
+ * @param options - Additional options for writing the file
315
+ */
316
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
317
+ /**
318
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
319
+ *
320
+ * @param code - The source code of the file
321
+ * @param path - The path to write the file to
322
+ * @param options - Additional options for writing the file
323
+ */
324
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
325
+ /**
326
+ * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
327
+ *
328
+ * @param code - The source code of the builtin file
329
+ * @param id - The unique identifier of the builtin file
330
+ * @param options - Additional options for writing the builtin file
331
+ */
332
+ emitBuiltin: (code: string, id: string, options?: EmitOptions) => Promise<void>;
333
+ /**
334
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
335
+ *
336
+ * @param code - The source code of the builtin file
337
+ * @param id - The unique identifier of the builtin file
338
+ * @param options - Additional options for writing the builtin file
339
+ */
340
+ emitBuiltinSync: (code: string, id: string, options?: EmitOptions) => void;
341
+ /**
342
+ * Resolves a entry virtual file and writes it to the VFS if it does not already exist
343
+ *
344
+ * @param code - The source code of the entry file
345
+ * @param path - An optional path to write the entry file to
346
+ * @param options - Additional options for writing the entry file
347
+ */
348
+ emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
349
+ /**
350
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
351
+ *
352
+ * @param code - The source code of the entry file
353
+ * @param path - An optional path to write the entry file to
354
+ * @param options - Additional options for writing the entry file
355
+ */
356
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
357
+ /**
358
+ * A function to update the context fields using a new user configuration options
359
+ */
360
+ withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
361
+ /**
362
+ * A function to update the context fields using inline configuration options
363
+ */
364
+ withInlineConfig: (inlineConfig: InlineConfig, options?: InitContextOptions) => Promise<void>;
365
+ /**
366
+ * Create a new logger instance
367
+ *
368
+ * @param name - The name to use for the logger instance
369
+ * @returns A logger function
370
+ */
371
+ createLog: (name: string | null) => LogFn;
372
+ /**
373
+ * Extend the current logger instance with a new name
374
+ *
375
+ * @param name - The name to use for the extended logger instance
376
+ * @returns A logger function
377
+ */
378
+ extendLog: (name: string) => LogFn;
379
+ /**
380
+ * Generates a checksum representing the current context state
381
+ *
382
+ * @returns A promise that resolves to a string representing the checksum
383
+ */
384
+ generateChecksum: () => Promise<string>;
385
+ }
386
+ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<UnresolvedContext<TResolvedConfig>, "config"> & {
387
+ /**
388
+ * The fully resolved Powerlines configuration
389
+ */
390
+ config: TResolvedConfig;
391
+ };
392
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
393
+ /**
394
+ * The expected plugins options for the Powerlines project.
395
+ *
396
+ * @remarks
397
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
398
+ */
399
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
400
+ /**
401
+ * A function to add a plugin to the context and update the configuration options
402
+ */
403
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
404
+ /**
405
+ * A table for storing the current context for each configured environment
406
+ */
407
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
408
+ /**
409
+ * Retrieves the context for a specific environment by name
410
+ *
411
+ * @throws Will throw an error if the environment does not exist
412
+ *
413
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
414
+ * @returns A promise that resolves to the environment context.
415
+ *
416
+ * @example
417
+ * ```ts
418
+ * const devEnv = await apiContext.getEnvironment("development");
419
+ * const defaultEnv = await apiContext.getEnvironment();
420
+ * ```
421
+ */
422
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
423
+ /**
424
+ * Safely retrieves the context for a specific environment by name
425
+ *
426
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
427
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
428
+ *
429
+ * @example
430
+ * ```ts
431
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
432
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
433
+ * ```
434
+ *
435
+ * @remarks
436
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
437
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
438
+ *
439
+ * ```ts
440
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
441
+ * if (testEnv) {
442
+ * // Environment exists, safe to use it
443
+ * } else {
444
+ * // Environment does not exist, handle accordingly
445
+ * }
446
+ * ```
447
+ *
448
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
449
+ */
450
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
451
+ /**
452
+ * A function to copy the context and update the fields for a specific environment
453
+ *
454
+ * @param environment - The environment configuration to use.
455
+ * @returns A new context instance with the updated environment.
456
+ */
457
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
458
+ /**
459
+ * A function to merge all configured environments into a single context
460
+ *
461
+ * @returns A promise that resolves to the merged environment context.
462
+ */
463
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
464
+ }
465
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
466
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
467
+ context: PluginContext<TResolvedConfig>;
468
+ }
469
+ type SelectHookResultItem<TContext extends PluginContext, TKey extends string> = InferHooksListItem<TContext, TKey> & {
470
+ context: TContext;
471
+ };
472
+ type SelectHookResult<TContext extends PluginContext, TKey extends string> = SelectHookResultItem<TContext, TKey>[];
473
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
474
+ /**
475
+ * The expected plugins options for the Powerlines project.
476
+ *
477
+ * @remarks
478
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
479
+ */
480
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
481
+ /**
482
+ * A function to add a plugin to the context and update the configuration options
483
+ */
484
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
485
+ /**
486
+ * The environment specific resolved configuration
487
+ */
488
+ environment: EnvironmentResolvedConfig;
489
+ /**
490
+ * A table holding references to hook functions registered by plugins
491
+ */
492
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
493
+ /**
494
+ * Retrieves the hook handlers for a specific hook name
495
+ */
496
+ selectHooks: <TKey extends string>(key: TKey, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey>;
497
+ }
498
+ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
499
+ /**
500
+ * The environment specific resolved configuration
501
+ */
502
+ environment: EnvironmentResolvedConfig;
503
+ /**
504
+ * An alternative property name for the {@link log} property
505
+ *
506
+ * @remarks
507
+ * This is provided for compatibility with other logging libraries that expect a `logger` property.
508
+ */
509
+ logger: LogFn;
510
+ }
511
+ type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
512
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
513
+ //#endregion
514
+ export { APIContext, BuildPluginContext, Context, EnvironmentContext, PluginContext, SelectHooksOptions, UnresolvedContext, WithUnpluginBuildContext };