@noxickon/onyx 6.5.0 → 6.6.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,3 @@
1
+ import { OxExecutor } from '../../hooks';
2
+ import { ConnectCall, ConnectExecutorOptions } from './connectExecutor.types';
3
+ export declare function connectExecutor<TForm extends object, TResult = unknown>(call: ConnectCall<TForm, TResult>, options?: ConnectExecutorOptions<TForm>): OxExecutor<TForm, TResult>;
@@ -0,0 +1,21 @@
1
+ import { formErrors as e } from "../../hooks/useForm/useForm.js";
2
+ import { defaultParseErrors as t } from "./errorDetails.js";
3
+ import { ConnectError as n } from "@connectrpc/connect";
4
+ //#region src/connect/executors/connectExecutor.ts
5
+ function r(r, i = {}) {
6
+ let { parseErrors: a = t } = i;
7
+ return async ({ payload: t, signal: i, url: o }) => {
8
+ if (o !== void 0) throw Error("connectExecutor: ctx.url is meaningless for RPC (the call closes over its own client and endpoint)");
9
+ try {
10
+ return await r(t, { signal: i });
11
+ } catch (t) {
12
+ if (t instanceof n) {
13
+ let n = a(t);
14
+ if (n !== null) return e(n);
15
+ }
16
+ throw t;
17
+ }
18
+ };
19
+ }
20
+ //#endregion
21
+ export { r as connectExecutor };
@@ -0,0 +1,8 @@
1
+ import { ConnectError } from '@connectrpc/connect';
2
+ import { OxFormDataErrors } from '../../internal/hooks';
3
+ export type ConnectCall<TForm extends object, TResult> = (payload: TForm, options: {
4
+ signal: AbortSignal;
5
+ }) => Promise<TResult>;
6
+ export interface ConnectExecutorOptions<TForm extends object> {
7
+ parseErrors?: (error: ConnectError) => OxFormDataErrors<TForm> | null;
8
+ }
@@ -0,0 +1,9 @@
1
+ import { ConnectError } from '@connectrpc/connect';
2
+ import { OxFormDataErrors } from '../../internal/hooks';
3
+ export interface OxConnectErrorInfo {
4
+ domain: string;
5
+ metadata: Record<string, string>;
6
+ reason: string;
7
+ }
8
+ export declare function connectErrorInfo(error: ConnectError): OxConnectErrorInfo | null;
9
+ export declare function defaultParseErrors<TForm extends object>(error: ConnectError): OxFormDataErrors<TForm> | null;
@@ -0,0 +1,21 @@
1
+ import { BadRequestSchema as e, ErrorInfoSchema as t } from "../schemas/error_details_pb.js";
2
+ import { Code as n } from "@connectrpc/connect";
3
+ //#region src/connect/executors/errorDetails.ts
4
+ function r(e) {
5
+ let [n] = e.findDetails(t);
6
+ return n ? {
7
+ domain: n.domain,
8
+ metadata: n.metadata,
9
+ reason: n.reason
10
+ } : null;
11
+ }
12
+ function i(t) {
13
+ if (t.code !== n.InvalidArgument) return null;
14
+ let [r] = t.findDetails(e);
15
+ if (!r) return null;
16
+ let i = {};
17
+ for (let { description: e, field: t } of r.fieldViolations) t && !Object.hasOwn(i, t) && (i[t] = e);
18
+ return Object.keys(i).length > 0 ? i : null;
19
+ }
20
+ //#endregion
21
+ export { r as connectErrorInfo, i as defaultParseErrors };
@@ -0,0 +1,4 @@
1
+ export { connectExecutor } from './executors/connectExecutor';
2
+ export type { ConnectCall, ConnectExecutorOptions } from './executors/connectExecutor.types';
3
+ export { connectErrorInfo } from './executors/errorDetails';
4
+ export type { OxConnectErrorInfo } from './executors/errorDetails';
@@ -0,0 +1,62 @@
1
+ import { GenFile, GenMessage } from '@bufbuild/protobuf/codegenv2';
2
+ import { Message } from '@bufbuild/protobuf';
3
+ /**
4
+ * Describes the file error_details.proto.
5
+ */
6
+ export declare const file_error_details: GenFile;
7
+ /**
8
+ * @generated from message google.rpc.ErrorInfo
9
+ */
10
+ export type ErrorInfo = Message<"google.rpc.ErrorInfo"> & {
11
+ /**
12
+ * @generated from field: string reason = 1;
13
+ */
14
+ reason: string;
15
+ /**
16
+ * @generated from field: string domain = 2;
17
+ */
18
+ domain: string;
19
+ /**
20
+ * @generated from field: map<string, string> metadata = 3;
21
+ */
22
+ metadata: {
23
+ [key: string]: string;
24
+ };
25
+ };
26
+ /**
27
+ * Describes the message google.rpc.ErrorInfo.
28
+ * Use `create(ErrorInfoSchema)` to create a new message.
29
+ */
30
+ export declare const ErrorInfoSchema: GenMessage<ErrorInfo>;
31
+ /**
32
+ * @generated from message google.rpc.BadRequest
33
+ */
34
+ export type BadRequest = Message<"google.rpc.BadRequest"> & {
35
+ /**
36
+ * @generated from field: repeated google.rpc.BadRequest.FieldViolation field_violations = 1;
37
+ */
38
+ fieldViolations: BadRequest_FieldViolation[];
39
+ };
40
+ /**
41
+ * Describes the message google.rpc.BadRequest.
42
+ * Use `create(BadRequestSchema)` to create a new message.
43
+ */
44
+ export declare const BadRequestSchema: GenMessage<BadRequest>;
45
+ /**
46
+ * @generated from message google.rpc.BadRequest.FieldViolation
47
+ */
48
+ export type BadRequest_FieldViolation = Message<"google.rpc.BadRequest.FieldViolation"> & {
49
+ /**
50
+ * @generated from field: string field = 1;
51
+ */
52
+ field: string;
53
+ /**
54
+ * @generated from field: string description = 2;
55
+ */
56
+ description: string;
57
+ };
58
+ /**
59
+ * Describes the message google.rpc.BadRequest.FieldViolation.
60
+ * Use `create(BadRequest_FieldViolationSchema)` to create a new message.
61
+ */
62
+ export declare const BadRequest_FieldViolationSchema: GenMessage<BadRequest_FieldViolation>;
@@ -0,0 +1,5 @@
1
+ import { fileDesc as e, messageDesc as t } from "@bufbuild/protobuf/codegenv2";
2
+ //#region src/connect/schemas/error_details_pb.ts
3
+ var n = /*@__PURE__*/ e("ChNlcnJvcl9kZXRhaWxzLnByb3RvEgpnb29nbGUucnBjIpMBCglFcnJvckluZm8SDgoGcmVhc29uGAEgASgJEg4KBmRvbWFpbhgCIAEoCRI1CghtZXRhZGF0YRgDIAMoCzIjLmdvb2dsZS5ycGMuRXJyb3JJbmZvLk1ldGFkYXRhRW50cnkaLwoNTWV0YWRhdGFFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBIoMBCgpCYWRSZXF1ZXN0Ej8KEGZpZWxkX3Zpb2xhdGlvbnMYASADKAsyJS5nb29nbGUucnBjLkJhZFJlcXVlc3QuRmllbGRWaW9sYXRpb24aNAoORmllbGRWaW9sYXRpb24SDQoFZmllbGQYASABKAkSEwoLZGVzY3JpcHRpb24YAiABKAliBnByb3RvMw"), r = /*@__PURE__*/ t(n, 0), i = /*@__PURE__*/ t(n, 1);
4
+ //#endregion
5
+ export { i as BadRequestSchema, r as ErrorInfoSchema, n as file_error_details };
@@ -0,0 +1,3 @@
1
+ import { connectErrorInfo as e } from "./connect/executors/errorDetails.js";
2
+ import { connectExecutor as t } from "./connect/executors/connectExecutor.js";
3
+ export { e as connectErrorInfo, t as connectExecutor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxickon/onyx",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -26,6 +26,10 @@
26
26
  "types": "./dist/rest/index.d.ts",
27
27
  "import": "./dist/rest.js"
28
28
  },
29
+ "./connect": {
30
+ "types": "./dist/connect/index.d.ts",
31
+ "import": "./dist/connect.js"
32
+ },
29
33
  "./graphql": {
30
34
  "types": "./dist/graphql/index.d.ts",
31
35
  "import": "./dist/graphql.js"
@@ -68,6 +72,8 @@
68
72
  },
69
73
  "peerDependencies": {
70
74
  "@apollo/client": "^4.2.3",
75
+ "@bufbuild/protobuf": "^2.7.0",
76
+ "@connectrpc/connect": "^2.0.0",
71
77
  "@tiptap/extension-placeholder": "^3.0.0",
72
78
  "@tiptap/pm": "^3.0.0",
73
79
  "@tiptap/react": "^3.0.0",
@@ -83,6 +89,12 @@
83
89
  "@apollo/client": {
84
90
  "optional": true
85
91
  },
92
+ "@bufbuild/protobuf": {
93
+ "optional": true
94
+ },
95
+ "@connectrpc/connect": {
96
+ "optional": true
97
+ },
86
98
  "graphql": {
87
99
  "optional": true
88
100
  },
@@ -119,7 +131,9 @@
119
131
  },
120
132
  "devDependencies": {
121
133
  "@apollo/client": "^4.2.3",
134
+ "@bufbuild/protobuf": "^2.12.1",
122
135
  "@chromatic-com/storybook": "^5.0.0",
136
+ "@connectrpc/connect": "^2.1.2",
123
137
  "@eslint-react/eslint-plugin": "^5.9.0",
124
138
  "@eslint/js": "^10.0.0",
125
139
  "@noxickon/codex": "^4.0.4",