@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 +6 -0
- package/README.md +42 -17
- package/dist/index.d.ts +204 -190
- package/dist/index.js +353 -404
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
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 {
|
|
80
|
+
import { UserModule } from "./typedef.ts";
|
|
81
81
|
|
|
82
|
-
const { Query } =
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
Query
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
|
116
|
-
|
|
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 {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import * as
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
type: EventType;
|
|
171
|
+
path: string;
|
|
172
|
+
relativePath: string;
|
|
164
173
|
}
|
|
165
174
|
declare class Watcher {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
251
|
+
type: PluginType;
|
|
239
252
|
}): plugin is GeneratorPluginV1<unknown>;
|
|
240
253
|
declare function getGeneratorPlugins(plugins?: Array<{
|
|
241
|
-
|
|
254
|
+
type: PluginType;
|
|
242
255
|
}>): GeneratorPluginV1<unknown>[];
|
|
243
|
-
|
|
244
|
-
export {
|
|
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
|