vovk-hello-world 0.0.1

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/README.md ADDED
@@ -0,0 +1,97 @@
1
+
2
+
3
+ # vovk-hello-world v0.0.1 ![TypeScript](https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555) ![Vovk.ts](https://badgen.net/badge/Built%20with/Vovk.ts/333333?icon=https://vovk.dev/icon-white.svg)
4
+
5
+ > A showcase for Next.js + Vovk.ts + Zod, demonstrating its capabilities with TypeScript, Rust, and Python RPC.
6
+
7
+ License: **MIT**
8
+
9
+ ```bash
10
+ # Install the package
11
+ npm install vovk-hello-world
12
+ ```
13
+
14
+
15
+
16
+ ## UserRPC
17
+
18
+ ### UserRPC.updateUser
19
+ > Update user
20
+
21
+ Update user by ID
22
+
23
+ `POST http://localhost:3000/api/users/{id}`
24
+
25
+ ```ts
26
+ import { UserRPC } from 'vovk-hello-world';
27
+
28
+ const response = await UserRPC.updateUser({
29
+ params: {
30
+ id: "123e4567-e89b-12d3-a456-426614174000"
31
+ },
32
+ body: {
33
+ email: "john@example.com",
34
+ profile: {
35
+ name: "John Doe",
36
+ age: 25
37
+ }
38
+ },
39
+ query: {
40
+ notify: "email"
41
+ },
42
+ });
43
+
44
+ console.log(response);
45
+ /*
46
+ {
47
+ success: true
48
+ }
49
+ */
50
+ ```
51
+
52
+
53
+
54
+ ## StreamRPC
55
+
56
+ ### StreamRPC.streamTokens
57
+ > Stream tokens
58
+
59
+ Stream tokens to the client
60
+
61
+ `GET http://localhost:3000/api/streams/tokens`
62
+
63
+ ```ts
64
+ import { StreamRPC } from 'vovk-hello-world';
65
+
66
+ using response = await StreamRPC.streamTokens();
67
+
68
+ for await (const item of response) {
69
+ console.log(item);
70
+ /*
71
+ {
72
+ message: "string"
73
+ }
74
+ */
75
+ }
76
+ ```
77
+
78
+
79
+
80
+
81
+ ## OpenApiRPC
82
+
83
+ ### OpenApiRPC.getSpec
84
+ > OpenAPI spec
85
+
86
+ Get the OpenAPI spec for the "Hello World" app API
87
+
88
+ `GET http://localhost:3000/api/static/openapi/spec.json`
89
+
90
+ ```ts
91
+ import { OpenApiRPC } from 'vovk-hello-world';
92
+
93
+ const response = await OpenApiRPC.getSpec();
94
+ ```
95
+
96
+
97
+
package/index.cjs ADDED
@@ -0,0 +1,229 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const vovk = __toESM(require("vovk"));
25
+ const vovk_react_query = __toESM(require("vovk-react-query"));
26
+ const vovk_ajv = __toESM(require("vovk-ajv"));
27
+
28
+ //#region .vovk-schema/_meta.json
29
+ var config = {
30
+ "$schema": "https://vovk.dev/api/spec/v3/config.json",
31
+ "libs": {}
32
+ };
33
+ var _meta_default = { config };
34
+
35
+ //#endregion
36
+ //#region .vovk-schema/root.json
37
+ var $schema$1 = "https://vovk.dev/api/spec/v3/segment.json";
38
+ var emitSchema$1 = true;
39
+ var segmentName$1 = "";
40
+ var segmentType$1 = "segment";
41
+ var controllers$1 = {
42
+ "UserRPC": {
43
+ "rpcModuleName": "UserRPC",
44
+ "originalControllerName": "UserController",
45
+ "prefix": "users",
46
+ "handlers": { "updateUser": {
47
+ "validation": {
48
+ "body": {
49
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
50
+ "description": "User data object",
51
+ "type": "object",
52
+ "properties": {
53
+ "email": {
54
+ "description": "User email",
55
+ "examples": ["john@example.com", "jane@example.com"],
56
+ "type": "string",
57
+ "format": "email",
58
+ "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
59
+ },
60
+ "profile": {
61
+ "description": "User profile object",
62
+ "type": "object",
63
+ "properties": {
64
+ "name": {
65
+ "description": "User full name",
66
+ "examples": ["John Doe", "Jane Smith"],
67
+ "type": "string"
68
+ },
69
+ "age": {
70
+ "description": "User age",
71
+ "examples": [25, 30],
72
+ "type": "integer",
73
+ "minimum": 16,
74
+ "maximum": 120
75
+ }
76
+ },
77
+ "required": ["name", "age"],
78
+ "additionalProperties": false
79
+ }
80
+ },
81
+ "required": ["email", "profile"],
82
+ "additionalProperties": false
83
+ },
84
+ "query": {
85
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
86
+ "description": "Query parameters",
87
+ "type": "object",
88
+ "properties": { "notify": {
89
+ "description": "Notification type",
90
+ "type": "string",
91
+ "enum": [
92
+ "email",
93
+ "push",
94
+ "none"
95
+ ]
96
+ } },
97
+ "required": ["notify"],
98
+ "additionalProperties": false
99
+ },
100
+ "params": {
101
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
102
+ "description": "Path parameters",
103
+ "type": "object",
104
+ "properties": { "id": {
105
+ "description": "User ID",
106
+ "examples": ["123e4567-e89b-12d3-a456-426614174000"],
107
+ "type": "string",
108
+ "format": "uuid",
109
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
110
+ } },
111
+ "required": ["id"],
112
+ "additionalProperties": false
113
+ },
114
+ "output": {
115
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
116
+ "description": "Response object",
117
+ "type": "object",
118
+ "properties": { "success": {
119
+ "description": "Success status",
120
+ "type": "boolean"
121
+ } },
122
+ "required": ["success"],
123
+ "additionalProperties": false
124
+ }
125
+ },
126
+ "path": "{id}",
127
+ "httpMethod": "POST",
128
+ "openapi": {
129
+ "summary": "Update user",
130
+ "description": "Update user by ID"
131
+ }
132
+ } }
133
+ },
134
+ "StreamRPC": {
135
+ "rpcModuleName": "StreamRPC",
136
+ "originalControllerName": "StreamController",
137
+ "prefix": "streams",
138
+ "handlers": { "streamTokens": {
139
+ "validation": { "iteration": {
140
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
141
+ "description": "Streamed token object",
142
+ "type": "object",
143
+ "properties": { "message": {
144
+ "description": "Message from the token",
145
+ "type": "string"
146
+ } },
147
+ "required": ["message"],
148
+ "additionalProperties": false
149
+ } },
150
+ "path": "tokens",
151
+ "httpMethod": "GET",
152
+ "openapi": {
153
+ "summary": "Stream tokens",
154
+ "description": "Stream tokens to the client"
155
+ }
156
+ } }
157
+ }
158
+ };
159
+ var root_default = {
160
+ $schema: $schema$1,
161
+ emitSchema: emitSchema$1,
162
+ segmentName: segmentName$1,
163
+ segmentType: segmentType$1,
164
+ controllers: controllers$1
165
+ };
166
+
167
+ //#endregion
168
+ //#region .vovk-schema/static.json
169
+ var $schema = "https://vovk.dev/api/spec/v3/segment.json";
170
+ var emitSchema = true;
171
+ var segmentName = "static";
172
+ var segmentType = "segment";
173
+ var controllers = { "OpenApiRPC": {
174
+ "rpcModuleName": "OpenApiRPC",
175
+ "originalControllerName": "OpenApiController",
176
+ "prefix": "openapi",
177
+ "handlers": { "getSpec": {
178
+ "path": "spec.json",
179
+ "httpMethod": "GET",
180
+ "openapi": {
181
+ "summary": "OpenAPI spec",
182
+ "description": "Get the OpenAPI spec for the \"Hello World\" app API"
183
+ }
184
+ } }
185
+ } };
186
+ var static_default = {
187
+ $schema,
188
+ emitSchema,
189
+ segmentName,
190
+ segmentType,
191
+ controllers
192
+ };
193
+
194
+ //#endregion
195
+ //#region tmp_ts_rpc/schema.ts
196
+ const segments = {
197
+ "": root_default,
198
+ "static": static_default
199
+ };
200
+ const schema = {
201
+ $schema: "https://vovk.dev/api/spec/v3/schema.json",
202
+ segments,
203
+ meta: {
204
+ $schema: "https://vovk.dev/api/spec/v3/meta.json",
205
+ apiRoot: "http://localhost:3000/api",
206
+ ..._meta_default
207
+ }
208
+ };
209
+
210
+ //#endregion
211
+ //#region tmp_ts_rpc/index.ts
212
+ const UserRPC = (0, vovk_react_query.createRPC)(schema, "", "UserRPC", vovk.fetcher, {
213
+ validateOnClient: vovk_ajv.validateOnClient,
214
+ apiRoot: "http://localhost:3000/api"
215
+ });
216
+ const StreamRPC = (0, vovk_react_query.createRPC)(schema, "", "StreamRPC", vovk.fetcher, {
217
+ validateOnClient: vovk_ajv.validateOnClient,
218
+ apiRoot: "http://localhost:3000/api"
219
+ });
220
+ const OpenApiRPC = (0, vovk_react_query.createRPC)(schema, "static", "OpenApiRPC", vovk.fetcher, {
221
+ validateOnClient: vovk_ajv.validateOnClient,
222
+ apiRoot: "http://localhost:3000/api"
223
+ });
224
+
225
+ //#endregion
226
+ exports.OpenApiRPC = OpenApiRPC;
227
+ exports.StreamRPC = StreamRPC;
228
+ exports.UserRPC = UserRPC;
229
+ exports.schema = schema;
package/index.d.cts ADDED
@@ -0,0 +1,373 @@
1
+ import * as vovk0 from "vovk";
2
+ import { VovkClientFetcher } from "vovk";
3
+ import * as _tanstack_react_query8 from "@tanstack/react-query";
4
+ import * as _tanstack_query_core9 from "@tanstack/query-core";
5
+ import * as openapi3_ts_oas3139 from "openapi3-ts/oas31";
6
+
7
+ //#region tmp_ts_rpc/schema.d.ts
8
+ declare const schema: {
9
+ $schema: string;
10
+ segments: {
11
+ '': {
12
+ $schema: string;
13
+ emitSchema: boolean;
14
+ segmentName: string;
15
+ segmentType: string;
16
+ controllers: {
17
+ UserRPC: {
18
+ rpcModuleName: string;
19
+ originalControllerName: string;
20
+ prefix: string;
21
+ handlers: {
22
+ updateUser: {
23
+ validation: {
24
+ body: {
25
+ $schema: string;
26
+ description: string;
27
+ type: string;
28
+ properties: {
29
+ email: {
30
+ description: string;
31
+ examples: string[];
32
+ type: string;
33
+ format: string;
34
+ pattern: string;
35
+ };
36
+ profile: {
37
+ description: string;
38
+ type: string;
39
+ properties: {
40
+ name: {
41
+ description: string;
42
+ examples: string[];
43
+ type: string;
44
+ };
45
+ age: {
46
+ description: string;
47
+ examples: number[];
48
+ type: string;
49
+ minimum: number;
50
+ maximum: number;
51
+ };
52
+ };
53
+ required: string[];
54
+ additionalProperties: boolean;
55
+ };
56
+ };
57
+ required: string[];
58
+ additionalProperties: boolean;
59
+ };
60
+ query: {
61
+ $schema: string;
62
+ description: string;
63
+ type: string;
64
+ properties: {
65
+ notify: {
66
+ description: string;
67
+ type: string;
68
+ enum: string[];
69
+ };
70
+ };
71
+ required: string[];
72
+ additionalProperties: boolean;
73
+ };
74
+ params: {
75
+ $schema: string;
76
+ description: string;
77
+ type: string;
78
+ properties: {
79
+ id: {
80
+ description: string;
81
+ examples: string[];
82
+ type: string;
83
+ format: string;
84
+ pattern: string;
85
+ };
86
+ };
87
+ required: string[];
88
+ additionalProperties: boolean;
89
+ };
90
+ output: {
91
+ $schema: string;
92
+ description: string;
93
+ type: string;
94
+ properties: {
95
+ success: {
96
+ description: string;
97
+ type: string;
98
+ };
99
+ };
100
+ required: string[];
101
+ additionalProperties: boolean;
102
+ };
103
+ };
104
+ path: string;
105
+ httpMethod: string;
106
+ openapi: {
107
+ summary: string;
108
+ description: string;
109
+ };
110
+ };
111
+ };
112
+ };
113
+ StreamRPC: {
114
+ rpcModuleName: string;
115
+ originalControllerName: string;
116
+ prefix: string;
117
+ handlers: {
118
+ streamTokens: {
119
+ validation: {
120
+ iteration: {
121
+ $schema: string;
122
+ description: string;
123
+ type: string;
124
+ properties: {
125
+ message: {
126
+ description: string;
127
+ type: string;
128
+ };
129
+ };
130
+ required: string[];
131
+ additionalProperties: boolean;
132
+ };
133
+ };
134
+ path: string;
135
+ httpMethod: string;
136
+ openapi: {
137
+ summary: string;
138
+ description: string;
139
+ };
140
+ };
141
+ };
142
+ };
143
+ };
144
+ };
145
+ static: {
146
+ $schema: string;
147
+ emitSchema: boolean;
148
+ segmentName: string;
149
+ segmentType: string;
150
+ controllers: {
151
+ OpenApiRPC: {
152
+ rpcModuleName: string;
153
+ originalControllerName: string;
154
+ prefix: string;
155
+ handlers: {
156
+ getSpec: {
157
+ path: string;
158
+ httpMethod: string;
159
+ openapi: {
160
+ summary: string;
161
+ description: string;
162
+ };
163
+ };
164
+ };
165
+ };
166
+ };
167
+ };
168
+ };
169
+ meta: {
170
+ config: {
171
+ $schema: string;
172
+ libs: {};
173
+ };
174
+ $schema: string;
175
+ apiRoot: string;
176
+ };
177
+ };
178
+ //#endregion
179
+ //#region tmp_ts_rpc/index.d.ts
180
+ declare const UserRPC: {
181
+ updateUser: (<R, F extends unknown = vovk0.VovkDefaultFetcherOptions<{
182
+ apiRoot?: string;
183
+ disableClientValidation?: boolean;
184
+ validateOnClient?: vovk0.VovkValidateOnClient;
185
+ interpretAs?: string;
186
+ init?: RequestInit;
187
+ }>>(options: {
188
+ body: {
189
+ email: string;
190
+ profile: {
191
+ name: string;
192
+ age: number;
193
+ };
194
+ };
195
+ query: {
196
+ notify: "email" | "push" | "none";
197
+ };
198
+ params: {
199
+ id: string;
200
+ };
201
+ apiRoot?: string | undefined;
202
+ disableClientValidation?: boolean | undefined;
203
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
204
+ interpretAs?: string | undefined;
205
+ init?: RequestInit | undefined;
206
+ transform?: ((staticMethodReturn: {
207
+ success: true;
208
+ }, resp: Response) => R) | undefined;
209
+ fetcher?: VovkClientFetcher<F> | undefined;
210
+ }) => R extends object ? Promise<Awaited<R>> : Promise<{
211
+ success: true;
212
+ }>) & {
213
+ isRPC: true;
214
+ schema: vovk0.VovkHandlerSchema;
215
+ controllerSchema: vovk0.VovkControllerSchema;
216
+ segmentSchema: vovk0.VovkSegmentSchema;
217
+ fullSchema: vovk0.VovkSchema;
218
+ __types: {
219
+ body: {
220
+ email: string;
221
+ profile: {
222
+ name: string;
223
+ age: number;
224
+ };
225
+ };
226
+ query: {
227
+ notify: "email" | "push" | "none";
228
+ };
229
+ params: {
230
+ id: string;
231
+ };
232
+ output: {
233
+ success: boolean;
234
+ };
235
+ iteration: unknown;
236
+ isForm: false;
237
+ };
238
+ } & {
239
+ useQuery: (input: {
240
+ body: {
241
+ email: string;
242
+ profile: {
243
+ name: string;
244
+ age: number;
245
+ };
246
+ };
247
+ query: {
248
+ notify: "email" | "push" | "none";
249
+ };
250
+ params: {
251
+ id: string;
252
+ };
253
+ apiRoot?: string | undefined;
254
+ disableClientValidation?: boolean | undefined;
255
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
256
+ interpretAs?: string | undefined;
257
+ init?: RequestInit | undefined;
258
+ transform?: ((staticMethodReturn: {
259
+ success: true;
260
+ }, resp: Response) => unknown) | undefined;
261
+ fetcher?: VovkClientFetcher<unknown> | undefined;
262
+ }, options?: Omit<_tanstack_react_query8.UseQueryOptions<Promise<{
263
+ success: true;
264
+ }>, Error, Promise<{
265
+ success: true;
266
+ }>, readonly unknown[]>, "queryFn" | "queryKey"> | undefined, queryClient?: _tanstack_query_core9.QueryClient) => _tanstack_react_query8.UseQueryResult<{
267
+ success: true;
268
+ }, vovk0.HttpException>;
269
+ useMutation: (options?: Omit<_tanstack_react_query8.UseMutationOptions<Promise<{
270
+ success: true;
271
+ }>, Error, void, unknown>, "mutationFn"> | undefined, queryClient?: _tanstack_query_core9.QueryClient) => _tanstack_react_query8.UseMutationResult<{
272
+ success: true;
273
+ }, vovk0.HttpException, {
274
+ body: {
275
+ email: string;
276
+ profile: {
277
+ name: string;
278
+ age: number;
279
+ };
280
+ };
281
+ query: {
282
+ notify: "email" | "push" | "none";
283
+ };
284
+ params: {
285
+ id: string;
286
+ };
287
+ apiRoot?: string | undefined;
288
+ disableClientValidation?: boolean | undefined;
289
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
290
+ interpretAs?: string | undefined;
291
+ init?: RequestInit | undefined;
292
+ transform?: ((staticMethodReturn: {
293
+ success: true;
294
+ }, resp: Response) => unknown) | undefined;
295
+ fetcher?: VovkClientFetcher<unknown> | undefined;
296
+ }, unknown>;
297
+ };
298
+ };
299
+ declare const StreamRPC: {
300
+ streamTokens: (<R, F extends unknown = vovk0.VovkDefaultFetcherOptions<{
301
+ apiRoot?: string;
302
+ disableClientValidation?: boolean;
303
+ validateOnClient?: vovk0.VovkValidateOnClient;
304
+ interpretAs?: string;
305
+ init?: RequestInit;
306
+ }>>(options?: {
307
+ apiRoot?: string | undefined;
308
+ disableClientValidation?: boolean | undefined;
309
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
310
+ interpretAs?: string | undefined;
311
+ init?: RequestInit | undefined;
312
+ transform?: ((staticMethodReturn: AsyncGenerator<{
313
+ message: string;
314
+ }, void, unknown>, resp: Response) => R) | undefined;
315
+ fetcher?: VovkClientFetcher<F> | undefined;
316
+ } | undefined) => Promise<vovk0.VovkStreamAsyncIterable<{
317
+ message: string;
318
+ }>>) & {
319
+ isRPC: true;
320
+ schema: vovk0.VovkHandlerSchema;
321
+ controllerSchema: vovk0.VovkControllerSchema;
322
+ segmentSchema: vovk0.VovkSegmentSchema;
323
+ fullSchema: vovk0.VovkSchema;
324
+ __types: {
325
+ body: unknown;
326
+ query: unknown;
327
+ params: unknown;
328
+ output: unknown;
329
+ iteration: {
330
+ message: string;
331
+ };
332
+ isForm: false;
333
+ };
334
+ } & {
335
+ useQuery: (input?: {
336
+ apiRoot?: string | undefined;
337
+ disableClientValidation?: boolean | undefined;
338
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
339
+ interpretAs?: string | undefined;
340
+ init?: RequestInit | undefined;
341
+ transform?: ((staticMethodReturn: AsyncGenerator<{
342
+ message: string;
343
+ }, void, unknown>, resp: Response) => unknown) | undefined;
344
+ fetcher?: VovkClientFetcher<unknown> | undefined;
345
+ } | undefined, options?: Omit<_tanstack_react_query8.UseQueryOptions<Promise<vovk0.VovkStreamAsyncIterable<{
346
+ message: string;
347
+ }>>, Error, Promise<vovk0.VovkStreamAsyncIterable<{
348
+ message: string;
349
+ }>>, readonly unknown[]>, "queryFn" | "queryKey"> | undefined, queryClient?: _tanstack_query_core9.QueryClient) => _tanstack_react_query8.UseQueryResult<{
350
+ message: string;
351
+ }[], vovk0.HttpException>;
352
+ useMutation: (options?: Omit<_tanstack_react_query8.UseMutationOptions<Promise<vovk0.VovkStreamAsyncIterable<{
353
+ message: string;
354
+ }>>, Error, void, unknown>, "mutationFn"> | undefined, queryClient?: _tanstack_query_core9.QueryClient) => _tanstack_react_query8.UseMutationResult<vovk0.VovkStreamAsyncIterable<{
355
+ message: string;
356
+ }>, vovk0.HttpException, {
357
+ apiRoot?: string | undefined;
358
+ disableClientValidation?: boolean | undefined;
359
+ validateOnClient?: vovk0.VovkValidateOnClient | undefined;
360
+ interpretAs?: string | undefined;
361
+ init?: RequestInit | undefined;
362
+ transform?: ((staticMethodReturn: AsyncGenerator<{
363
+ message: string;
364
+ }, void, unknown>, resp: Response) => unknown) | undefined;
365
+ fetcher?: VovkClientFetcher<unknown> | undefined;
366
+ } | undefined, unknown>;
367
+ };
368
+ };
369
+ declare const OpenApiRPC: {
370
+ getSpec: () => Promise<openapi3_ts_oas3139.OpenAPIObject>;
371
+ };
372
+ //#endregion
373
+ export { OpenApiRPC, StreamRPC, UserRPC, schema };