@baeta/generator-sdk 2.0.0-next.3 → 2.0.0-next.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @baeta/generator-sdk
2
2
 
3
+ ## 2.0.0-next.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#389](https://github.com/andreisergiu98/baeta/pull/389) [`3e7a4d7`](https://github.com/andreisergiu98/baeta/commit/3e7a4d71a59543b8a506938f788aec8b5d907776) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Add support for Apollo Federation
8
+
9
+ - Updated dependencies [[`3e7a4d7`](https://github.com/andreisergiu98/baeta/commit/3e7a4d71a59543b8a506938f788aec8b5d907776), [`53322ca`](https://github.com/andreisergiu98/baeta/commit/53322ca8ad0c10bce70e49692d5d15023ec3a5e8)]:
10
+ - @baeta/util-path@2.0.0-next.4
11
+
12
+ ## 2.0.0-next.4
13
+
14
+ ### Patch Changes
15
+
16
+ - [`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Fix generator overwriting types.ts file
17
+
18
+ - Updated dependencies [[`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008), [`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008)]:
19
+ - @baeta/plugin@2.0.0-next.3
20
+ - @baeta/util-path@2.0.0-next.3
21
+
3
22
  ## 2.0.0-next.3
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <div align="center">
6
6
  <h1>Baeta</h1>
7
7
  <a href="https://www.npmjs.com/package/@baeta/cli"><img src="https://img.shields.io/npm/v/@baeta/cli.svg?style=flat" /></a>
8
- <a href="https://github.com/andreisergiu98/baeta/actions/workflows/testing.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/testing.yml" /></a>
8
+ <a href="https://github.com/andreisergiu98/baeta/actions/workflows/checks.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/checks.yml" /></a>
9
9
  <a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
10
10
  <a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
11
11
  <br />
@@ -103,7 +103,7 @@ import { UserModule } from "./typedef.ts";
103
103
  const { Query } = UserModule;
104
104
 
105
105
  const userQuery = Query.user
106
- .auth({
106
+ .$auth({
107
107
  $or: {
108
108
  isPublic: true,
109
109
  isLoggedIn: true,
@@ -122,16 +122,16 @@ const { Query, Mutation, User } = UserModule;
122
122
  export const userCache = User.$createCache();
123
123
 
124
124
  const userQuery = Query.user
125
- .auth({
125
+ .$auth({
126
126
  // ...
127
127
  })
128
- .useCache(userCache)
128
+ .$useCache(userCache)
129
129
  .resolve(async ({ args }) => {
130
130
  // ...
131
131
  });
132
132
 
133
133
  const updateUserMutation = Mutation.updateUser
134
- .use(async (next) => {
134
+ .$use(async (next) => {
135
135
  const user = await next();
136
136
  await userCache.save(user);
137
137
  return user;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PluginType } from "@baeta/plugin";
2
2
  import { Event, EventType, Options } from "@parcel/watcher";
3
3
  import micromatch from "micromatch";
4
- import * as fs_promises0 from "fs/promises";
4
+ import * as _$fs_promises0 from "fs/promises";
5
5
 
6
6
  //#region lib/file.d.ts
7
7
  /**
@@ -29,10 +29,10 @@ interface FileOptions {
29
29
  */
30
30
  disableBiomeV2Header?: boolean;
31
31
  /**
32
- * Allow overwriting the file.
33
- * @defaultValue true
32
+ * Disallow overwriting the file.
33
+ * @defaultValue false
34
34
  */
35
- allowOverwrite?: boolean;
35
+ disableOverwrite?: boolean;
36
36
  /**
37
37
  * Add custom header at the beginning of the file.
38
38
  */
@@ -44,10 +44,10 @@ interface FileOptions {
44
44
  }
45
45
  declare class File {
46
46
  persisted: boolean;
47
- filename: string;
48
- content: string;
49
- tag: string;
50
- private options?;
47
+ readonly filename: string;
48
+ readonly content: string;
49
+ readonly tag: string;
50
+ readonly options?: FileOptions;
51
51
  constructor(filename: string, content: string, tag: string, options?: FileOptions);
52
52
  write: () => Promise<void>;
53
53
  unlink: () => Promise<void>;
@@ -60,10 +60,9 @@ declare class File {
60
60
  /**
61
61
  * Interface for custom schema loaders.
62
62
  */
63
- type GraphQlLoaderAny = any;
64
- interface Loader<TOptions = GraphQlLoaderAny> {
65
- load(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;
66
- loadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;
63
+ interface Loader<TOptions = any> {
64
+ load(pointer: string, options?: TOptions): Promise<any[] | null>;
65
+ loadSync?(pointer: string, options?: TOptions): any[] | null;
67
66
  }
68
67
  /**
69
68
  * Options for the Baeta Generator.
@@ -89,7 +88,7 @@ interface GeneratorOptions {
89
88
  /**
90
89
  * Filename for the generated module definition file.
91
90
  * Contains type definitions and the GraphQL AST.
92
- * @defaultValue 'typedef.ts'
91
+ * @defaultValue 'typedef'
93
92
  */
94
93
  moduleDefinitionName?: string;
95
94
  /**
@@ -154,7 +153,7 @@ declare class WatcherIgnore {
154
153
  private regexps;
155
154
  private functions;
156
155
  private globs;
157
- private globsMap;
156
+ private readonly globsMap;
158
157
  constructor(cwd: string);
159
158
  ignore(pattern: MatchPattern): void;
160
159
  isMicromatch(pattern: string): boolean;
@@ -174,9 +173,9 @@ interface WatcherFile {
174
173
  declare class Watcher {
175
174
  private readonly cwd;
176
175
  private readonly options?;
177
- private subscription;
178
- private listeners;
179
- private watcherIgnore;
176
+ private readonly subscription;
177
+ private readonly listeners;
178
+ private readonly watcherIgnore;
180
179
  constructor(cwd: string, options?: Options);
181
180
  onEvents: (err: Error | null, events: Event[]) => void;
182
181
  on(event: EventType, listener: WatcherListener): void;
@@ -211,7 +210,7 @@ declare class FileBlock extends File {
211
210
  constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
212
211
  write: () => Promise<void>;
213
212
  unlink: () => Promise<void>;
214
- protected getExistingContent(): Promise<readonly [string, fs_promises0.FileHandle] | readonly ["", null]>;
213
+ protected getExistingContent(): Promise<readonly [string, _$fs_promises0.FileHandle] | readonly ["", null]>;
215
214
  protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
216
215
  protected addBlockToContent(existingContent: string): string;
217
216
  protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
package/dist/index.js CHANGED
@@ -4,13 +4,12 @@ import { pascalCase } from "change-case-all";
4
4
  import { PluginType } from "@baeta/plugin";
5
5
  import { subscribe } from "@parcel/watcher";
6
6
  import micromatch, { default as micromatch$1 } from "micromatch";
7
-
8
7
  //#region lib/config.ts
9
8
  function loadOptions(options) {
10
9
  const cwd = posixPath(options.cwd ?? process.cwd());
11
10
  const schemas = options.schemas ?? ["src/**/*.graphql"];
12
11
  const modulesDir = posixPath(resolve(cwd, options.modulesDir || "src/modules"));
13
- const moduleDefinitionName = options.moduleDefinitionName || "typedef.ts";
12
+ const moduleDefinitionName = options.moduleDefinitionName || "typedef";
14
13
  const defaultTypesDir = resolve(modulesDir, "../__generated__/");
15
14
  return {
16
15
  cwd,
@@ -23,7 +22,6 @@ function loadOptions(options) {
23
22
  importExtension: options.importExtension === false ? "" : options.importExtension ?? ".ts"
24
23
  };
25
24
  }
26
-
27
25
  //#endregion
28
26
  //#region lib/file.ts
29
27
  var File = class {
@@ -41,7 +39,7 @@ var File = class {
41
39
  write = async () => {
42
40
  if (this.persisted) return;
43
41
  this.persisted = true;
44
- if (this.options?.allowOverwrite === false) {
42
+ if (this.options?.disableOverwrite === true) {
45
43
  if (await fs.stat(this.filename).then((res) => res.isFile()).catch(() => false)) return;
46
44
  }
47
45
  const dir = dirname(this.filename);
@@ -89,7 +87,6 @@ var File = class {
89
87
  return `/* ${comment} */`;
90
88
  }
91
89
  };
92
-
93
90
  //#endregion
94
91
  //#region lib/file-block.ts
95
92
  var FileBlock = class extends File {
@@ -168,7 +165,6 @@ var FileBlock = class extends File {
168
165
  return "\n\n";
169
166
  }
170
167
  };
171
-
172
168
  //#endregion
173
169
  //#region lib/file-manager.ts
174
170
  var FileManager = class {
@@ -222,13 +218,11 @@ var FileManager = class {
222
218
  return this.files.filter((file) => file.persisted);
223
219
  }
224
220
  };
225
-
226
221
  //#endregion
227
222
  //#region lib/module.ts
228
223
  function getModuleExportName(name) {
229
224
  return `${pascalCase(name)}Module`;
230
225
  }
231
-
232
226
  //#endregion
233
227
  //#region lib/plugin.ts
234
228
  const GeneratorPluginVersion = { V1: "v1" };
@@ -258,7 +252,6 @@ function getGeneratorPlugins(plugins) {
258
252
  if (!plugins) return [];
259
253
  return plugins.filter(isGeneratorPlugin);
260
254
  }
261
-
262
255
  //#endregion
263
256
  //#region lib/watcher-ignore.ts
264
257
  var WatcherIgnore = class {
@@ -311,15 +304,14 @@ var WatcherIgnore = class {
311
304
  this.globsMap.delete(pattern);
312
305
  this.globs = Array.from(this.globsMap.values());
313
306
  }
314
- isIgnored(path$1) {
315
- if (this.files.includes(path$1)) return true;
316
- if (this.globs.some((f) => f(path$1))) return true;
317
- if (this.regexps.some((r) => r.test(path$1))) return true;
318
- if (this.functions.some((f) => f(path$1))) return true;
307
+ isIgnored(path) {
308
+ if (this.files.includes(path)) return true;
309
+ if (this.globs.some((f) => f(path))) return true;
310
+ if (this.regexps.some((r) => r.test(path))) return true;
311
+ if (this.functions.some((f) => f(path))) return true;
319
312
  return false;
320
313
  }
321
314
  };
322
-
323
315
  //#endregion
324
316
  //#region lib/watcher.ts
325
317
  const isMatch = micromatch.isMatch;
@@ -376,7 +368,7 @@ var Watcher = class {
376
368
  return this.subscription.unsubscribe();
377
369
  }
378
370
  };
379
-
380
371
  //#endregion
381
372
  export { File, FileBlock, FileManager, GeneratorPluginVersion, Watcher, WatcherIgnore, createPluginV1, getGeneratorPlugins, getModuleExportName, isGeneratorPlugin, isMatch, loadOptions, micromatch };
373
+
382
374
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["headerItems: string[]","defaultPluginFn: GeneratorPluginV1Fn<unknown>","micromatch","path"],"sources":["../lib/config.ts","../lib/file.ts","../lib/file-block.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher-ignore.ts","../lib/watcher.ts"],"sourcesContent":["import { posixPath, resolve } from '@baeta/util-path';\nimport type { FileOptions } from './file.ts';\n\n/**\n * Interface for custom schema loaders.\n */\n// biome-ignore lint/suspicious/noExplicitAny: We don't want to import graphql for this type\ntype GraphQlLoaderAny = any;\nexport interface Loader<TOptions = GraphQlLoaderAny> {\n\tload(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;\n\tloadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;\n}\n\n/**\n * Options for the Baeta Generator.\n */\nexport interface GeneratorOptions {\n\t/**\n\t * Current working directory for resolving relative paths.\n\t * @defaultValue process.cwd()\n\t */\n\tcwd?: string;\n\n\t/**\n\t * Glob pattern(s) to locate GraphQL schema files.\n\t * @defaultValue ```ts\n\t * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']\n\t * ```\n\t */\n\tschemas: string[];\n\n\t/**\n\t * Root directory where GraphQL modules are defined.\n\t * @defaultValue 'src/modules'\n\t */\n\tmodulesDir?: string;\n\n\t/**\n\t * Filename for the generated module definition file.\n\t * Contains type definitions and the GraphQL AST.\n\t * @defaultValue 'typedef.ts'\n\t */\n\tmoduleDefinitionName?: string;\n\n\t/**\n\t * Output path for the generated type files.\n\t * @defaultValue ```ts\n\t * `${modulesDir}/../__generated__/types.ts`\n\t * ```\n\t */\n\ttypesDir?: string;\n\n\t/**\n\t * Configuration options for generated files.\n\t */\n\tfileOptions?: FileOptions;\n\n\t/**\n\t * Custom schema loaders for processing schema files.\n\t */\n\tloaders?: Loader[];\n\n\t/**\n\t * File extension to use in generated import statements.\n\t * Set to false to omit extensions.\n\t * @defaultValue '.ts'\n\t */\n\timportExtension?: '.js' | '.ts' | false;\n}\n\nexport interface NormalizedGeneratorOptions {\n\tcwd: string;\n\tschemas: string[];\n\tmodulesDir: string;\n\tmoduleDefinitionName: string;\n\ttypesDir: string;\n\tfileOptions?: FileOptions;\n\tloaders?: Loader[];\n\timportExtension: '.js' | '.ts' | '';\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n\tconst cwd = posixPath(options.cwd ?? process.cwd());\n\tconst schemas = options.schemas ?? ['src/**/*.graphql'];\n\tconst modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n\tconst moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\tconst defaultTypesDir = resolve(modulesDir, '../__generated__/');\n\tconst typesDir = resolve(cwd, options.typesDir || defaultTypesDir);\n\n\treturn {\n\t\tcwd,\n\t\tschemas,\n\t\tmodulesDir,\n\t\tmoduleDefinitionName,\n\t\ttypesDir,\n\t\tfileOptions: options.fileOptions,\n\t\tloaders: options.loaders,\n\t\timportExtension: options.importExtension === false ? '' : (options.importExtension ?? '.ts'),\n\t};\n}\n","import fs from 'node:fs/promises';\nimport { dirname, extname } from '@baeta/util-path';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n\t/**\n\t * Disable generation notice at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableGenerationNoticeHeader?: boolean;\n\n\t/**\n\t * Disable eslint-disable comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableEslintHeader?: boolean;\n\n\t/**\n\t * Disable biome v1 comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableBiomeV1Header?: boolean;\n\n\t/**\n\t * Disable biome v2 comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableBiomeV2Header?: boolean;\n\n\t/**\n\t * Allow overwriting the file.\n\t * @defaultValue true\n\t */\n\tallowOverwrite?: boolean;\n\n\t/**\n\t * Add custom header at the beginning of the file.\n\t */\n\taddHeader?: (name: string, content: string, tag: string) => string;\n\n\t/**\n\t * Edit the content of the file before writing it.\n\t */\n\ttransformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n\tpersisted = false;\n\tfilename: string;\n\tcontent: string;\n\ttag: string;\n\tprivate options?: FileOptions;\n\n\tconstructor(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.tag = tag;\n\t\tthis.options = options;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tif (this.options?.allowOverwrite === false) {\n\t\t\tconst exists = await fs\n\t\t\t\t.stat(this.filename)\n\t\t\t\t.then((res) => res.isFile())\n\t\t\t\t.catch(() => false);\n\t\t\tif (exists) return;\n\t\t}\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait fs.mkdir(dir, { recursive: true });\n\n\t\tconst content = await this.buildContent();\n\n\t\treturn fs.writeFile(this.filename, content, 'utf-8');\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\t\treturn fs.unlink(this.filename);\n\t};\n\n\tprotected async buildContent() {\n\t\tconst content = this.buildHeader() + this.content;\n\n\t\tif (this.options?.transformContent) {\n\t\t\treturn this.options.transformContent(this.filename, content, this.tag);\n\t\t}\n\n\t\treturn content;\n\t}\n\n\tprotected buildHeader() {\n\t\tconst headerItems: string[] = [];\n\n\t\tif (this.options?.disableGenerationNoticeHeader !== true) {\n\t\t\tconst comment = this.createComment(\n\t\t\t\t'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n\t\t\t);\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableEslintHeader !== true) {\n\t\t\tconst comment = this.createComment('eslint-disable');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableBiomeV1Header !== true) {\n\t\t\tconst comment = this.createComment('@biome-ignore-all: generated file');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableBiomeV2Header !== true) {\n\t\t\tconst comment = this.createComment('biome-ignore-all lint: generated file');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addHeader) {\n\t\t\tconst customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n\t\t\theaderItems.push(customHeader);\n\t\t}\n\n\t\tif (headerItems.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `${headerItems.join('\\n')}\\n\\n`;\n\t}\n\n\tprotected createComment(comment: string) {\n\t\tconst extension = extname(this.filename);\n\n\t\tif (['.gql', '.graphql'].includes(extension)) {\n\t\t\treturn `# ${comment}`;\n\t\t}\n\n\t\treturn `/* ${comment} */`;\n\t}\n}\n","import { mkdir, open, writeFile } from 'node:fs/promises';\nimport { dirname } from '@baeta/util-path';\nimport { File, type FileOptions } from './file.ts';\n\nexport class FileBlock extends File {\n\tpublic filename: string;\n\tpublic content: string;\n\tpublic start: string;\n\tpublic end: string;\n\tpublic tag: string;\n\tconstructor(\n\t\tfilename: string,\n\t\tcontent: string,\n\t\tstart: string,\n\t\tend: string,\n\t\ttag: string,\n\t\toptions?: FileOptions,\n\t) {\n\t\tsuper(filename, content, tag, {\n\t\t\tdisableBiomeV1Header: options?.disableBiomeV1Header ?? true,\n\t\t\tdisableBiomeV2Header: options?.disableBiomeV2Header ?? true,\n\t\t\tdisableEslintHeader: options?.disableEslintHeader ?? true,\n\t\t\tdisableGenerationNoticeHeader: options?.disableGenerationNoticeHeader ?? true,\n\t\t});\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.start = start;\n\t\tthis.end = end;\n\t\tthis.tag = tag;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait mkdir(dir, { recursive: true });\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tthis.content = this.addBlockToContent(existingContent);\n\t\tconst content = await this.buildContent();\n\n\t\tif (fd) {\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(content, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t} else {\n\t\t\tawait writeFile(this.filename, content, 'utf-8');\n\t\t}\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tif (fd) {\n\t\t\tconst [start, end] = this.getSlices(existingContent);\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(start + end, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t}\n\t};\n\n\tprotected async getExistingContent() {\n\t\ttry {\n\t\t\tconst fd = await open(this.filename, 'r+');\n\t\t\tconst existingContent = await fd.readFile('utf-8');\n\t\t\treturn [existingContent, fd] as const;\n\t\t} catch {\n\t\t\treturn ['', null] as const;\n\t\t}\n\t}\n\n\tprotected getSlices(existingContent: string) {\n\t\tconst startMarkerIndex = existingContent.indexOf(this.start);\n\t\tconst endMarkerIndex = existingContent.lastIndexOf(this.end);\n\n\t\tif (startMarkerIndex === -1 || endMarkerIndex === -1) {\n\t\t\treturn [existingContent, '', false] as const;\n\t\t}\n\n\t\treturn [\n\t\t\texistingContent.slice(0, startMarkerIndex),\n\t\t\texistingContent.slice(endMarkerIndex + this.end.length),\n\t\t\ttrue,\n\t\t] as const;\n\t}\n\n\tprotected addBlockToContent(existingContent: string) {\n\t\tconst block = `${this.start}\\n${this.content}\\n${this.end}`;\n\t\tconst [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);\n\t\tconst padding = hasMarkers ? '' : this.buildPadding(existingContent);\n\t\treturn startSlice + padding + block + endSlice;\n\t}\n\n\tprotected buildPadding(existingContent: string) {\n\t\tif (existingContent === '') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n\\n')) {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n')) {\n\t\t\treturn '\\n';\n\t\t}\n\n\t\treturn '\\n\\n';\n\t}\n}\n","import { File, type FileOptions } from './file.ts';\n\nexport class FileManager {\n\tfiles: File[] = [];\n\tfileOptions?: FileOptions;\n\n\tconstructor(fileOptions?: FileOptions) {\n\t\tthis.fileOptions = fileOptions;\n\t}\n\n\tcreateAndAdd(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tconst file = new File(filename, content, tag, { ...this.fileOptions, ...options });\n\t\tthis.add(file);\n\t\treturn file;\n\t}\n\n\tadd(...file: File[]) {\n\t\tthis.files.push(...file);\n\t}\n\n\tget(filename: string) {\n\t\treturn this.files.find((file) => file.filename === filename);\n\t}\n\n\tgetAll() {\n\t\treturn this.files;\n\t}\n\n\tgetByTag(tag: string) {\n\t\treturn this.files.filter((file) => file.tag === tag);\n\t}\n\n\tremove(filename: string) {\n\t\tconst index = this.files.findIndex((file) => file.filename === filename);\n\t\tthis.files.splice(index, 1);\n\t}\n\n\tremoveAll() {\n\t\tthis.files = [];\n\t}\n\n\tremoveByTag(tag: string) {\n\t\tthis.files = this.files.filter((file) => file.tag !== tag);\n\t}\n\n\twriteAll() {\n\t\tconst toWrite = this.files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\twriteByTag(tag: string) {\n\t\tconst files = this.getByTag(tag);\n\t\tconst toWrite = files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\tunlinkAll() {\n\t\treturn Promise.all(this.files.map((file) => file.unlink())).then(() => {\n\t\t\t// void\n\t\t});\n\t}\n\n\tgetPersistedFiles() {\n\t\treturn this.files.filter((file) => file.persisted);\n\t}\n}\n","import { pascalCase } from 'change-case-all';\n\nexport function getModuleExportName(name: string) {\n\treturn `${pascalCase(name)}Module`;\n}\n","import { PluginType } from '@baeta/plugin';\nimport type { NormalizedGeneratorOptions } from './config.ts';\nimport type { Ctx } from './ctx.ts';\nimport type { Watcher, WatcherFile } from './watcher.ts';\n\nexport const GeneratorPluginVersion = {\n\tV1: 'v1',\n} as const;\n\nexport type GeneratorPluginVersion =\n\t(typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n\tctx: Ctx<Store>,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n\toptions: NormalizedGeneratorOptions,\n\twatcher: Watcher,\n\treload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n\tname: string;\n\tactionName: string;\n\tsetup?: GeneratorPluginV1Fn<Store>;\n\tgenerate?: GeneratorPluginV1Fn<Store>;\n\tend?: GeneratorPluginV1Fn<Store>;\n\twatch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n\tname: string;\n\tactionName: string;\n\tversion: typeof GeneratorPluginVersion.V1;\n\ttype: typeof PluginType.Generator;\n\tsetup: GeneratorPluginV1Fn<Store>;\n\tgenerate: GeneratorPluginV1Fn<Store>;\n\tend: GeneratorPluginV1Fn<Store>;\n\twatch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (_ctx, next) => {\n\treturn next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = unknown>(\n\toptions: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n\treturn {\n\t\tname: options.name,\n\t\tactionName: options.actionName,\n\t\tversion: GeneratorPluginVersion.V1,\n\t\ttype: PluginType.Generator,\n\t\tend: options.end ?? defaultPluginFn,\n\t\tgenerate: options.generate ?? defaultPluginFn,\n\t\tsetup: options.setup ?? defaultPluginFn,\n\t\twatch: options.watch ?? defaultWatchFn,\n\t};\n}\n\nexport function isGeneratorPlugin(plugin: {\n\ttype: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n\treturn plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n\tif (!plugins) {\n\t\treturn [];\n\t}\n\treturn plugins.filter(isGeneratorPlugin);\n}\n","import path from '@baeta/util-path';\nimport micromatch from 'micromatch';\n\nexport type MatchFn = (testString: string) => boolean;\nexport type MatchPattern = string | RegExp | MatchFn;\n\nexport class WatcherIgnore {\n\tprivate readonly cwd: string;\n\tprivate files: string[] = [];\n\tprivate regexps: RegExp[] = [];\n\tprivate functions: MatchFn[] = [];\n\n\tprivate globs: MatchFn[] = [];\n\tprivate globsMap = new Map<string, MatchFn>();\n\n\tconstructor(cwd: string) {\n\t\tthis.cwd = cwd;\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tthis.files.push(this.resolveFile(pattern));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.set(pattern, micromatch.matcher(pattern));\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisMicromatch(pattern: string) {\n\t\tconst result = micromatch.scan(pattern);\n\t\treturn result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n\t}\n\n\tresolveFile(file: string) {\n\t\treturn path.isAbsolute(file) ? file : path.join(this.cwd, file);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps = this.regexps.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions = this.functions.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tconst file = this.resolveFile(pattern);\n\t\t\tthis.files = this.files.filter((p) => p !== file);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.delete(pattern);\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisIgnored(path: string) {\n\t\tif (this.files.includes(path)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.globs.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.regexps.some((r) => r.test(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.functions.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport {\n\ttype AsyncSubscription,\n\ttype Event,\n\ttype EventType,\n\ttype Options,\n\tsubscribe,\n} from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { type MatchPattern, WatcherIgnore } from './watcher-ignore.ts';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n\ttype: EventType;\n\tpath: string;\n\trelativePath: string;\n}\nexport class Watcher {\n\tprivate readonly cwd: string;\n\tprivate readonly options?: Options;\n\n\tprivate subscription: AsyncSubscription;\n\n\tprivate listeners: Record<EventType, WatcherListener[]> = {\n\t\tcreate: [],\n\t\tupdate: [],\n\t\tdelete: [],\n\t};\n\n\tprivate watcherIgnore: WatcherIgnore;\n\n\tconstructor(cwd: string, options?: Options) {\n\t\tthis.cwd = cwd;\n\t\tthis.options = options;\n\t\tthis.watcherIgnore = new WatcherIgnore(cwd);\n\t\tthis.subscription = this.createSubscription();\n\t}\n\n\tonEvents = (err: Error | null, events: Event[]) => {\n\t\tif (err) {\n\t\t\tconsole.error(err);\n\t\t\treturn;\n\t\t}\n\n\t\tconst filteredEvents = events.filter((event) => {\n\t\t\treturn !this.watcherIgnore.isIgnored(posixPath(event.path));\n\t\t});\n\n\t\tfor (const event of filteredEvents) {\n\t\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\t\tlistener({\n\t\t\t\t\ttype: event.type,\n\t\t\t\t\tpath: posixPath(event.path),\n\t\t\t\t\trelativePath: posixPath(path.relative(this.cwd, event.path)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\ton(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event].push(listener);\n\t}\n\n\toff(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.ignore(pattern);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.unignore(pattern);\n\t}\n\n\tcreateSubscription() {\n\t\tconst promise = subscribe(this.cwd, this.onEvents, this.options);\n\n\t\tconst unsubscribe = async () => {\n\t\t\tconst subscription = await promise;\n\t\t\tawait subscription.unsubscribe();\n\t\t};\n\n\t\treturn {\n\t\t\tunsubscribe,\n\t\t};\n\t}\n\n\tclose() {\n\t\treturn this.subscription.unsubscribe();\n\t}\n}\n"],"mappings":";;;;;;;;AAiFA,SAAgB,YAAY,SAAuD;CAClF,MAAM,MAAM,UAAU,QAAQ,OAAO,QAAQ,KAAK,CAAC;CACnD,MAAM,UAAU,QAAQ,WAAW,CAAC,mBAAmB;CACvD,MAAM,aAAa,UAAU,QAAQ,KAAK,QAAQ,cAAc,cAAc,CAAC;CAC/E,MAAM,uBAAuB,QAAQ,wBAAwB;CAC7D,MAAM,kBAAkB,QAAQ,YAAY,oBAAoB;AAGhE,QAAO;EACN;EACA;EACA;EACA;EACA,UAPgB,QAAQ,KAAK,QAAQ,YAAY,gBAAgB;EAQjE,aAAa,QAAQ;EACrB,SAAS,QAAQ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AAK;AACR,WAAQ,MAAM,IAAI;AAClB;;EAGD,MAAM,iBAAiB,OAAO,QAAQ,UAAU;AAC/C,UAAO,CAAC,KAAK,cAAc,UAAU,UAAU,MAAM,KAAK,CAAC;IAC1D;AAEF,OAAK,MAAM,SAAS,eACnB,MAAK,MAAM,YAAY,KAAK,UAAU,MAAM,MAC3C,UAAS;GACR,MAAM,MAAM;GACZ,MAAM,UAAU,MAAM,KAAK;GAC3B,cAAc,UAAU,KAAK,SAAS,KAAK,KAAK,MAAM,KAAK,CAAC;GAC5D,CAAC;;CAKL,GAAG,OAAkB,UAA2B;AAC/C,OAAK,UAAU,OAAO,KAAK,SAAS;;CAGrC,IAAI,OAAkB,UAA2B;AAChD,OAAK,UAAU,SAAS,KAAK,UAAU,OAAO,QAAQ,MAAM,MAAM,SAAS;;CAG5E,OAAO,SAAuB;AAC7B,OAAK,cAAc,OAAO,QAAQ;;CAGnC,SAAS,SAAuB;AAC/B,OAAK,cAAc,SAAS,QAAQ;;CAGrC,qBAAqB;EACpB,MAAM,UAAU,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,QAAQ;EAEhE,MAAM,cAAc,YAAY;AAE/B,UADqB,MAAM,SACR,aAAa;;AAGjC,SAAO,EACN,aACA;;CAGF,QAAQ;AACP,SAAO,KAAK,aAAa,aAAa"}
1
+ {"version":3,"file":"index.js","names":["micromatch"],"sources":["../lib/config.ts","../lib/file.ts","../lib/file-block.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher-ignore.ts","../lib/watcher.ts"],"sourcesContent":["import { posixPath, resolve } from '@baeta/util-path';\nimport type { FileOptions } from './file.ts';\n\n/**\n * Interface for custom schema loaders.\n */\n\nexport interface Loader<TOptions = any> {\n\tload(pointer: string, options?: TOptions): Promise<any[] | null>;\n\tloadSync?(pointer: string, options?: TOptions): any[] | null;\n}\n\n/**\n * Options for the Baeta Generator.\n */\nexport interface GeneratorOptions {\n\t/**\n\t * Current working directory for resolving relative paths.\n\t * @defaultValue process.cwd()\n\t */\n\tcwd?: string;\n\n\t/**\n\t * Glob pattern(s) to locate GraphQL schema files.\n\t * @defaultValue ```ts\n\t * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']\n\t * ```\n\t */\n\tschemas: string[];\n\n\t/**\n\t * Root directory where GraphQL modules are defined.\n\t * @defaultValue 'src/modules'\n\t */\n\tmodulesDir?: string;\n\n\t/**\n\t * Filename for the generated module definition file.\n\t * Contains type definitions and the GraphQL AST.\n\t * @defaultValue 'typedef'\n\t */\n\tmoduleDefinitionName?: string;\n\n\t/**\n\t * Output path for the generated type files.\n\t * @defaultValue ```ts\n\t * `${modulesDir}/../__generated__/types.ts`\n\t * ```\n\t */\n\ttypesDir?: string;\n\n\t/**\n\t * Configuration options for generated files.\n\t */\n\tfileOptions?: FileOptions;\n\n\t/**\n\t * Custom schema loaders for processing schema files.\n\t */\n\tloaders?: Loader[];\n\n\t/**\n\t * File extension to use in generated import statements.\n\t * Set to false to omit extensions.\n\t * @defaultValue '.ts'\n\t */\n\timportExtension?: '.js' | '.ts' | false;\n}\n\nexport interface NormalizedGeneratorOptions {\n\tcwd: string;\n\tschemas: string[];\n\tmodulesDir: string;\n\tmoduleDefinitionName: string;\n\ttypesDir: string;\n\tfileOptions?: FileOptions;\n\tloaders?: Loader[];\n\timportExtension: '.js' | '.ts' | '';\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n\tconst cwd = posixPath(options.cwd ?? process.cwd());\n\tconst schemas = options.schemas ?? ['src/**/*.graphql'];\n\tconst modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n\tconst moduleDefinitionName = options.moduleDefinitionName || 'typedef';\n\tconst defaultTypesDir = resolve(modulesDir, '../__generated__/');\n\tconst typesDir = resolve(cwd, options.typesDir || defaultTypesDir);\n\n\treturn {\n\t\tcwd,\n\t\tschemas,\n\t\tmodulesDir,\n\t\tmoduleDefinitionName,\n\t\ttypesDir,\n\t\tfileOptions: options.fileOptions,\n\t\tloaders: options.loaders,\n\t\timportExtension: options.importExtension === false ? '' : (options.importExtension ?? '.ts'),\n\t};\n}\n","import fs from 'node:fs/promises';\nimport { dirname, extname } from '@baeta/util-path';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n\t/**\n\t * Disable generation notice at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableGenerationNoticeHeader?: boolean;\n\n\t/**\n\t * Disable eslint-disable comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableEslintHeader?: boolean;\n\n\t/**\n\t * Disable biome v1 comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableBiomeV1Header?: boolean;\n\n\t/**\n\t * Disable biome v2 comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableBiomeV2Header?: boolean;\n\n\t/**\n\t * Disallow overwriting the file.\n\t * @defaultValue false\n\t */\n\tdisableOverwrite?: boolean;\n\n\t/**\n\t * Add custom header at the beginning of the file.\n\t */\n\taddHeader?: (name: string, content: string, tag: string) => string;\n\n\t/**\n\t * Edit the content of the file before writing it.\n\t */\n\ttransformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n\tpersisted = false;\n\treadonly filename: string;\n\treadonly content: string;\n\treadonly tag: string;\n\treadonly options?: FileOptions;\n\n\tconstructor(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.tag = tag;\n\t\tthis.options = options;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tif (this.options?.disableOverwrite === true) {\n\t\t\tconst exists = await fs\n\t\t\t\t.stat(this.filename)\n\t\t\t\t.then((res) => res.isFile())\n\t\t\t\t.catch(() => false);\n\t\t\tif (exists) return;\n\t\t}\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait fs.mkdir(dir, { recursive: true });\n\n\t\tconst content = await this.buildContent();\n\n\t\treturn fs.writeFile(this.filename, content, 'utf-8');\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\t\treturn fs.unlink(this.filename);\n\t};\n\n\tprotected async buildContent() {\n\t\tconst content = this.buildHeader() + this.content;\n\n\t\tif (this.options?.transformContent) {\n\t\t\treturn this.options.transformContent(this.filename, content, this.tag);\n\t\t}\n\n\t\treturn content;\n\t}\n\n\tprotected buildHeader() {\n\t\tconst headerItems: string[] = [];\n\n\t\tif (this.options?.disableGenerationNoticeHeader !== true) {\n\t\t\tconst comment = this.createComment(\n\t\t\t\t'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n\t\t\t);\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableEslintHeader !== true) {\n\t\t\tconst comment = this.createComment('eslint-disable');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableBiomeV1Header !== true) {\n\t\t\tconst comment = this.createComment('@biome-ignore-all: generated file');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableBiomeV2Header !== true) {\n\t\t\tconst comment = this.createComment('biome-ignore-all lint: generated file');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addHeader) {\n\t\t\tconst customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n\t\t\theaderItems.push(customHeader);\n\t\t}\n\n\t\tif (headerItems.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `${headerItems.join('\\n')}\\n\\n`;\n\t}\n\n\tprotected createComment(comment: string) {\n\t\tconst extension = extname(this.filename);\n\n\t\tif (['.gql', '.graphql'].includes(extension)) {\n\t\t\treturn `# ${comment}`;\n\t\t}\n\n\t\treturn `/* ${comment} */`;\n\t}\n}\n","import { mkdir, open, writeFile } from 'node:fs/promises';\nimport { dirname } from '@baeta/util-path';\nimport { File, type FileOptions } from './file.ts';\n\nexport class FileBlock extends File {\n\tpublic filename: string;\n\tpublic content: string;\n\tpublic start: string;\n\tpublic end: string;\n\tpublic tag: string;\n\tconstructor(\n\t\tfilename: string,\n\t\tcontent: string,\n\t\tstart: string,\n\t\tend: string,\n\t\ttag: string,\n\t\toptions?: FileOptions,\n\t) {\n\t\tsuper(filename, content, tag, {\n\t\t\tdisableBiomeV1Header: options?.disableBiomeV1Header ?? true,\n\t\t\tdisableBiomeV2Header: options?.disableBiomeV2Header ?? true,\n\t\t\tdisableEslintHeader: options?.disableEslintHeader ?? true,\n\t\t\tdisableGenerationNoticeHeader: options?.disableGenerationNoticeHeader ?? true,\n\t\t});\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.start = start;\n\t\tthis.end = end;\n\t\tthis.tag = tag;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait mkdir(dir, { recursive: true });\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tthis.content = this.addBlockToContent(existingContent);\n\t\tconst content = await this.buildContent();\n\n\t\tif (fd) {\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(content, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t} else {\n\t\t\tawait writeFile(this.filename, content, 'utf-8');\n\t\t}\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tif (fd) {\n\t\t\tconst [start, end] = this.getSlices(existingContent);\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(start + end, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t}\n\t};\n\n\tprotected async getExistingContent() {\n\t\ttry {\n\t\t\tconst fd = await open(this.filename, 'r+');\n\t\t\tconst existingContent = await fd.readFile('utf-8');\n\t\t\treturn [existingContent, fd] as const;\n\t\t} catch {\n\t\t\treturn ['', null] as const;\n\t\t}\n\t}\n\n\tprotected getSlices(existingContent: string) {\n\t\tconst startMarkerIndex = existingContent.indexOf(this.start);\n\t\tconst endMarkerIndex = existingContent.lastIndexOf(this.end);\n\n\t\tif (startMarkerIndex === -1 || endMarkerIndex === -1) {\n\t\t\treturn [existingContent, '', false] as const;\n\t\t}\n\n\t\treturn [\n\t\t\texistingContent.slice(0, startMarkerIndex),\n\t\t\texistingContent.slice(endMarkerIndex + this.end.length),\n\t\t\ttrue,\n\t\t] as const;\n\t}\n\n\tprotected addBlockToContent(existingContent: string) {\n\t\tconst block = `${this.start}\\n${this.content}\\n${this.end}`;\n\t\tconst [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);\n\t\tconst padding = hasMarkers ? '' : this.buildPadding(existingContent);\n\t\treturn startSlice + padding + block + endSlice;\n\t}\n\n\tprotected buildPadding(existingContent: string) {\n\t\tif (existingContent === '') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n\\n')) {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n')) {\n\t\t\treturn '\\n';\n\t\t}\n\n\t\treturn '\\n\\n';\n\t}\n}\n","import { File, type FileOptions } from './file.ts';\n\nexport class FileManager {\n\tfiles: File[] = [];\n\tfileOptions?: FileOptions;\n\n\tconstructor(fileOptions?: FileOptions) {\n\t\tthis.fileOptions = fileOptions;\n\t}\n\n\tcreateAndAdd(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tconst file = new File(filename, content, tag, { ...this.fileOptions, ...options });\n\t\tthis.add(file);\n\t\treturn file;\n\t}\n\n\tadd(...file: File[]) {\n\t\tthis.files.push(...file);\n\t}\n\n\tget(filename: string) {\n\t\treturn this.files.find((file) => file.filename === filename);\n\t}\n\n\tgetAll() {\n\t\treturn this.files;\n\t}\n\n\tgetByTag(tag: string) {\n\t\treturn this.files.filter((file) => file.tag === tag);\n\t}\n\n\tremove(filename: string) {\n\t\tconst index = this.files.findIndex((file) => file.filename === filename);\n\t\tthis.files.splice(index, 1);\n\t}\n\n\tremoveAll() {\n\t\tthis.files = [];\n\t}\n\n\tremoveByTag(tag: string) {\n\t\tthis.files = this.files.filter((file) => file.tag !== tag);\n\t}\n\n\twriteAll() {\n\t\tconst toWrite = this.files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\twriteByTag(tag: string) {\n\t\tconst files = this.getByTag(tag);\n\t\tconst toWrite = files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\tunlinkAll() {\n\t\treturn Promise.all(this.files.map((file) => file.unlink())).then(() => {\n\t\t\t// void\n\t\t});\n\t}\n\n\tgetPersistedFiles() {\n\t\treturn this.files.filter((file) => file.persisted);\n\t}\n}\n","import { pascalCase } from 'change-case-all';\n\nexport function getModuleExportName(name: string) {\n\treturn `${pascalCase(name)}Module`;\n}\n","import { PluginType } from '@baeta/plugin';\nimport type { NormalizedGeneratorOptions } from './config.ts';\nimport type { Ctx } from './ctx.ts';\nimport type { Watcher, WatcherFile } from './watcher.ts';\n\nexport const GeneratorPluginVersion = {\n\tV1: 'v1',\n} as const;\n\nexport type GeneratorPluginVersion =\n\t(typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n\tctx: Ctx<Store>,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n\toptions: NormalizedGeneratorOptions,\n\twatcher: Watcher,\n\treload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n\tname: string;\n\tactionName: string;\n\tsetup?: GeneratorPluginV1Fn<Store>;\n\tgenerate?: GeneratorPluginV1Fn<Store>;\n\tend?: GeneratorPluginV1Fn<Store>;\n\twatch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n\tname: string;\n\tactionName: string;\n\tversion: typeof GeneratorPluginVersion.V1;\n\ttype: typeof PluginType.Generator;\n\tsetup: GeneratorPluginV1Fn<Store>;\n\tgenerate: GeneratorPluginV1Fn<Store>;\n\tend: GeneratorPluginV1Fn<Store>;\n\twatch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (_ctx, next) => {\n\treturn next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = unknown>(\n\toptions: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n\treturn {\n\t\tname: options.name,\n\t\tactionName: options.actionName,\n\t\tversion: GeneratorPluginVersion.V1,\n\t\ttype: PluginType.Generator,\n\t\tend: options.end ?? defaultPluginFn,\n\t\tgenerate: options.generate ?? defaultPluginFn,\n\t\tsetup: options.setup ?? defaultPluginFn,\n\t\twatch: options.watch ?? defaultWatchFn,\n\t};\n}\n\nexport function isGeneratorPlugin(plugin: {\n\ttype: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n\treturn plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n\tif (!plugins) {\n\t\treturn [];\n\t}\n\treturn plugins.filter(isGeneratorPlugin);\n}\n","import path from '@baeta/util-path';\nimport micromatch from 'micromatch';\n\nexport type MatchFn = (testString: string) => boolean;\nexport type MatchPattern = string | RegExp | MatchFn;\n\nexport class WatcherIgnore {\n\tprivate readonly cwd: string;\n\tprivate files: string[] = [];\n\tprivate regexps: RegExp[] = [];\n\tprivate functions: MatchFn[] = [];\n\n\tprivate globs: MatchFn[] = [];\n\tprivate readonly globsMap = new Map<string, MatchFn>();\n\n\tconstructor(cwd: string) {\n\t\tthis.cwd = cwd;\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tthis.files.push(this.resolveFile(pattern));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.set(pattern, micromatch.matcher(pattern));\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisMicromatch(pattern: string) {\n\t\tconst result = micromatch.scan(pattern);\n\t\treturn result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n\t}\n\n\tresolveFile(file: string) {\n\t\treturn path.isAbsolute(file) ? file : path.join(this.cwd, file);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps = this.regexps.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions = this.functions.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tconst file = this.resolveFile(pattern);\n\t\t\tthis.files = this.files.filter((p) => p !== file);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.delete(pattern);\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisIgnored(path: string) {\n\t\tif (this.files.includes(path)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.globs.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.regexps.some((r) => r.test(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.functions.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport {\n\ttype AsyncSubscription,\n\ttype Event,\n\ttype EventType,\n\ttype Options,\n\tsubscribe,\n} from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { type MatchPattern, WatcherIgnore } from './watcher-ignore.ts';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n\ttype: EventType;\n\tpath: string;\n\trelativePath: string;\n}\nexport class Watcher {\n\tprivate readonly cwd: string;\n\tprivate readonly options?: Options;\n\n\tprivate readonly subscription: AsyncSubscription;\n\n\tprivate readonly listeners: Record<EventType, WatcherListener[]> = {\n\t\tcreate: [],\n\t\tupdate: [],\n\t\tdelete: [],\n\t};\n\n\tprivate readonly watcherIgnore: WatcherIgnore;\n\n\tconstructor(cwd: string, options?: Options) {\n\t\tthis.cwd = cwd;\n\t\tthis.options = options;\n\t\tthis.watcherIgnore = new WatcherIgnore(cwd);\n\t\tthis.subscription = this.createSubscription();\n\t}\n\n\tonEvents = (err: Error | null, events: Event[]) => {\n\t\tif (err) {\n\t\t\tconsole.error(err);\n\t\t\treturn;\n\t\t}\n\n\t\tconst filteredEvents = events.filter((event) => {\n\t\t\treturn !this.watcherIgnore.isIgnored(posixPath(event.path));\n\t\t});\n\n\t\tfor (const event of filteredEvents) {\n\t\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\t\tlistener({\n\t\t\t\t\ttype: event.type,\n\t\t\t\t\tpath: posixPath(event.path),\n\t\t\t\t\trelativePath: posixPath(path.relative(this.cwd, event.path)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\ton(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event].push(listener);\n\t}\n\n\toff(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.ignore(pattern);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.unignore(pattern);\n\t}\n\n\tcreateSubscription() {\n\t\tconst promise = subscribe(this.cwd, this.onEvents, this.options);\n\n\t\tconst unsubscribe = async () => {\n\t\t\tconst subscription = await promise;\n\t\t\tawait subscription.unsubscribe();\n\t\t};\n\n\t\treturn {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",
3
+ "version": "2.0.0-next.5",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -38,23 +38,31 @@
38
38
  ],
39
39
  "scripts": {
40
40
  "build": "builder build",
41
+ "check:deps": "builder check-deps",
41
42
  "prepack": "builder prepare",
42
- "postpack": "builder prepare --clean",
43
+ "postpack": "builder prepare --restore",
44
+ "test": "builder test",
43
45
  "types": "tsc --noEmit"
44
46
  },
47
+ "ava": {
48
+ "extensions": [
49
+ "ts"
50
+ ]
51
+ },
45
52
  "dependencies": {
46
- "@baeta/plugin": "^2.0.0-next.2",
47
- "@baeta/util-path": "^2.0.0-next.2",
48
- "@parcel/watcher": "^2.5.1",
53
+ "@baeta/plugin": "^2.0.0-next.3",
54
+ "@baeta/util-path": "^2.0.0-next.4",
55
+ "@parcel/watcher": "^2.5.6",
49
56
  "change-case-all": "2.1.0",
50
57
  "micromatch": "^4.0.8"
51
58
  },
52
59
  "devDependencies": {
53
60
  "@baeta/builder": "^0.0.0",
61
+ "@baeta/testing": "^0.0.0",
54
62
  "@baeta/tsconfig": "^0.0.0",
55
63
  "@types/micromatch": "^4.0.10",
56
- "@types/node": "^22.18.13",
57
- "typescript": "^5.9.3"
64
+ "@types/node": "^22.19.17",
65
+ "typescript": "^6.0.0"
58
66
  },
59
67
  "engines": {
60
68
  "node": ">=22.20.0"