@baeta/generator-sdk 2.0.0-next.2 → 2.0.0-next.4

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,21 @@
1
1
  # @baeta/generator-sdk
2
2
 
3
+ ## 2.0.0-next.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Fix generator overwriting types.ts file
8
+
9
+ - Updated dependencies [[`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008), [`831cfa2`](https://github.com/andreisergiu98/baeta/commit/831cfa2a11445aaf7f2d1a1d7ddf073db9bb8008)]:
10
+ - @baeta/plugin@2.0.0-next.3
11
+ - @baeta/util-path@2.0.0-next.3
12
+
13
+ ## 2.0.0-next.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [#214](https://github.com/andreisergiu98/baeta/pull/214) [`6de5d15`](https://github.com/andreisergiu98/baeta/commit/6de5d15484d341a1717a1b2f3f45272912e6a886) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Fix generated import paths with custom config
18
+
3
19
  ## 2.0.0-next.2
4
20
 
5
21
  ### 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 />
@@ -77,43 +77,68 @@ type Query {
77
77
  #### 2. Implement your resolvers
78
78
 
79
79
  ```typescript
80
- import { getUserModule } from "./typedef";
80
+ import { UserModule } from "./typedef.ts";
81
81
 
82
- const { Query } = getUserModule();
82
+ const { Query } = UserModule;
83
83
 
84
- Query.user(({ args }) => {
84
+ const userQuery = Query.user.resolve(({ args }) => {
85
85
  return dataSource.user.find(args.where);
86
86
  });
87
87
 
88
- Query.users(() => {
88
+ const usersQuery = Query.users.resolve(() => {
89
89
  return dataSource.user.findMany();
90
90
  });
91
+
92
+ Query.$fields({
93
+ user: userQuery,
94
+ users: usersQuery,
95
+ });
91
96
  ```
92
97
 
93
98
  #### 3. Add authorization
94
99
 
95
100
  ```typescript
96
- const { Query, Mutation } = getUserModule();
97
-
98
- Query.users.$auth({
99
- $or: {
100
- isPublic: true,
101
- isLoggedIn: true,
102
- },
103
- });
101
+ import { UserModule } from "./typedef.ts";
102
+
103
+ const { Query } = UserModule;
104
+
105
+ const userQuery = Query.user
106
+ .$auth({
107
+ $or: {
108
+ isPublic: true,
109
+ isLoggedIn: true,
110
+ },
111
+ })
112
+ .resolve(async ({ args }) => {
113
+ // ...
114
+ });
104
115
  ```
105
116
 
106
117
  #### 4. Add caching
107
118
 
108
119
  ```typescript
109
- import { getUserModule } from "./typedef";
110
-
111
- const { User, Query } = getUserModule();
120
+ const { Query, Mutation, User } = UserModule;
112
121
 
113
122
  export const userCache = User.$createCache();
114
123
 
115
- Query.user.$useCache(userCache);
116
- Query.users.$useCache(userCache);
124
+ const userQuery = Query.user
125
+ .$auth({
126
+ // ...
127
+ })
128
+ .$useCache(userCache)
129
+ .resolve(async ({ args }) => {
130
+ // ...
131
+ });
132
+
133
+ const updateUserMutation = Mutation.updateUser
134
+ .$use(async (next) => {
135
+ const user = await next();
136
+ await userCache.save(user);
137
+ return user;
138
+ })
139
+ .resolve(async ({ args }) => {
140
+ // ...
141
+ });
117
142
  ```
118
143
 
119
144
  ## Compatibility
package/dist/index.d.ts CHANGED
@@ -1,244 +1,257 @@
1
- import { EventType, Options, Event } from '@parcel/watcher';
2
- import micromatch from 'micromatch';
3
- export { default as micromatch } from 'micromatch';
4
- import * as fs_promises from 'fs/promises';
5
- import { PluginType } from '@baeta/plugin';
1
+ import { PluginType } from "@baeta/plugin";
2
+ import { Event, EventType, Options } from "@parcel/watcher";
3
+ import micromatch from "micromatch";
4
+ import * as fs_promises0 from "fs/promises";
6
5
 
6
+ //#region lib/file.d.ts
7
7
  /**
8
8
  * Options for generated files.
9
9
  */
10
10
  interface FileOptions {
11
- /**
12
- * Disable generation notice at the beginning of the file.
13
- * @defaultValue false
14
- */
15
- disableGenerationNoticeHeader?: boolean;
16
- /**
17
- * Disable eslint-disable comment at the beginning of the file.
18
- * @defaultValue false
19
- */
20
- disableEslintHeader?: boolean;
21
- /**
22
- * Disable biome comment at the beginning of the file.
23
- * @defaultValue false
24
- */
25
- disableBiomeHeader?: boolean;
26
- /**
27
- * Allow overwriting the file.
28
- * @defaultValue true
29
- */
30
- allowOverwrite?: boolean;
31
- /**
32
- * Add custom header at the beginning of the file.
33
- */
34
- addHeader?: (name: string, content: string, tag: string) => string;
35
- /**
36
- * Edit the content of the file before writing it.
37
- */
38
- transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
11
+ /**
12
+ * Disable generation notice at the beginning of the file.
13
+ * @defaultValue false
14
+ */
15
+ disableGenerationNoticeHeader?: boolean;
16
+ /**
17
+ * Disable eslint-disable comment at the beginning of the file.
18
+ * @defaultValue false
19
+ */
20
+ disableEslintHeader?: boolean;
21
+ /**
22
+ * Disable biome v1 comment at the beginning of the file.
23
+ * @defaultValue false
24
+ */
25
+ disableBiomeV1Header?: boolean;
26
+ /**
27
+ * Disable biome v2 comment at the beginning of the file.
28
+ * @defaultValue false
29
+ */
30
+ disableBiomeV2Header?: boolean;
31
+ /**
32
+ * Dissallow overwriting the file.
33
+ * @defaultValue false
34
+ */
35
+ disableOverwrite?: boolean;
36
+ /**
37
+ * Add custom header at the beginning of the file.
38
+ */
39
+ addHeader?: (name: string, content: string, tag: string) => string;
40
+ /**
41
+ * Edit the content of the file before writing it.
42
+ */
43
+ transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
39
44
  }
40
45
  declare class File {
41
- persisted: boolean;
42
- filename: string;
43
- content: string;
44
- tag: string;
45
- private options?;
46
- constructor(filename: string, content: string, tag: string, options?: FileOptions);
47
- write: () => Promise<void>;
48
- unlink: () => Promise<void>;
49
- protected buildContent(): Promise<string>;
50
- protected buildHeader(): string;
51
- protected createComment(comment: string): string;
46
+ persisted: boolean;
47
+ readonly filename: string;
48
+ readonly content: string;
49
+ readonly tag: string;
50
+ readonly options?: FileOptions;
51
+ constructor(filename: string, content: string, tag: string, options?: FileOptions);
52
+ write: () => Promise<void>;
53
+ unlink: () => Promise<void>;
54
+ protected buildContent(): Promise<string>;
55
+ protected buildHeader(): string;
56
+ protected createComment(comment: string): string;
52
57
  }
53
-
58
+ //#endregion
59
+ //#region lib/config.d.ts
54
60
  /**
55
61
  * Interface for custom schema loaders.
56
62
  */
57
- type GraphQlLoaderAny = any;
58
- interface Loader<TOptions = GraphQlLoaderAny> {
59
- load(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;
60
- 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;
61
66
  }
62
67
  /**
63
68
  * Options for the Baeta Generator.
64
69
  */
65
70
  interface GeneratorOptions {
66
- /**
67
- * Current working directory for resolving relative paths.
68
- * @defaultValue process.cwd()
69
- */
70
- cwd?: string;
71
- /**
72
- * Glob pattern(s) to locate GraphQL schema files.
73
- * @defaultValue ```ts
74
- * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']
75
- * ```
76
- */
77
- schemas: string[];
78
- /**
79
- * Root directory where GraphQL modules are defined.
80
- * @defaultValue 'src/modules'
81
- */
82
- modulesDir?: string;
83
- /**
84
- * Filename for the generated module definition file.
85
- * Contains type definitions and the GraphQL AST.
86
- * @defaultValue 'typedef.ts'
87
- */
88
- moduleDefinitionName?: string;
89
- /**
90
- * Output path for the generated type files.
91
- * @defaultValue ```ts
92
- * `${modulesDir}/../__generated__/types.ts`
93
- * ```
94
- */
95
- typesDir?: string;
96
- /**
97
- * Configuration options for generated files.
98
- */
99
- fileOptions?: FileOptions;
100
- /**
101
- * Custom schema loaders for processing schema files.
102
- */
103
- loaders?: Loader[];
104
- /**
105
- * File extension to use in generated import statements.
106
- * Set to false to omit extensions.
107
- * @defaultValue '.ts'
108
- */
109
- importExtension?: '.js' | '.ts' | false;
71
+ /**
72
+ * Current working directory for resolving relative paths.
73
+ * @defaultValue process.cwd()
74
+ */
75
+ cwd?: string;
76
+ /**
77
+ * Glob pattern(s) to locate GraphQL schema files.
78
+ * @defaultValue ```ts
79
+ * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']
80
+ * ```
81
+ */
82
+ schemas: string[];
83
+ /**
84
+ * Root directory where GraphQL modules are defined.
85
+ * @defaultValue 'src/modules'
86
+ */
87
+ modulesDir?: string;
88
+ /**
89
+ * Filename for the generated module definition file.
90
+ * Contains type definitions and the GraphQL AST.
91
+ * @defaultValue 'typedef.ts'
92
+ */
93
+ moduleDefinitionName?: string;
94
+ /**
95
+ * Output path for the generated type files.
96
+ * @defaultValue ```ts
97
+ * `${modulesDir}/../__generated__/types.ts`
98
+ * ```
99
+ */
100
+ typesDir?: string;
101
+ /**
102
+ * Configuration options for generated files.
103
+ */
104
+ fileOptions?: FileOptions;
105
+ /**
106
+ * Custom schema loaders for processing schema files.
107
+ */
108
+ loaders?: Loader[];
109
+ /**
110
+ * File extension to use in generated import statements.
111
+ * Set to false to omit extensions.
112
+ * @defaultValue '.ts'
113
+ */
114
+ importExtension?: '.js' | '.ts' | false;
110
115
  }
111
116
  interface NormalizedGeneratorOptions {
112
- cwd: string;
113
- schemas: string[];
114
- modulesDir: string;
115
- moduleDefinitionName: string;
116
- typesDir: string;
117
- fileOptions?: FileOptions;
118
- loaders?: Loader[];
119
- importExtension: '.js' | '.ts' | '';
117
+ cwd: string;
118
+ schemas: string[];
119
+ modulesDir: string;
120
+ moduleDefinitionName: string;
121
+ typesDir: string;
122
+ fileOptions?: FileOptions;
123
+ loaders?: Loader[];
124
+ importExtension: '.js' | '.ts' | '';
120
125
  }
121
126
  declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
122
-
127
+ //#endregion
128
+ //#region lib/file-manager.d.ts
123
129
  declare class FileManager {
124
- files: File[];
125
- fileOptions?: FileOptions;
126
- constructor(fileOptions?: FileOptions);
127
- createAndAdd(filename: string, content: string, tag: string, options?: FileOptions): File;
128
- add(...file: File[]): void;
129
- get(filename: string): File | undefined;
130
- getAll(): File[];
131
- getByTag(tag: string): File[];
132
- remove(filename: string): void;
133
- removeAll(): void;
134
- removeByTag(tag: string): void;
135
- writeAll(): Promise<void[]>;
136
- writeByTag(tag: string): Promise<void[]>;
137
- unlinkAll(): Promise<void>;
138
- getPersistedFiles(): File[];
130
+ files: File[];
131
+ fileOptions?: FileOptions;
132
+ constructor(fileOptions?: FileOptions);
133
+ createAndAdd(filename: string, content: string, tag: string, options?: FileOptions): File;
134
+ add(...file: File[]): void;
135
+ get(filename: string): File | undefined;
136
+ getAll(): File[];
137
+ getByTag(tag: string): File[];
138
+ remove(filename: string): void;
139
+ removeAll(): void;
140
+ removeByTag(tag: string): void;
141
+ writeAll(): Promise<void[]>;
142
+ writeByTag(tag: string): Promise<void[]>;
143
+ unlinkAll(): Promise<void>;
144
+ getPersistedFiles(): File[];
139
145
  }
140
-
146
+ //#endregion
147
+ //#region lib/watcher-ignore.d.ts
141
148
  type MatchFn = (testString: string) => boolean;
142
149
  type MatchPattern = string | RegExp | MatchFn;
143
150
  declare class WatcherIgnore {
144
- private readonly cwd;
145
- private files;
146
- private regexps;
147
- private functions;
148
- private globs;
149
- private globsMap;
150
- constructor(cwd: string);
151
- ignore(pattern: MatchPattern): void;
152
- isMicromatch(pattern: string): boolean;
153
- resolveFile(file: string): string;
154
- unignore(pattern: MatchPattern): void;
155
- isIgnored(path: string): boolean;
151
+ private readonly cwd;
152
+ private files;
153
+ private regexps;
154
+ private functions;
155
+ private globs;
156
+ private readonly globsMap;
157
+ constructor(cwd: string);
158
+ ignore(pattern: MatchPattern): void;
159
+ isMicromatch(pattern: string): boolean;
160
+ resolveFile(file: string): string;
161
+ unignore(pattern: MatchPattern): void;
162
+ isIgnored(path: string): boolean;
156
163
  }
157
-
164
+ //#endregion
165
+ //#region lib/watcher.d.ts
158
166
  declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options) => boolean;
159
167
  type WatcherListener = (path: WatcherFile) => void;
160
168
  interface WatcherFile {
161
- type: EventType;
162
- path: string;
163
- relativePath: string;
169
+ type: EventType;
170
+ path: string;
171
+ relativePath: string;
164
172
  }
165
173
  declare class Watcher {
166
- private readonly cwd;
167
- private readonly options?;
168
- private subscription;
169
- private listeners;
170
- private watcherIgnore;
171
- constructor(cwd: string, options?: Options);
172
- onEvents: (err: Error | null, events: Event[]) => void;
173
- on(event: EventType, listener: WatcherListener): void;
174
- off(event: EventType, listener: WatcherListener): void;
175
- ignore(pattern: MatchPattern): void;
176
- unignore(pattern: MatchPattern): void;
177
- createSubscription(): {
178
- unsubscribe: () => Promise<void>;
179
- };
180
- close(): Promise<void>;
174
+ private readonly cwd;
175
+ private readonly options?;
176
+ private readonly subscription;
177
+ private readonly listeners;
178
+ private readonly watcherIgnore;
179
+ constructor(cwd: string, options?: Options);
180
+ onEvents: (err: Error | null, events: Event[]) => void;
181
+ on(event: EventType, listener: WatcherListener): void;
182
+ off(event: EventType, listener: WatcherListener): void;
183
+ ignore(pattern: MatchPattern): void;
184
+ unignore(pattern: MatchPattern): void;
185
+ createSubscription(): {
186
+ unsubscribe: () => Promise<void>;
187
+ };
188
+ close(): Promise<void>;
181
189
  }
182
-
190
+ //#endregion
191
+ //#region lib/ctx.d.ts
183
192
  type Ctx<T = unknown> = {
184
- fileManager: FileManager;
185
- didSetup: string[];
186
- didGenerate: string[];
187
- didEnd: string[];
188
- pluginNames: string[];
189
- generatorOptions: NormalizedGeneratorOptions;
190
- watching: boolean;
191
- changedFile?: WatcherFile;
193
+ fileManager: FileManager;
194
+ didSetup: string[];
195
+ didGenerate: string[];
196
+ didEnd: string[];
197
+ pluginNames: string[];
198
+ generatorOptions: NormalizedGeneratorOptions;
199
+ watching: boolean;
200
+ changedFile?: WatcherFile;
192
201
  } & T;
193
-
202
+ //#endregion
203
+ //#region lib/file-block.d.ts
194
204
  declare class FileBlock extends File {
195
- filename: string;
196
- content: string;
197
- start: string;
198
- end: string;
199
- tag: string;
200
- constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
201
- write: () => Promise<void>;
202
- unlink: () => Promise<void>;
203
- protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
204
- protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
205
- protected addBlockToContent(existingContent: string): string;
206
- protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
205
+ filename: string;
206
+ content: string;
207
+ start: string;
208
+ end: string;
209
+ tag: string;
210
+ constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
211
+ write: () => Promise<void>;
212
+ unlink: () => Promise<void>;
213
+ protected getExistingContent(): Promise<readonly [string, fs_promises0.FileHandle] | readonly ["", null]>;
214
+ protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
215
+ protected addBlockToContent(existingContent: string): string;
216
+ protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
207
217
  }
208
-
218
+ //#endregion
219
+ //#region lib/module.d.ts
209
220
  declare function getModuleExportName(name: string): string;
210
-
221
+ //#endregion
222
+ //#region lib/plugin.d.ts
211
223
  declare const GeneratorPluginVersion: {
212
- readonly V1: "v1";
224
+ readonly V1: "v1";
213
225
  };
214
226
  type GeneratorPluginVersion = (typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];
215
227
  type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
216
228
  type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
217
229
  type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
218
230
  type GeneratorPluginV1Factory<Store = unknown> = {
219
- name: string;
220
- actionName: string;
221
- setup?: GeneratorPluginV1Fn<Store>;
222
- generate?: GeneratorPluginV1Fn<Store>;
223
- end?: GeneratorPluginV1Fn<Store>;
224
- watch?: GeneratorPluginV1WatchOptions;
231
+ name: string;
232
+ actionName: string;
233
+ setup?: GeneratorPluginV1Fn<Store>;
234
+ generate?: GeneratorPluginV1Fn<Store>;
235
+ end?: GeneratorPluginV1Fn<Store>;
236
+ watch?: GeneratorPluginV1WatchOptions;
225
237
  };
226
238
  interface GeneratorPluginV1<Store = unknown> {
227
- name: string;
228
- actionName: string;
229
- version: typeof GeneratorPluginVersion.V1;
230
- type: typeof PluginType.Generator;
231
- setup: GeneratorPluginV1Fn<Store>;
232
- generate: GeneratorPluginV1Fn<Store>;
233
- end: GeneratorPluginV1Fn<Store>;
234
- watch: GeneratorPluginV1WatchOptions;
239
+ name: string;
240
+ actionName: string;
241
+ version: typeof GeneratorPluginVersion.V1;
242
+ type: typeof PluginType.Generator;
243
+ setup: GeneratorPluginV1Fn<Store>;
244
+ generate: GeneratorPluginV1Fn<Store>;
245
+ end: GeneratorPluginV1Fn<Store>;
246
+ watch: GeneratorPluginV1WatchOptions;
235
247
  }
236
248
  declare function createPluginV1<Store = unknown>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
237
249
  declare function isGeneratorPlugin(plugin: {
238
- type: PluginType;
250
+ type: PluginType;
239
251
  }): plugin is GeneratorPluginV1<unknown>;
240
252
  declare function getGeneratorPlugins(plugins?: Array<{
241
- type: PluginType;
253
+ type: PluginType;
242
254
  }>): GeneratorPluginV1<unknown>[];
243
-
244
- export { type Ctx, File, FileBlock, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type Loader, type MatchFn, type MatchPattern, type NormalizedGeneratorOptions, Watcher, type WatcherFile, WatcherIgnore, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleExportName, isGeneratorPlugin, isMatch, loadOptions };
255
+ //#endregion
256
+ export { Ctx, File, FileBlock, FileManager, FileOptions, GeneratorOptions, GeneratorPluginV1, GeneratorPluginV1Factory, GeneratorPluginV1Fn, GeneratorPluginV1ReloadFn, GeneratorPluginV1WatchOptions, GeneratorPluginVersion, Loader, MatchFn, MatchPattern, NormalizedGeneratorOptions, Watcher, WatcherFile, WatcherIgnore, WatcherListener, createPluginV1, getGeneratorPlugins, getModuleExportName, isGeneratorPlugin, isMatch, loadOptions, micromatch };
257
+ //# sourceMappingURL=index.d.ts.map