@trpc/next 11.0.0-next-beta.206 → 11.0.0-next-beta.216

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.
@@ -1,107 +1,8 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var client = require('@trpc/client');
6
4
  var core = require('@trpc/core');
7
- var observable = require('@trpc/core/observable');
8
- var React = require('react');
9
- var shared = require('../shared-a452b80f.js');
10
-
11
- // ts-prune-ignore-next
12
- function experimental_serverActionLink() {
13
- return (runtime)=>({ op })=>observable.observable((observer)=>{
14
- const context = op.context;
15
- context._action(shared.isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
16
- const transformed = core.transformResult(data, runtime.transformer);
17
- if (!transformed.ok) {
18
- observer.error(client.TRPCClientError.from(transformed.error, {}));
19
- return;
20
- }
21
- observer.next({
22
- context: op.context,
23
- result: transformed.result
24
- });
25
- observer.complete();
26
- }).catch((cause)=>{
27
- observer.error(client.TRPCClientError.from(cause));
28
- });
29
- });
30
- }
31
- // ts-prune-ignore-next
32
- function experimental_createActionHook(opts) {
33
- const client$1 = client.createTRPCUntypedClient(opts);
34
- return function useAction(handler, useActionOpts) {
35
- const count = React.useRef(0);
36
- const [state, setState] = React.useState({
37
- status: 'idle'
38
- });
39
- const actionOptsRef = React.useRef(useActionOpts);
40
- actionOptsRef.current = useActionOpts;
41
- React.useEffect(()=>{
42
- return ()=>{
43
- // cleanup after unmount to prevent calling hook opts after unmount
44
- count.current = -1;
45
- actionOptsRef.current = undefined;
46
- };
47
- }, []);
48
- const mutateAsync = React.useCallback((input, requestOptions)=>{
49
- const idx = ++count.current;
50
- const context = {
51
- ...requestOptions?.context,
52
- _action (innerInput) {
53
- return handler(innerInput);
54
- }
55
- };
56
- setState({
57
- status: 'loading'
58
- });
59
- return client$1.mutation('serverAction', input, {
60
- ...requestOptions,
61
- context
62
- }).then(async (data)=>{
63
- await actionOptsRef.current?.onSuccess?.(data);
64
- if (idx !== count.current) {
65
- return;
66
- }
67
- setState({
68
- status: 'success',
69
- data: data
70
- });
71
- }).catch(async (error)=>{
72
- await actionOptsRef.current?.onError?.(error);
73
- throw error;
74
- }).catch((error)=>{
75
- if (idx !== count.current) {
76
- return;
77
- }
78
- setState({
79
- status: 'error',
80
- error: client.TRPCClientError.from(error, {})
81
- });
82
- throw error;
83
- });
84
- }, [
85
- handler
86
- ]);
87
- const mutate = React.useCallback((...args)=>{
88
- void mutateAsync(...args).catch(()=>{
89
- // ignored
90
- });
91
- }, [
92
- mutateAsync
93
- ]);
94
- return React.useMemo(()=>({
95
- ...state,
96
- mutate,
97
- mutateAsync
98
- }), [
99
- mutate,
100
- mutateAsync,
101
- state
102
- ]);
103
- };
104
- }
5
+ var createActionHook = require('./create-action-hook.js');
105
6
 
106
7
  // ts-prune-ignore-next
107
8
  function experimental_createTRPCNextAppDirClient(opts) {
@@ -142,6 +43,6 @@ function experimental_createTRPCNextAppDirClient(opts) {
142
43
  // });
143
44
  }
144
45
 
145
- exports.experimental_createActionHook = experimental_createActionHook;
46
+ exports.experimental_createActionHook = createActionHook.experimental_createActionHook;
47
+ exports.experimental_serverActionLink = createActionHook.experimental_serverActionLink;
146
48
  exports.experimental_createTRPCNextAppDirClient = experimental_createTRPCNextAppDirClient;
147
- exports.experimental_serverActionLink = experimental_serverActionLink;
@@ -1,103 +1,6 @@
1
- import { TRPCClientError, createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
2
- import { transformResult, createRecursiveProxy } from '@trpc/core';
3
- import { observable } from '@trpc/core/observable';
4
- import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
5
- import { i as isFormData } from '../shared-2f1ecbeb.mjs';
6
-
7
- // ts-prune-ignore-next
8
- function experimental_serverActionLink() {
9
- return (runtime)=>({ op })=>observable((observer)=>{
10
- const context = op.context;
11
- context._action(isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
12
- const transformed = transformResult(data, runtime.transformer);
13
- if (!transformed.ok) {
14
- observer.error(TRPCClientError.from(transformed.error, {}));
15
- return;
16
- }
17
- observer.next({
18
- context: op.context,
19
- result: transformed.result
20
- });
21
- observer.complete();
22
- }).catch((cause)=>{
23
- observer.error(TRPCClientError.from(cause));
24
- });
25
- });
26
- }
27
- // ts-prune-ignore-next
28
- function experimental_createActionHook(opts) {
29
- const client = createTRPCUntypedClient(opts);
30
- return function useAction(handler, useActionOpts) {
31
- const count = useRef(0);
32
- const [state, setState] = useState({
33
- status: 'idle'
34
- });
35
- const actionOptsRef = useRef(useActionOpts);
36
- actionOptsRef.current = useActionOpts;
37
- useEffect(()=>{
38
- return ()=>{
39
- // cleanup after unmount to prevent calling hook opts after unmount
40
- count.current = -1;
41
- actionOptsRef.current = undefined;
42
- };
43
- }, []);
44
- const mutateAsync = useCallback((input, requestOptions)=>{
45
- const idx = ++count.current;
46
- const context = {
47
- ...requestOptions?.context,
48
- _action (innerInput) {
49
- return handler(innerInput);
50
- }
51
- };
52
- setState({
53
- status: 'loading'
54
- });
55
- return client.mutation('serverAction', input, {
56
- ...requestOptions,
57
- context
58
- }).then(async (data)=>{
59
- await actionOptsRef.current?.onSuccess?.(data);
60
- if (idx !== count.current) {
61
- return;
62
- }
63
- setState({
64
- status: 'success',
65
- data: data
66
- });
67
- }).catch(async (error)=>{
68
- await actionOptsRef.current?.onError?.(error);
69
- throw error;
70
- }).catch((error)=>{
71
- if (idx !== count.current) {
72
- return;
73
- }
74
- setState({
75
- status: 'error',
76
- error: TRPCClientError.from(error, {})
77
- });
78
- throw error;
79
- });
80
- }, [
81
- handler
82
- ]);
83
- const mutate = useCallback((...args)=>{
84
- void mutateAsync(...args).catch(()=>{
85
- // ignored
86
- });
87
- }, [
88
- mutateAsync
89
- ]);
90
- return useMemo(()=>({
91
- ...state,
92
- mutate,
93
- mutateAsync
94
- }), [
95
- mutate,
96
- mutateAsync,
97
- state
98
- ]);
99
- };
100
- }
1
+ import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
2
+ import { createRecursiveProxy } from '@trpc/core';
3
+ export { experimental_createActionHook, experimental_serverActionLink } from './create-action-hook.mjs';
101
4
 
102
5
  // ts-prune-ignore-next
103
6
  function experimental_createTRPCNextAppDirClient(opts) {
@@ -138,4 +41,4 @@ function experimental_createTRPCNextAppDirClient(opts) {
138
41
  // });
139
42
  }
140
43
 
141
- export { experimental_createActionHook, experimental_createTRPCNextAppDirClient, experimental_serverActionLink };
44
+ export { experimental_createTRPCNextAppDirClient };
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ var client = require('@trpc/client');
4
+ var core = require('@trpc/core');
5
+ var observable = require('@trpc/core/observable');
6
+ var React = require('react');
7
+ var shared = require('./shared.js');
8
+
9
+ // ts-prune-ignore-next
10
+ function experimental_serverActionLink() {
11
+ return (runtime)=>({ op })=>observable.observable((observer)=>{
12
+ const context = op.context;
13
+ context._action(shared.isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
14
+ const transformed = core.transformResult(data, runtime.transformer);
15
+ if (!transformed.ok) {
16
+ observer.error(client.TRPCClientError.from(transformed.error, {}));
17
+ return;
18
+ }
19
+ observer.next({
20
+ context: op.context,
21
+ result: transformed.result
22
+ });
23
+ observer.complete();
24
+ }).catch((cause)=>{
25
+ observer.error(client.TRPCClientError.from(cause));
26
+ });
27
+ });
28
+ }
29
+ // ts-prune-ignore-next
30
+ function experimental_createActionHook(opts) {
31
+ const client$1 = client.createTRPCUntypedClient(opts);
32
+ return function useAction(handler, useActionOpts) {
33
+ const count = React.useRef(0);
34
+ const [state, setState] = React.useState({
35
+ status: 'idle'
36
+ });
37
+ const actionOptsRef = React.useRef(useActionOpts);
38
+ actionOptsRef.current = useActionOpts;
39
+ React.useEffect(()=>{
40
+ return ()=>{
41
+ // cleanup after unmount to prevent calling hook opts after unmount
42
+ count.current = -1;
43
+ actionOptsRef.current = undefined;
44
+ };
45
+ }, []);
46
+ const mutateAsync = React.useCallback((input, requestOptions)=>{
47
+ const idx = ++count.current;
48
+ const context = {
49
+ ...requestOptions?.context,
50
+ _action (innerInput) {
51
+ return handler(innerInput);
52
+ }
53
+ };
54
+ setState({
55
+ status: 'loading'
56
+ });
57
+ return client$1.mutation('serverAction', input, {
58
+ ...requestOptions,
59
+ context
60
+ }).then(async (data)=>{
61
+ await actionOptsRef.current?.onSuccess?.(data);
62
+ if (idx !== count.current) {
63
+ return;
64
+ }
65
+ setState({
66
+ status: 'success',
67
+ data: data
68
+ });
69
+ }).catch(async (error)=>{
70
+ await actionOptsRef.current?.onError?.(error);
71
+ throw error;
72
+ }).catch((error)=>{
73
+ if (idx !== count.current) {
74
+ return;
75
+ }
76
+ setState({
77
+ status: 'error',
78
+ error: client.TRPCClientError.from(error, {})
79
+ });
80
+ throw error;
81
+ });
82
+ }, [
83
+ handler
84
+ ]);
85
+ const mutate = React.useCallback((...args)=>{
86
+ void mutateAsync(...args).catch(()=>{
87
+ // ignored
88
+ });
89
+ }, [
90
+ mutateAsync
91
+ ]);
92
+ return React.useMemo(()=>({
93
+ ...state,
94
+ mutate,
95
+ mutateAsync
96
+ }), [
97
+ mutate,
98
+ mutateAsync,
99
+ state
100
+ ]);
101
+ };
102
+ }
103
+
104
+ exports.experimental_createActionHook = experimental_createActionHook;
105
+ exports.experimental_serverActionLink = experimental_serverActionLink;
@@ -0,0 +1,102 @@
1
+ import { TRPCClientError, createTRPCUntypedClient } from '@trpc/client';
2
+ import { transformResult } from '@trpc/core';
3
+ import { observable } from '@trpc/core/observable';
4
+ import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
5
+ import { isFormData } from './shared.mjs';
6
+
7
+ // ts-prune-ignore-next
8
+ function experimental_serverActionLink() {
9
+ return (runtime)=>({ op })=>observable((observer)=>{
10
+ const context = op.context;
11
+ context._action(isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
12
+ const transformed = transformResult(data, runtime.transformer);
13
+ if (!transformed.ok) {
14
+ observer.error(TRPCClientError.from(transformed.error, {}));
15
+ return;
16
+ }
17
+ observer.next({
18
+ context: op.context,
19
+ result: transformed.result
20
+ });
21
+ observer.complete();
22
+ }).catch((cause)=>{
23
+ observer.error(TRPCClientError.from(cause));
24
+ });
25
+ });
26
+ }
27
+ // ts-prune-ignore-next
28
+ function experimental_createActionHook(opts) {
29
+ const client = createTRPCUntypedClient(opts);
30
+ return function useAction(handler, useActionOpts) {
31
+ const count = useRef(0);
32
+ const [state, setState] = useState({
33
+ status: 'idle'
34
+ });
35
+ const actionOptsRef = useRef(useActionOpts);
36
+ actionOptsRef.current = useActionOpts;
37
+ useEffect(()=>{
38
+ return ()=>{
39
+ // cleanup after unmount to prevent calling hook opts after unmount
40
+ count.current = -1;
41
+ actionOptsRef.current = undefined;
42
+ };
43
+ }, []);
44
+ const mutateAsync = useCallback((input, requestOptions)=>{
45
+ const idx = ++count.current;
46
+ const context = {
47
+ ...requestOptions?.context,
48
+ _action (innerInput) {
49
+ return handler(innerInput);
50
+ }
51
+ };
52
+ setState({
53
+ status: 'loading'
54
+ });
55
+ return client.mutation('serverAction', input, {
56
+ ...requestOptions,
57
+ context
58
+ }).then(async (data)=>{
59
+ await actionOptsRef.current?.onSuccess?.(data);
60
+ if (idx !== count.current) {
61
+ return;
62
+ }
63
+ setState({
64
+ status: 'success',
65
+ data: data
66
+ });
67
+ }).catch(async (error)=>{
68
+ await actionOptsRef.current?.onError?.(error);
69
+ throw error;
70
+ }).catch((error)=>{
71
+ if (idx !== count.current) {
72
+ return;
73
+ }
74
+ setState({
75
+ status: 'error',
76
+ error: TRPCClientError.from(error, {})
77
+ });
78
+ throw error;
79
+ });
80
+ }, [
81
+ handler
82
+ ]);
83
+ const mutate = useCallback((...args)=>{
84
+ void mutateAsync(...args).catch(()=>{
85
+ // ignored
86
+ });
87
+ }, [
88
+ mutateAsync
89
+ ]);
90
+ return useMemo(()=>({
91
+ ...state,
92
+ mutate,
93
+ mutateAsync
94
+ }), [
95
+ mutate,
96
+ mutateAsync,
97
+ state
98
+ ]);
99
+ };
100
+ }
101
+
102
+ export { experimental_createActionHook, experimental_serverActionLink };
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
4
+ if (typeof path === 'string') {
5
+ path = path.split(/[\.\[\]]/).filter(Boolean);
6
+ }
7
+ if (path.length > 1) {
8
+ const p = path.shift();
9
+ const isArrayIndex = /^\d+$/.test(path[0]);
10
+ obj[p] = obj[p] || (isArrayIndex ? [] : {});
11
+ set(obj[p], path, value);
12
+ return;
13
+ }
14
+ const p1 = path[0];
15
+ if (obj[p1] === undefined) {
16
+ obj[p1] = value;
17
+ } else if (Array.isArray(obj[p1])) {
18
+ obj[p1].push(value);
19
+ } else {
20
+ obj[p1] = [
21
+ obj[p1],
22
+ value
23
+ ];
24
+ }
25
+ }
26
+ function formDataToObject(formData) {
27
+ const obj = {};
28
+ for (const [key, value] of formData.entries()){
29
+ set(obj, key, value);
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ exports.formDataToObject = formDataToObject;
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
2
+ if (typeof path === 'string') {
3
+ path = path.split(/[\.\[\]]/).filter(Boolean);
4
+ }
5
+ if (path.length > 1) {
6
+ const p = path.shift();
7
+ const isArrayIndex = /^\d+$/.test(path[0]);
8
+ obj[p] = obj[p] || (isArrayIndex ? [] : {});
9
+ set(obj[p], path, value);
10
+ return;
11
+ }
12
+ const p1 = path[0];
13
+ if (obj[p1] === undefined) {
14
+ obj[p1] = value;
15
+ } else if (Array.isArray(obj[p1])) {
16
+ obj[p1].push(value);
17
+ } else {
18
+ obj[p1] = [
19
+ obj[p1],
20
+ value
21
+ ];
22
+ }
23
+ }
24
+ function formDataToObject(formData) {
25
+ const obj = {};
26
+ for (const [key, value] of formData.entries()){
27
+ set(obj, key, value);
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ export { formDataToObject };
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var client = require('@trpc/client');
6
4
  var core = require('@trpc/core');
7
5
  var observable = require('@trpc/core/observable');
8
6
  var cache = require('next/cache');
9
- var shared = require('../../shared-a452b80f.js');
7
+ var shared = require('../shared.js');
10
8
 
11
9
  // import "server-only";
12
10
  // ts-prune-ignore-next
@@ -2,7 +2,7 @@ import { TRPCClientError } from '@trpc/client';
2
2
  import { callProcedure } from '@trpc/core';
3
3
  import { observable } from '@trpc/core/observable';
4
4
  import { unstable_cache } from 'next/cache';
5
- import { g as generateCacheTag } from '../../shared-2f1ecbeb.mjs';
5
+ import { generateCacheTag } from '../shared.mjs';
6
6
 
7
7
  // import "server-only";
8
8
  // ts-prune-ignore-next
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var client = require('@trpc/client');
6
- var shared = require('../../shared-a452b80f.js');
7
- require('@trpc/core');
4
+ var shared = require('../shared.js');
8
5
 
9
6
  // ts-prune-ignore-next
10
7
  function experimental_nextHttpLink(opts) {
@@ -1,6 +1,5 @@
1
1
  import { httpBatchLink, httpLink } from '@trpc/client';
2
- import { g as generateCacheTag } from '../../shared-2f1ecbeb.mjs';
3
- import '@trpc/core';
2
+ import { generateCacheTag } from '../shared.mjs';
4
3
 
5
4
  // ts-prune-ignore-next
6
5
  function experimental_nextHttpLink(opts) {
@@ -1,43 +1,11 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var client = require('@trpc/client');
6
4
  var core = require('@trpc/core');
7
5
  var cache = require('next/cache');
8
6
  var React = require('react');
9
- var shared = require('../shared-a452b80f.js');
10
-
11
- /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
12
- if (typeof path === 'string') {
13
- path = path.split(/[\.\[\]]/).filter(Boolean);
14
- }
15
- if (path.length > 1) {
16
- const p = path.shift();
17
- const isArrayIndex = /^\d+$/.test(path[0]);
18
- obj[p] = obj[p] || (isArrayIndex ? [] : {});
19
- set(obj[p], path, value);
20
- return;
21
- }
22
- const p1 = path[0];
23
- if (obj[p1] === undefined) {
24
- obj[p1] = value;
25
- } else if (Array.isArray(obj[p1])) {
26
- obj[p1].push(value);
27
- } else {
28
- obj[p1] = [
29
- obj[p1],
30
- value
31
- ];
32
- }
33
- }
34
- function formDataToObject(formData) {
35
- const obj = {};
36
- for (const [key, value] of formData.entries()){
37
- set(obj, key, value);
38
- }
39
- return obj;
40
- }
7
+ var formDataToObject = require('./formDataToObject.js');
8
+ var shared = require('./shared.js');
41
9
 
42
10
  /// <reference types="next" />
43
11
  // ts-prune-ignore-next
@@ -77,7 +45,7 @@ function experimental_createServerActionHandler(t, opts) {
77
45
  if (normalizeFormData && shared.isFormData(rawInput)) {
78
46
  // Normalizes formdata so we can use `z.object({})` etc on the server
79
47
  try {
80
- rawInput = formDataToObject(rawInput);
48
+ rawInput = formDataToObject.formDataToObject(rawInput);
81
49
  } catch {
82
50
  throw new core.TRPCError({
83
51
  code: 'INTERNAL_SERVER_ERROR',
@@ -2,38 +2,8 @@ import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/cl
2
2
  import { createRecursiveProxy, TRPCError, transformTRPCResponse, getTRPCErrorFromUnknown, getErrorShape } from '@trpc/core';
3
3
  import { revalidateTag } from 'next/cache';
4
4
  import { cache } from 'react';
5
- import { g as generateCacheTag, i as isFormData } from '../shared-2f1ecbeb.mjs';
6
-
7
- /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
8
- if (typeof path === 'string') {
9
- path = path.split(/[\.\[\]]/).filter(Boolean);
10
- }
11
- if (path.length > 1) {
12
- const p = path.shift();
13
- const isArrayIndex = /^\d+$/.test(path[0]);
14
- obj[p] = obj[p] || (isArrayIndex ? [] : {});
15
- set(obj[p], path, value);
16
- return;
17
- }
18
- const p1 = path[0];
19
- if (obj[p1] === undefined) {
20
- obj[p1] = value;
21
- } else if (Array.isArray(obj[p1])) {
22
- obj[p1].push(value);
23
- } else {
24
- obj[p1] = [
25
- obj[p1],
26
- value
27
- ];
28
- }
29
- }
30
- function formDataToObject(formData) {
31
- const obj = {};
32
- for (const [key, value] of formData.entries()){
33
- set(obj, key, value);
34
- }
35
- return obj;
36
- }
5
+ import { formDataToObject } from './formDataToObject.mjs';
6
+ import { generateCacheTag, isFormData } from './shared.mjs';
37
7
 
38
8
  /// <reference types="next" />
39
9
  // ts-prune-ignore-next
@@ -13,4 +13,4 @@ function isFormData(value) {
13
13
  return value instanceof FormData;
14
14
  }
15
15
 
16
- export { generateCacheTag as g, isFormData as i };
16
+ export { generateCacheTag, isFormData };