@tuyau/core 0.4.1 → 1.0.0-beta.0

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.
@@ -0,0 +1,195 @@
1
+ import { Options } from 'ky';
2
+ import { ClientRouteMatchItTokens } from '@adonisjs/http-server/client/url_builder';
3
+
4
+ /**
5
+ * Supported HTTP methods for API endpoints
6
+ */
7
+ type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
8
+ /**
9
+ * Definition of an AdonisJS endpoint with types and metadata
10
+ */
11
+ interface AdonisEndpoint {
12
+ methods: Method[];
13
+ pattern: string;
14
+ tokens: ClientRouteMatchItTokens[];
15
+ types: {
16
+ paramsTuple: [...any[]];
17
+ params: Record<string, string | number | boolean>;
18
+ query: Record<string, any>;
19
+ body: unknown;
20
+ response: unknown;
21
+ };
22
+ }
23
+ /**
24
+ * Registry mapping endpoint names to their definitions
25
+ */
26
+ type AdonisRegistry = Record<string, AdonisEndpoint>;
27
+ type ValueOf<T> = T[keyof T];
28
+ type IsEmptyObj<T> = keyof T extends never ? true : false;
29
+ type IsEmptyTuple<T> = T extends [] ? true : false;
30
+ type Endpoints = ValueOf<AdonisRegistry>;
31
+ type EndpointByName<Name extends keyof AdonisRegistry & string> = AdonisRegistry[Name];
32
+ /**
33
+ * Checks if a type has any keys
34
+ */
35
+ type HasKeys<T> = keyof T extends never ? false : true;
36
+ /**
37
+ * Checks if a type has required keys (non-optional properties)
38
+ */
39
+ type HasRequiredKeys<T> = T extends Record<string, any> ? keyof T extends never ? false : {} extends Pick<T, keyof T> ? false : true : false;
40
+ /**
41
+ * Constructs the request arguments type for an endpoint
42
+ */
43
+ type RequestArgs<E extends AdonisEndpoint> = (HasKeys<E['types']['params']> extends true ? HasRequiredKeys<E['types']['params']> extends true ? {
44
+ params: E['types']['params'];
45
+ } : {
46
+ params?: E['types']['params'];
47
+ } : {}) & (E['types']['query'] extends object ? HasRequiredKeys<E['types']['query']> extends true ? {
48
+ query: E['types']['query'];
49
+ } : {
50
+ query?: E['types']['query'];
51
+ } : {}) & (E['types']['body'] extends never | undefined ? {} : HasRequiredKeys<E['types']['body']> extends true ? {
52
+ body: E['types']['body'];
53
+ } : {
54
+ body?: E['types']['body'];
55
+ }) & Omit<Options, 'body' | 'params' | 'searchParams' | 'method' | 'json' | 'prefixUrl'>;
56
+ /**
57
+ * Extracts response type from an endpoint
58
+ */
59
+ type ResponseOf<E extends AdonisEndpoint> = E['types']['response'];
60
+ /**
61
+ * Splits a dot-separated string into an array of strings
62
+ */
63
+ type Split<S extends string> = S extends `${infer H}.${infer T}` ? [H, ...Split<T>] : [S];
64
+ /**
65
+ * Converts a union type to an intersection type
66
+ */
67
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
68
+ /**
69
+ * Builds a nested object type for the fluent API based on endpoint names
70
+ */
71
+ type BuildNamed<Reg extends Record<string, AdonisEndpoint>> = UnionToIntersection<{
72
+ [K in keyof Reg & string]: SetAtPath<Split<K>, EndpointFn<Reg[K]>>;
73
+ }[keyof Reg & string]>;
74
+ /**
75
+ * Sets a value at a specific path in a nested object type
76
+ */
77
+ type SetAtPath<Path extends string[], V> = Path extends [
78
+ infer H extends string,
79
+ ...infer T extends string[]
80
+ ] ? {
81
+ [K in H]: T['length'] extends 0 ? V : SetAtPath<T, V>;
82
+ } : {};
83
+ /**
84
+ * Function type for calling an endpoint
85
+ */
86
+ type EndpointFn<E extends AdonisEndpoint> = (args: RequestArgs<E>) => Promise<E['types']['response']>;
87
+ /**
88
+ * Filters endpoints by HTTP method
89
+ */
90
+ type EndpointsByMethod<Reg extends Record<string, AdonisEndpoint>, M extends Method> = {
91
+ [K in keyof Reg]: M extends Reg[K]['methods'][number] ? Reg[K] : never;
92
+ }[keyof Reg];
93
+ type StrKeys<R> = Extract<keyof R, string>;
94
+ type RegValues<R> = R[StrKeys<R>];
95
+ /**
96
+ * Gets URL patterns for endpoints matching a specific HTTP method
97
+ */
98
+ type PatternsByMethod<Reg extends Record<string, AdonisEndpoint>, M extends Method> = EndpointsByMethod<Reg, M>['pattern'];
99
+ /**
100
+ * Finds an endpoint by HTTP method and URL pattern
101
+ */
102
+ type EndpointByMethodPattern<R extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<R, M>> = FilterByMethodPathForRegistry<R, M, P>;
103
+ /**
104
+ * Plugin function type for extending Tuyau functionality
105
+ */
106
+ type TuyauPlugin = (params: {
107
+ options: TuyauConfiguration<any>;
108
+ }) => void;
109
+ type MaybeArray<T> = T | T[];
110
+ /**
111
+ * Type for URL query parameters
112
+ */
113
+ type QueryParameters = Record<string, MaybeArray<string | number | boolean | null | undefined>>;
114
+ /**
115
+ * Configuration options for creating a Tuyau client
116
+ */
117
+ type TuyauConfiguration<T extends Record<string, AdonisEndpoint>> = Omit<Options, 'prefixUrl' | 'body' | 'json' | 'method' | 'searchParams'> & {
118
+ registry: T;
119
+ baseUrl: string;
120
+ plugins?: TuyauPlugin[];
121
+ };
122
+ /**
123
+ * Should be augmented by the user to provide their endpoint registry
124
+ */
125
+ interface UserRegistry {
126
+ }
127
+ type UserAdonisRegistry = UserRegistry extends Record<string, AdonisEndpoint> ? UserRegistry : Record<string, AdonisEndpoint>;
128
+ type UserEndpointByName<Name extends keyof UserAdonisRegistry> = UserAdonisRegistry[Name];
129
+ type FilterByMethodPathForRegistry<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends ValueOf<Reg>['pattern'] & string> = {
130
+ [K in keyof Reg]: [Reg[K]['pattern'], M] extends [P, Reg[K]['methods'][number]] ? Reg[K] : never;
131
+ }[keyof Reg];
132
+ type EndpointByNameForRegistry<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = Reg[Name];
133
+ /**
134
+ * Internal type utilities for working with endpoints by HTTP method and path pattern
135
+ * Accepts a registry as generic parameter
136
+ */
137
+ declare namespace PathWithRegistry {
138
+ type Request<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = RequestArgs<FilterByMethodPathForRegistry<Reg, M, P>>;
139
+ type Response<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = ResponseOf<FilterByMethodPathForRegistry<Reg, M, P>>;
140
+ type Params<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['params'];
141
+ type Body<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['body'];
142
+ type Query<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['query'];
143
+ }
144
+ /**
145
+ * Internal type utilities for working with endpoints by route name
146
+ * Accepts a registry as generic parameter
147
+ */
148
+ declare namespace RouteWithRegistry {
149
+ type Request<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = RequestArgs<EndpointByNameForRegistry<Reg, Name>>;
150
+ type Response<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = ResponseOf<EndpointByNameForRegistry<Reg, Name>>;
151
+ type Params<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['params'];
152
+ type Body<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['body'];
153
+ type Query<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['query'];
154
+ }
155
+ /**
156
+ * Type utilities for working with endpoints by HTTP method and path pattern
157
+ * Uses the user-augmented registry
158
+ */
159
+ declare namespace Path {
160
+ type Request<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = RequestArgs<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>;
161
+ type Response<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = ResponseOf<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>;
162
+ type Params<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['params'];
163
+ type Body<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['body'];
164
+ type Query<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['query'];
165
+ }
166
+ /**
167
+ * Type utilities for working with endpoints by route name
168
+ * Uses the user-augmented registry
169
+ */
170
+ declare namespace Route {
171
+ type Request<Name extends keyof UserAdonisRegistry> = RequestArgs<UserEndpointByName<Name>>;
172
+ type Response<Name extends keyof UserAdonisRegistry> = ResponseOf<UserEndpointByName<Name>>;
173
+ type Params<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['params'];
174
+ type Body<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['body'];
175
+ type Query<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['query'];
176
+ }
177
+ type ParamsShape<E> = E extends {
178
+ types: {
179
+ paramsTuple: infer PT;
180
+ params: infer P;
181
+ };
182
+ } ? (IsEmptyTuple<PT> extends true ? {
183
+ paramsTuple?: PT;
184
+ } : {
185
+ paramsTuple: PT;
186
+ }) & (IsEmptyObj<P> extends true ? {} : {
187
+ params: P;
188
+ }) : never;
189
+ type RegistryGroupedByMethod<R extends Record<string, AdonisEndpoint>, M extends Method = Method> = {
190
+ [K in M | 'ALL']: {
191
+ [Route in keyof R as K extends 'ALL' ? Route : K extends R[Route]['methods'][number] ? Route : never]: ParamsShape<R[Route]>;
192
+ };
193
+ };
194
+
195
+ export { type AdonisEndpoint, type AdonisRegistry, type BuildNamed, type EndpointByMethodPattern, type EndpointByName, type Endpoints, type EndpointsByMethod, type HasKeys, type HasRequiredKeys, type MaybeArray, type Method, Path, PathWithRegistry, type PatternsByMethod, type QueryParameters, type RegValues, type RegistryGroupedByMethod, type RequestArgs, type ResponseOf, Route, RouteWithRegistry, type SetAtPath, type Split, type StrKeys, type TuyauConfiguration, type TuyauPlugin, type UnionToIntersection, type UserRegistry, type ValueOf };
@@ -1 +1 @@
1
- {"commands":[{"commandName":"tuyau:generate","description":"Tuyau generator command","help":"","namespace":"tuyau","aliases":[],"flags":[{"name":"verbose","flagName":"verbose","required":false,"type":"boolean","description":"Verbose logs","default":false,"alias":"v"}],"args":[],"options":{"startApp":true},"filePath":"generate.js"}],"version":1}
1
+ {"commands":[],"version":1}
package/package.json CHANGED
@@ -1,41 +1,49 @@
1
1
  {
2
2
  "name": "@tuyau/core",
3
3
  "type": "module",
4
- "version": "0.4.1",
5
- "description": "",
6
- "author": "",
4
+ "version": "1.0.0-beta.0",
5
+ "description": "e2e client for AdonisJS",
6
+ "author": "Julien Ripouteau <julien@ripouteau.com>",
7
7
  "license": "MIT",
8
- "keywords": [],
8
+ "keywords": [
9
+ "adonisjs",
10
+ "e2e",
11
+ "client"
12
+ ],
9
13
  "exports": {
10
- ".": "./build/index.js",
11
- "./types": "./build/src/types.js",
14
+ "./client": "./build/client/index.js",
15
+ "./types": "./build/client/types/index.js",
12
16
  "./commands": "./build/commands/main.js",
13
- "./tuyau_provider": "./build/providers/tuyau_provider.js",
14
- "./build_hook": "./build/src/hooks/build_hook.js"
17
+ "./hooks": "./build/backend/generate_registry.js"
15
18
  },
16
19
  "files": [
17
20
  "build"
18
21
  ],
19
22
  "engines": {
20
- "node": ">=20.6.0"
23
+ "node": ">=24.0.0"
21
24
  },
22
25
  "peerDependencies": {
23
- "@adonisjs/core": "^6.2.0"
26
+ "@adonisjs/assembler": "8.0.0-next.19",
27
+ "@adonisjs/core": "7.0.0-next.8"
24
28
  },
25
29
  "dependencies": {
26
- "ts-morph": "^25.0.1",
27
- "@tuyau/utils": "0.0.8"
30
+ "ky": "^1.14.0",
31
+ "object-to-formdata": "^4.5.1"
28
32
  },
29
33
  "devDependencies": {
30
- "@adonisjs/assembler": "^7.8.2",
31
- "@adonisjs/core": "^6.18.0",
32
- "@poppinss/cliui": "^6.4.3",
33
- "@poppinss/matchit": "^3.1.2",
34
- "@tuyau/client": "0.2.9"
34
+ "@adonisjs/assembler": "8.0.0-next.19",
35
+ "@adonisjs/core": "7.0.0-next.8",
36
+ "@adonisjs/http-server": "8.0.0-next.12",
37
+ "@arktype/attest": "^0.53.0",
38
+ "@faker-js/faker": "^10.1.0",
39
+ "@poppinss/ts-exec": "^1.4.1",
40
+ "@types/node": "^24.10.0",
41
+ "@typescript/analyze-trace": "^0.10.1",
42
+ "@vinejs/vine": "^4.1.0"
35
43
  },
36
44
  "publishConfig": {
37
45
  "access": "public",
38
- "tag": "latest"
46
+ "tag": "beta"
39
47
  },
40
48
  "c8": {
41
49
  "reporter": [
@@ -48,11 +56,9 @@
48
56
  },
49
57
  "tsup": {
50
58
  "entry": [
51
- "./index.ts",
52
- "./src/types.ts",
53
- "./src/hooks/build_hook.ts",
54
- "./commands/generate.ts",
55
- "./providers/tuyau_provider.ts"
59
+ "./src/backend/generate_registry.ts",
60
+ "./src/client/index.ts",
61
+ "./src/client/types/index.ts"
56
62
  ],
57
63
  "outDir": "./build",
58
64
  "clean": false,
@@ -65,7 +71,7 @@
65
71
  "copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
66
72
  "typecheck": "tsc --noEmit",
67
73
  "format": "prettier --write .",
68
- "quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
74
+ "quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts --force-exit",
69
75
  "test": "c8 npm run quick:test",
70
76
  "index:commands": "adonis-kit index build/commands",
71
77
  "prebuild": "npm run clean",
@@ -1,14 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result) __defProp(target, key, result);
9
- return result;
10
- };
11
-
12
- export {
13
- __decorateClass
14
- };
@@ -1,16 +0,0 @@
1
- import { BaseCommand } from '@adonisjs/core/ace';
2
- import { CommandOptions } from '@adonisjs/core/types/ace';
3
-
4
- declare class CodegenTypes extends BaseCommand {
5
- #private;
6
- static commandName: string;
7
- static description: string;
8
- static options: CommandOptions;
9
- verbose: boolean;
10
- /**
11
- * Execute command
12
- */
13
- run(): Promise<void>;
14
- }
15
-
16
- export { CodegenTypes as default };