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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @baeta/generator-sdk
2
2
 
3
+ ## 2.0.0-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
3
9
  ## 2.0.0-next.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -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,258 @@
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
+ * Allow overwriting the file.
33
+ * @defaultValue true
34
+ */
35
+ allowOverwrite?: 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
+ filename: string;
48
+ content: string;
49
+ tag: string;
50
+ private options?;
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
63
  type GraphQlLoaderAny = any;
58
64
  interface Loader<TOptions = GraphQlLoaderAny> {
59
- load(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;
60
- loadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;
65
+ load(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;
66
+ loadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;
61
67
  }
62
68
  /**
63
69
  * Options for the Baeta Generator.
64
70
  */
65
71
  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;
72
+ /**
73
+ * Current working directory for resolving relative paths.
74
+ * @defaultValue process.cwd()
75
+ */
76
+ cwd?: string;
77
+ /**
78
+ * Glob pattern(s) to locate GraphQL schema files.
79
+ * @defaultValue ```ts
80
+ * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']
81
+ * ```
82
+ */
83
+ schemas: string[];
84
+ /**
85
+ * Root directory where GraphQL modules are defined.
86
+ * @defaultValue 'src/modules'
87
+ */
88
+ modulesDir?: string;
89
+ /**
90
+ * Filename for the generated module definition file.
91
+ * Contains type definitions and the GraphQL AST.
92
+ * @defaultValue 'typedef.ts'
93
+ */
94
+ moduleDefinitionName?: string;
95
+ /**
96
+ * Output path for the generated type files.
97
+ * @defaultValue ```ts
98
+ * `${modulesDir}/../__generated__/types.ts`
99
+ * ```
100
+ */
101
+ typesDir?: string;
102
+ /**
103
+ * Configuration options for generated files.
104
+ */
105
+ fileOptions?: FileOptions;
106
+ /**
107
+ * Custom schema loaders for processing schema files.
108
+ */
109
+ loaders?: Loader[];
110
+ /**
111
+ * File extension to use in generated import statements.
112
+ * Set to false to omit extensions.
113
+ * @defaultValue '.ts'
114
+ */
115
+ importExtension?: '.js' | '.ts' | false;
110
116
  }
111
117
  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' | '';
118
+ cwd: string;
119
+ schemas: string[];
120
+ modulesDir: string;
121
+ moduleDefinitionName: string;
122
+ typesDir: string;
123
+ fileOptions?: FileOptions;
124
+ loaders?: Loader[];
125
+ importExtension: '.js' | '.ts' | '';
120
126
  }
121
127
  declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
122
-
128
+ //#endregion
129
+ //#region lib/file-manager.d.ts
123
130
  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[];
131
+ files: File[];
132
+ fileOptions?: FileOptions;
133
+ constructor(fileOptions?: FileOptions);
134
+ createAndAdd(filename: string, content: string, tag: string, options?: FileOptions): File;
135
+ add(...file: File[]): void;
136
+ get(filename: string): File | undefined;
137
+ getAll(): File[];
138
+ getByTag(tag: string): File[];
139
+ remove(filename: string): void;
140
+ removeAll(): void;
141
+ removeByTag(tag: string): void;
142
+ writeAll(): Promise<void[]>;
143
+ writeByTag(tag: string): Promise<void[]>;
144
+ unlinkAll(): Promise<void>;
145
+ getPersistedFiles(): File[];
139
146
  }
140
-
147
+ //#endregion
148
+ //#region lib/watcher-ignore.d.ts
141
149
  type MatchFn = (testString: string) => boolean;
142
150
  type MatchPattern = string | RegExp | MatchFn;
143
151
  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;
152
+ private readonly cwd;
153
+ private files;
154
+ private regexps;
155
+ private functions;
156
+ private globs;
157
+ private globsMap;
158
+ constructor(cwd: string);
159
+ ignore(pattern: MatchPattern): void;
160
+ isMicromatch(pattern: string): boolean;
161
+ resolveFile(file: string): string;
162
+ unignore(pattern: MatchPattern): void;
163
+ isIgnored(path: string): boolean;
156
164
  }
157
-
165
+ //#endregion
166
+ //#region lib/watcher.d.ts
158
167
  declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options) => boolean;
159
168
  type WatcherListener = (path: WatcherFile) => void;
160
169
  interface WatcherFile {
161
- type: EventType;
162
- path: string;
163
- relativePath: string;
170
+ type: EventType;
171
+ path: string;
172
+ relativePath: string;
164
173
  }
165
174
  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>;
175
+ private readonly cwd;
176
+ private readonly options?;
177
+ private subscription;
178
+ private listeners;
179
+ private watcherIgnore;
180
+ constructor(cwd: string, options?: Options);
181
+ onEvents: (err: Error | null, events: Event[]) => void;
182
+ on(event: EventType, listener: WatcherListener): void;
183
+ off(event: EventType, listener: WatcherListener): void;
184
+ ignore(pattern: MatchPattern): void;
185
+ unignore(pattern: MatchPattern): void;
186
+ createSubscription(): {
187
+ unsubscribe: () => Promise<void>;
188
+ };
189
+ close(): Promise<void>;
181
190
  }
182
-
191
+ //#endregion
192
+ //#region lib/ctx.d.ts
183
193
  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;
194
+ fileManager: FileManager;
195
+ didSetup: string[];
196
+ didGenerate: string[];
197
+ didEnd: string[];
198
+ pluginNames: string[];
199
+ generatorOptions: NormalizedGeneratorOptions;
200
+ watching: boolean;
201
+ changedFile?: WatcherFile;
192
202
  } & T;
193
-
203
+ //#endregion
204
+ //#region lib/file-block.d.ts
194
205
  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";
206
+ filename: string;
207
+ content: string;
208
+ start: string;
209
+ end: string;
210
+ tag: string;
211
+ constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
212
+ write: () => Promise<void>;
213
+ unlink: () => Promise<void>;
214
+ protected getExistingContent(): Promise<readonly [string, fs_promises0.FileHandle] | readonly ["", null]>;
215
+ protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
216
+ protected addBlockToContent(existingContent: string): string;
217
+ protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
207
218
  }
208
-
219
+ //#endregion
220
+ //#region lib/module.d.ts
209
221
  declare function getModuleExportName(name: string): string;
210
-
222
+ //#endregion
223
+ //#region lib/plugin.d.ts
211
224
  declare const GeneratorPluginVersion: {
212
- readonly V1: "v1";
225
+ readonly V1: "v1";
213
226
  };
214
227
  type GeneratorPluginVersion = (typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];
215
228
  type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
216
229
  type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
217
230
  type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
218
231
  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;
232
+ name: string;
233
+ actionName: string;
234
+ setup?: GeneratorPluginV1Fn<Store>;
235
+ generate?: GeneratorPluginV1Fn<Store>;
236
+ end?: GeneratorPluginV1Fn<Store>;
237
+ watch?: GeneratorPluginV1WatchOptions;
225
238
  };
226
239
  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;
240
+ name: string;
241
+ actionName: string;
242
+ version: typeof GeneratorPluginVersion.V1;
243
+ type: typeof PluginType.Generator;
244
+ setup: GeneratorPluginV1Fn<Store>;
245
+ generate: GeneratorPluginV1Fn<Store>;
246
+ end: GeneratorPluginV1Fn<Store>;
247
+ watch: GeneratorPluginV1WatchOptions;
235
248
  }
236
249
  declare function createPluginV1<Store = unknown>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
237
250
  declare function isGeneratorPlugin(plugin: {
238
- type: PluginType;
251
+ type: PluginType;
239
252
  }): plugin is GeneratorPluginV1<unknown>;
240
253
  declare function getGeneratorPlugins(plugins?: Array<{
241
- type: PluginType;
254
+ type: PluginType;
242
255
  }>): 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 };
256
+ //#endregion
257
+ 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 };
258
+ //# sourceMappingURL=index.d.ts.map