@tinvar/react 0.0.0-stage → 0.4.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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +168 -4
  3. package/src/action-server.js +41 -0
  4. package/src/action.d.ts +68 -0
  5. package/src/action.js +167 -0
  6. package/src/bootstrap.js +153 -0
  7. package/src/channel.d.ts +46 -0
  8. package/src/channel.js +132 -0
  9. package/src/client-modules.d.ts +8 -0
  10. package/src/client-modules.js +88 -0
  11. package/src/client.d.ts +36 -0
  12. package/src/client.js +42 -0
  13. package/src/compose-route.d.ts +33 -0
  14. package/src/compose-route.js +107 -0
  15. package/src/csrf.d.ts +11 -0
  16. package/src/csrf.js +49 -0
  17. package/src/deferred-boundary.d.ts +61 -0
  18. package/src/deferred-boundary.js +646 -0
  19. package/src/deferred-groups.d.ts +24 -0
  20. package/src/deferred-groups.js +198 -0
  21. package/src/deferred-revalidation.d.ts +37 -0
  22. package/src/deferred-revalidation.js +108 -0
  23. package/src/deferred-triggers.d.ts +26 -0
  24. package/src/deferred-triggers.js +172 -0
  25. package/src/deferred.d.ts +24 -0
  26. package/src/deferred.jsx +100 -0
  27. package/src/document-load.js +95 -0
  28. package/src/endpoint.d.ts +87 -0
  29. package/src/endpoint.js +304 -0
  30. package/src/form-data.js +219 -0
  31. package/src/form.d.ts +177 -0
  32. package/src/form.js +615 -0
  33. package/src/forms.d.ts +4 -0
  34. package/src/forms.js +10 -0
  35. package/src/fragment-client.d.ts +70 -0
  36. package/src/fragment-client.js +510 -0
  37. package/src/head.d.ts +85 -0
  38. package/src/head.js +360 -0
  39. package/src/inbox-view.d.ts +17 -0
  40. package/src/inbox-view.js +105 -0
  41. package/src/inbox.d.ts +108 -0
  42. package/src/inbox.js +293 -0
  43. package/src/index.combined.d.ts +31 -0
  44. package/src/index.d.ts +5 -0
  45. package/src/index.js +29 -0
  46. package/src/index.server.d.ts +4 -0
  47. package/src/index.server.js +8 -0
  48. package/src/infinite-scroll.d.ts +108 -0
  49. package/src/infinite-scroll.js +715 -0
  50. package/src/layout-props.d.ts +30 -0
  51. package/src/layout-props.js +143 -0
  52. package/src/link-click.d.ts +3 -0
  53. package/src/link-click.js +68 -0
  54. package/src/link.d.ts +63 -0
  55. package/src/link.js +274 -0
  56. package/src/live.d.ts +65 -0
  57. package/src/live.js +977 -0
  58. package/src/merge-slot.d.ts +41 -0
  59. package/src/merge-slot.js +253 -0
  60. package/src/merge.d.ts +111 -0
  61. package/src/merge.js +149 -0
  62. package/src/once-slot.d.ts +14 -0
  63. package/src/once-slot.js +75 -0
  64. package/src/once-store.d.ts +26 -0
  65. package/src/once-store.js +211 -0
  66. package/src/once.d.ts +44 -0
  67. package/src/once.js +65 -0
  68. package/src/optimistic.d.ts +14 -0
  69. package/src/optimistic.js +159 -0
  70. package/src/optional.d.ts +10 -0
  71. package/src/optional.js +31 -0
  72. package/src/page-root.d.ts +56 -0
  73. package/src/page-root.js +455 -0
  74. package/src/payload.d.ts +15 -0
  75. package/src/payload.js +101 -0
  76. package/src/poll.d.ts +55 -0
  77. package/src/poll.js +224 -0
  78. package/src/precognition.js +190 -0
  79. package/src/prefetch-cache.d.ts +46 -0
  80. package/src/prefetch-cache.js +256 -0
  81. package/src/progress.d.ts +38 -0
  82. package/src/progress.js +243 -0
  83. package/src/remember-store.d.ts +50 -0
  84. package/src/remember-store.js +486 -0
  85. package/src/rescue.d.ts +10 -0
  86. package/src/rescue.js +30 -0
  87. package/src/resumable.js +822 -0
  88. package/src/resume-store.js +364 -0
  89. package/src/route.d.ts +50 -0
  90. package/src/route.js +227 -0
  91. package/src/router-hooks.js +234 -0
  92. package/src/router.d.ts +586 -0
  93. package/src/router.js +3555 -0
  94. package/src/segment.d.ts +36 -0
  95. package/src/segment.js +116 -0
  96. package/src/server.d.ts +71 -0
  97. package/src/server.js +242 -0
  98. package/src/submit.js +333 -0
  99. package/src/telemetry.d.ts +71 -0
  100. package/src/telemetry.js +851 -0
  101. package/src/testing.d.ts +89 -0
  102. package/src/testing.js +634 -0
  103. package/src/transfer.d.ts +48 -0
  104. package/src/transfer.js +135 -0
  105. package/src/transport.js +390 -0
  106. package/src/upload.d.ts +342 -0
  107. package/src/upload.js +1240 -0
  108. package/src/use-channel.d.ts +21 -0
  109. package/src/use-channel.js +51 -0
  110. package/src/use-form.d.ts +86 -0
  111. package/src/use-form.js +432 -0
  112. package/src/use-http.d.ts +56 -0
  113. package/src/use-http.js +248 -0
  114. package/src/use-inbox.d.ts +41 -0
  115. package/src/use-inbox.js +201 -0
  116. package/src/use-remember.d.ts +10 -0
  117. package/src/use-remember.js +132 -0
  118. package/src/when-mounted.d.ts +15 -0
  119. package/src/when-mounted.js +27 -0
  120. package/README.md +0 -3
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The JavaScript half of the testing layer: what codegen's mocks of
3
+ * `@queries/*` and `@actions/*` are built on, and the harness server
4
+ * components render in. Loads only in a Vitest worker; see ADR 0061.
5
+ */
6
+
7
+ import type { ReactNode } from 'react';
8
+ import type { ActionReference, ActionResponse } from './action';
9
+ import type { SharedDataMap } from './server';
10
+
11
+ /** The marker a Vite build refuses any module of. */
12
+ export declare const TESTING_RUNTIME: 'tinvar:testing-runtime';
13
+
14
+ /** Throws unless the environment given is a Vitest worker's, and not production. */
15
+ export declare function refuseOutsideTests(env: Record<string, string | undefined> | undefined): void;
16
+
17
+ /** A stand-in for one `@queries/*` function. */
18
+ export interface MockedQuery<Args extends object, Result> {
19
+ (args: Args): Promise<Result>;
20
+ /** The query's wire name. */
21
+ readonly query: string;
22
+ }
23
+
24
+ /** A stand-in for one `@actions/*` reference: a reference, recording its calls. */
25
+ export type MockedAction<Args extends object, Result> = ActionReference<Args, Result>;
26
+
27
+ export declare function mockQuery<Args extends object, Result>(
28
+ name: string,
29
+ fallback: () => Result,
30
+ ): MockedQuery<Args, Result>;
31
+
32
+ export declare function mockAction<Args extends object, Result = ActionResponse>(
33
+ name: string,
34
+ fallback: () => Result,
35
+ ): MockedAction<Args, Result>;
36
+
37
+ type ArgsOf<M> = M extends (args: infer A, ...rest: never[]) => unknown ? A : never;
38
+ type ResultOf<M> = M extends (...args: never[]) => Promise<infer R> ? R : never;
39
+
40
+ /** The arguments each call to a mock was made with, oldest first. */
41
+ export declare function calls<M extends (...args: never[]) => Promise<unknown>>(mock: M): ArgsOf<M>[];
42
+
43
+ /** What a mock answers from now on: a value, or a function of the call's arguments. */
44
+ export declare function answer<M extends (...args: never[]) => Promise<unknown>>(
45
+ mock: M,
46
+ value: ResultOf<M> | Promise<ResultOf<M>> | ((args: ArgsOf<M>) => ResultOf<M> | Promise<ResultOf<M>>),
47
+ ): void;
48
+
49
+ /** Has a mock refuse from now on: an action with an ActionError (422 with field errors by default). */
50
+ export declare function refuse(
51
+ mock: (...args: never[]) => Promise<unknown>,
52
+ refusal?: { status?: number; errors?: Record<string, string[]> },
53
+ ): void;
54
+
55
+ /**
56
+ * What a fake takes: any field, at any depth. A plain object is laid over
57
+ * the field's defaults; a list, null or anything else replaces it.
58
+ */
59
+ export type Overrides<T> = T extends readonly unknown[]
60
+ ? T
61
+ : T extends (...args: never[]) => unknown
62
+ ? T
63
+ : T extends object
64
+ ? { [K in keyof T]?: Overrides<T[K]> }
65
+ : T;
66
+
67
+ /** A fake's defaults under a test's overrides, at any depth; what codegen's fakes return. */
68
+ export declare function withOverrides<T>(base: T, overrides: Overrides<T>): T;
69
+
70
+ /** Forgets every call and answer. */
71
+ export declare function resetMocks(): void;
72
+
73
+ /** A fetch that answers posts to `/_action/{name}` and `/_query/{name}` from the mocks, and nothing else. */
74
+ export declare function actionFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
75
+
76
+ /** Marks a 'use client' module's exports; `tinvarTesting()` adds the call. */
77
+ export declare function markClient(...exports: unknown[]): void;
78
+
79
+ export declare function isClientComponent(type: unknown): boolean;
80
+
81
+ /**
82
+ * Renders a tree's server components against the mocks, and hands back what
83
+ * is left -- host elements and client components -- for React Testing
84
+ * Library's render().
85
+ */
86
+ export declare function renderServer(
87
+ node: ReactNode,
88
+ options?: { shared?: { [K in keyof SharedDataMap]?: SharedDataMap[K] } },
89
+ ): Promise<ReactNode>;