@arrirpc/codegen-ts 0.45.4 → 0.45.6

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 CHANGED
@@ -1,11 +1,104 @@
1
- # arri-codegen-ts
1
+ # Arri Typescript Codegen
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## Setup
4
+
5
+ ### 1) Add the generator to your arri config
6
+
7
+ ```ts
8
+ // arri.config.ts
9
+ import { defineConfig, typescriptClientGenerator } from "arri";
10
+
11
+ export default defineConfig({
12
+ generators: [
13
+ typescriptClientGenerator({
14
+ clientName: "MyClient",
15
+ outputFile: "./client/src/myClient.g.ts",
16
+ }),
17
+ ],
18
+ });
19
+ ```
20
+
21
+ **Options:**
22
+
23
+ | Name | Description |
24
+ | --------------------- | ---------------------------------------------------- |
25
+ | clientName (required) | The name of the generated client |
26
+ | outputFile (required) | Path to a file that will be created by the generator |
27
+ | prettierOptions | Formatting options for the generated code |
28
+
29
+ ### 2) Install the TS client library
30
+
31
+ Make sure that the project that will be using the generated code has the client library installed. The version number should match your arri cli version.
32
+
33
+ ```bash
34
+ # npm
35
+ npm i @arrirpc/client
36
+
37
+ # pnpm
38
+ pnpm i --save @arrirpc/client
39
+ ```
40
+
41
+ ## Using the Generated Code
42
+
43
+ ### Initialize the client
44
+
45
+ ```ts
46
+ // This will match whatever you put in the arri config
47
+ import { MyClient } from "./myClient.g";
48
+
49
+ const client = new MyClient({
50
+ baseUrl: "https://example.com",
51
+ headers: () => {
52
+ return {
53
+ Authorization: "<some-token>",
54
+ };
55
+ },
56
+ });
57
+
58
+ await client.myProcedure();
59
+ ```
60
+
61
+ The root client will be a class containing all of the services and procedures in a single class. If you only need a particular service. You can also import just that service.
62
+
63
+ For example if we have a some procedures grouped under `"users"` we can import just that service like so.
64
+
65
+ ```ts
66
+ import { MyClientUsersService } from "./myClient.g";
67
+
68
+ const usersService = new MyClientUsersService({
69
+ baseUrl: "https://example.com",
70
+ headers: () => {
71
+ return {
72
+ Authorization: "<some-token>",
73
+ };
74
+ },
75
+ });
76
+
77
+ usersService.someProcedure();
78
+ ```
79
+
80
+ ### Importing and using types
81
+
82
+ All generated types and serializers/parsers can be imported from the generated code as well. Types will match the ID given to them in the schema. Serialization and parsing helpers will be prefixed with a `$$`
83
+
84
+ ```ts
85
+ // import the user type and the user helper
86
+ import { type User, $$User } from "./myClient.g";
87
+
88
+ const bob: User = {
89
+ // field
90
+ };
91
+
92
+ $$User.serialize(bob); // outputs valid JSON
93
+ $$User.parse("<some-json-string>"); // outputs a User
94
+ ```
95
+
96
+ # Development
4
97
 
5
98
  ## Building
6
99
 
7
- Run `nx build arri-codegen-ts` to build the library.
100
+ Run `nx build ts-codegen` to build the library.
8
101
 
9
102
  ## Running unit tests
10
103
 
11
- Run `nx test arri-codegen-ts` to execute the unit tests via [Vitest](https://vitest.dev).
104
+ Run `nx test ts-codegen` to execute the unit tests via [Vitest](https://vitest.dev).
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
3
  const codegenUtils = require('@arrirpc/codegen-utils');
5
4
  const schema = require('@arrirpc/schema');
5
+ const fs = require('fs');
6
6
  const prettier = require('prettier');
7
7
 
8
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { writeFileSync } from 'fs';
2
1
  import { defineClientGeneratorPlugin, pascalCase, unflattenProcedures, isRpcDefinition, isServiceDefinition, isSchemaFormProperties, isSchemaFormDiscriminator, isSchemaFormType, isSchemaFormEnum, isSchemaFormElements, isSchemaFormValues, isSchemaFormRef, camelCase } from '@arrirpc/codegen-utils';
3
2
  import { getSchemaParsingCode, getSchemaSerializationCode } from '@arrirpc/schema';
3
+ import { writeFileSync } from 'fs';
4
4
  import prettier from 'prettier';
5
5
 
6
6
  const typescriptClientGenerator = defineClientGeneratorPlugin(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/codegen-ts",
3
- "version": "0.45.4",
3
+ "version": "0.45.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -22,12 +22,11 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "ajv": "^8.13.0",
26
25
  "prettier": "^3.2.5",
27
- "@arrirpc/schema": "0.45.4",
28
- "@arrirpc/codegen-utils": "0.45.4"
26
+ "@arrirpc/codegen-utils": "0.45.6",
27
+ "@arrirpc/schema": "0.45.6"
29
28
  },
30
29
  "devDependencies": {
31
- "@arrirpc/client": "0.45.4"
30
+ "@arrirpc/client": "0.45.6"
32
31
  }
33
32
  }