@ontahi/runtime-nextjs 0.1.0-alpha.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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +11 -0
- package/dist/actions/builder.d.ts +83 -0
- package/dist/actions/builder.d.ts.map +1 -0
- package/dist/actions/builder.js +126 -0
- package/dist/actions/builder.js.map +1 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +2 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/server.d.ts +3 -0
- package/dist/actions/server.d.ts.map +1 -0
- package/dist/actions/server.js +3 -0
- package/dist/actions/server.js.map +1 -0
- package/dist/actions/transport.d.ts +50 -0
- package/dist/actions/transport.d.ts.map +1 -0
- package/dist/actions/transport.js +43 -0
- package/dist/actions/transport.js.map +1 -0
- package/dist/operation-invocation/index.d.ts +2 -0
- package/dist/operation-invocation/index.d.ts.map +1 -0
- package/dist/operation-invocation/index.js +2 -0
- package/dist/operation-invocation/index.js.map +1 -0
- package/dist/operation-invocation/route.d.ts +7 -0
- package/dist/operation-invocation/route.d.ts.map +1 -0
- package/dist/operation-invocation/route.js +17 -0
- package/dist/operation-invocation/route.js.map +1 -0
- package/package.json +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @ontahi/runtime-nextjs
|
|
2
|
+
|
|
3
|
+
Next.js runtime adapters for Ontahi applications.
|
|
4
|
+
|
|
5
|
+
This package depends on `@ontahi/core` and owns the Next.js / `next-safe-action` transport layer. It currently contains:
|
|
6
|
+
|
|
7
|
+
1. `@ontahi/runtime-nextjs/actions`: compatibility re-exports for generic action runtime metadata and result helpers from `@ontahi/core/runtime/actions`.
|
|
8
|
+
2. `@ontahi/runtime-nextjs/actions/server`: server-only `next-safe-action` transport and feature action factory helpers.
|
|
9
|
+
3. `@ontahi/runtime-nextjs/operation-invocation`: an App Router `Request`/`Response` adapter for the transport-neutral operation invocation protocol from `@ontahi/core`.
|
|
10
|
+
|
|
11
|
+
New generic consumers should import action metadata and result helpers from `@ontahi/core/runtime/actions`. React hooks and operation bridge adapters live in `@ontahi/react/actions` so this package can stay focused on Next.js runtime concerns.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { createFeatureAllQueryTarget, type ActionInvalidationTarget, type ActionQueryKey, type ActionQuerySpec } from '@ontahi/core/runtime/actions';
|
|
3
|
+
import { type EffectSuccessPayload, type LayerConcern, type OperationFailure, type OperationInput, type OperationRequirement, type OperationRuntimeError } from '@ontahi/core/runtime/server';
|
|
4
|
+
import type { Effect } from 'effect';
|
|
5
|
+
import type { InputSchemaFactoryFn, MaybeBrandThrows, SafeActionClient, SafeActionFn, ServerCodeFn } from 'next-safe-action';
|
|
6
|
+
type InferClientMetadata<TClient> = TClient extends SafeActionClient<any, any, any, infer Metadata, any, any, any, any, any, any, any, any> ? Metadata : never;
|
|
7
|
+
type InferClientCtx<TClient> = TClient extends SafeActionClient<any, any, any, any, any, infer Ctx, any, any, any, any, any, any> ? Ctx : object;
|
|
8
|
+
type InferClientInputSchema<TClient> = TClient extends SafeActionClient<any, any, any, any, any, any, any, infer InputSchema, any, any, any, any> ? InputSchema : undefined;
|
|
9
|
+
type InferClientBindArgsSchemas<TClient> = TClient extends SafeActionClient<any, any, any, any, any, any, any, any, any, infer BindArgsSchemas, any, any> ? BindArgsSchemas : readonly [];
|
|
10
|
+
type InferStandardSchemaOutput<Schema> = Schema extends {
|
|
11
|
+
readonly '~standard': {
|
|
12
|
+
readonly types?: {
|
|
13
|
+
readonly output: infer Output;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
} ? Output : undefined;
|
|
17
|
+
type InferClientParsedInput<TClient> = InferStandardSchemaOutput<InferClientInputSchema<TClient>>;
|
|
18
|
+
type ActionFnForClient<TClient, Data> = TClient extends SafeActionClient<infer ServerError, any, any, any, any, any, any, infer InputSchema, any, infer BindArgsSchemas, infer ShapedErrors, infer ThrowsValidationErrors> ? MaybeBrandThrows<SafeActionFn<ServerError, InputSchema, BindArgsSchemas, ShapedErrors, Data>, ThrowsValidationErrors> : never;
|
|
19
|
+
type ActionArgsForClient<TClient> = Parameters<ServerCodeFn<InferClientMetadata<TClient>, InferClientCtx<TClient>, InferClientInputSchema<TClient>, InferClientBindArgsSchemas<TClient>, unknown>>[0];
|
|
20
|
+
type ActionInputFnForClient<TClient, Data> = (parsedInput: InferClientParsedInput<TClient>) => Data | Promise<Data>;
|
|
21
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
22
|
+
type ActionOperationOptions<TClient, Data> = {
|
|
23
|
+
mapInput?: (parsedInput: InferClientParsedInput<TClient>, actionArgs: ActionArgsForClient<TClient>) => unknown;
|
|
24
|
+
onSuccess?: (args: {
|
|
25
|
+
parsedInput: InferClientParsedInput<TClient>;
|
|
26
|
+
input: unknown;
|
|
27
|
+
result: Awaited<Data>;
|
|
28
|
+
actionArgs: ActionArgsForClient<TClient>;
|
|
29
|
+
}) => MaybePromise<unknown>;
|
|
30
|
+
};
|
|
31
|
+
type DomainOperationForClient<TClient, Data> = {
|
|
32
|
+
operation: ActionInputFnForClient<TClient, Data>;
|
|
33
|
+
};
|
|
34
|
+
type CanonicalDomainOperationForClient<TClient> = {
|
|
35
|
+
name: string;
|
|
36
|
+
layer: string;
|
|
37
|
+
run: (input: InferClientParsedInput<TClient>) => Effect.Effect<Record<string, unknown> | void | EffectSuccessPayload<Record<string, unknown> | void>, OperationFailure | OperationRuntimeError>;
|
|
38
|
+
defectLogMessage?: string;
|
|
39
|
+
defectPublicMessage?: string;
|
|
40
|
+
extra?: (input: InferClientParsedInput<TClient>) => Record<string, unknown>;
|
|
41
|
+
telemetrySpanName?: string;
|
|
42
|
+
requires?: ReadonlyArray<OperationRequirement<InferClientParsedInput<TClient> & OperationInput>>;
|
|
43
|
+
concerns?: ReadonlyArray<LayerConcern<InferClientParsedInput<TClient>, unknown>>;
|
|
44
|
+
contracts?: unknown;
|
|
45
|
+
};
|
|
46
|
+
type AnyDomainOperationForClient<TClient, Data> = DomainOperationForClient<TClient, Data> | CanonicalDomainOperationForClient<TClient>;
|
|
47
|
+
type InvalidationResolver<TInput, TData> = (args: {
|
|
48
|
+
input: TInput;
|
|
49
|
+
data: TData;
|
|
50
|
+
}) => ActionInvalidationTarget[];
|
|
51
|
+
type AnySafeActionClient = SafeActionClient<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
52
|
+
type ResolvedInputSchema<Schema> = Schema extends InputSchemaFactoryFn<any, infer NextSchema> ? NextSchema : Schema;
|
|
53
|
+
type NextClientForSchema<Client extends AnySafeActionClient, Schema extends Parameters<Client['inputSchema']>[0]> = Client extends SafeActionClient<infer ServerError, infer ErrorsFormat, infer MetadataSchema, infer Metadata, infer HasMetadata, infer Ctx, infer InputSchemaFn, infer CurrentInputSchema, infer OutputSchema, infer BindArgsSchemas, any, infer ThrowsValidationErrors> ? SafeActionClient<ServerError, ErrorsFormat, MetadataSchema, Metadata, HasMetadata, Ctx, InputSchemaFn, ResolvedInputSchema<Schema>, OutputSchema, BindArgsSchemas, any, ThrowsValidationErrors> : AnySafeActionClient;
|
|
54
|
+
type MetadataClient<Client extends AnySafeActionClient> = ReturnType<Client['metadata']>;
|
|
55
|
+
type ActionBuilder<Client extends AnySafeActionClient> = {
|
|
56
|
+
input: <Schema extends Parameters<Client['inputSchema']>[0]>(schema: Schema) => ActionBuilder<NextClientForSchema<Client, Schema>>;
|
|
57
|
+
inputType: <Schema extends Parameters<Client['inputSchema']>[0]>(schema: Schema) => ActionBuilder<NextClientForSchema<Client, Schema>>;
|
|
58
|
+
key: {
|
|
59
|
+
(querySpec: ActionQuerySpec<InferClientParsedInput<Client>>): ActionBuilder<Client>;
|
|
60
|
+
(getQueryKey: (input: InferClientParsedInput<Client>) => ActionQueryKey): ActionBuilder<Client>;
|
|
61
|
+
};
|
|
62
|
+
affects: (targets: ActionInvalidationTarget[] | InvalidationResolver<InferClientParsedInput<Client>, unknown>) => ActionBuilder<Client>;
|
|
63
|
+
run: <Data>(serverCodeFn: ServerCodeFn<InferClientMetadata<Client>, InferClientCtx<Client>, InferClientInputSchema<Client>, InferClientBindArgsSchemas<Client>, Data>) => ActionFnForClient<Client, Data>;
|
|
64
|
+
runEffect: <Data>(effectFn: (parsedInput: InferClientParsedInput<Client>) => Effect.Effect<Data | EffectSuccessPayload<Data>, unknown>, options?: {
|
|
65
|
+
scope?: string;
|
|
66
|
+
telemetrySpanName?: string;
|
|
67
|
+
input?: (parsedInput: InferClientParsedInput<Client>, actionArgs: ActionArgsForClient<Client>) => Record<string, unknown> | undefined;
|
|
68
|
+
extra?: (parsedInput: InferClientParsedInput<Client>, actionArgs: ActionArgsForClient<Client>) => Record<string, unknown> | undefined;
|
|
69
|
+
}) => ActionFnForClient<Client, Data>;
|
|
70
|
+
runOperation: <Data>(operationFn: ActionInputFnForClient<Client, Data>, options?: ActionOperationOptions<Client, Data>) => ActionFnForClient<Client, Data>;
|
|
71
|
+
runDomainOperation: <Data>(operation: AnyDomainOperationForClient<Client, Data>, options?: ActionOperationOptions<Client, Data>) => ActionFnForClient<Client, Data>;
|
|
72
|
+
};
|
|
73
|
+
type FeatureActionsFactory = <PublicClient extends AnySafeActionClient, AuthClient extends AnySafeActionClient>(clients: {
|
|
74
|
+
actionClient: PublicClient;
|
|
75
|
+
authActionClient: AuthClient;
|
|
76
|
+
}) => (feature: string) => {
|
|
77
|
+
ALL: ReturnType<typeof createFeatureAllQueryTarget>;
|
|
78
|
+
auth: (actionName: string) => ActionBuilder<MetadataClient<AuthClient>>;
|
|
79
|
+
public: (actionName: string) => ActionBuilder<MetadataClient<PublicClient>>;
|
|
80
|
+
};
|
|
81
|
+
export declare const createFeatureActionsFactory: FeatureActionsFactory;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/actions/builder.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAEL,2BAA2B,EAG3B,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC3B,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACb,MAAM,kBAAkB,CAAC;AAO1B,KAAK,mBAAmB,CAAC,OAAO,IAC9B,OAAO,SAAS,gBAAgB,CAC9B,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,QAAQ,EACd,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACJ,GACG,QAAQ,GACR,KAAK,CAAC;AAEZ,KAAK,cAAc,CAAC,OAAO,IACzB,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,GAAG,EA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IAAI,CAAC,CAAC;IACrC,YAAY,EAAE,CAAC,IAAI,EACjB,WAAW,EAAE,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,EACjD,OAAO,CAAC,EAAE,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,KAC3C,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,kBAAkB,EAAE,CAAC,IAAI,EACvB,SAAS,EAAE,2BAA2B,CAAC,MAAM,EAAE,IAAI,CAAC,EACpD,OAAO,CAAC,EAAE,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,KAC3C,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACtC,CAAC;AAyMF,KAAK,qBAAqB,GAAG,CAC3B,YAAY,SAAS,mBAAmB,EACxC,UAAU,SAAS,mBAAmB,EACtC,OAAO,EAAE;IACT,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,UAAU,CAAC;CAC9B,KAAK,CAAC,OAAO,EAAE,MAAM,KAAK;IACzB,GAAG,EAAE,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC;IACpD,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,aAAa,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IACxE,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,aAAa,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;CAC7E,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,qBA8BtC,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { attachActionRuntime, createFeatureAllQueryTarget, getActionQueryKeyPrefixFromSpec, resolveInvalidationTarget, } from '@ontahi/core/runtime/actions';
|
|
3
|
+
import { layer, runServerEffect, } from '@ontahi/core/runtime/server';
|
|
4
|
+
import { isRecord } from '@ontahi/core/value/object';
|
|
5
|
+
import { withActionMetadata } from './transport.js';
|
|
6
|
+
const toScopeSegment = (value) => value.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
7
|
+
const createActionBuilder = (client, metadata, config) => {
|
|
8
|
+
const resolveKeyConfig = (specOrGetQueryKey) => {
|
|
9
|
+
if (typeof specOrGetQueryKey === 'function') {
|
|
10
|
+
const getQueryKey = specOrGetQueryKey;
|
|
11
|
+
return {
|
|
12
|
+
getQueryKey,
|
|
13
|
+
querySpec: undefined,
|
|
14
|
+
invalidationQueryKeyPrefix: undefined,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
getQueryKey: undefined,
|
|
19
|
+
querySpec: specOrGetQueryKey,
|
|
20
|
+
invalidationQueryKeyPrefix: getActionQueryKeyPrefixFromSpec(specOrGetQueryKey),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const input = (schema) => {
|
|
24
|
+
const nextClient = client.inputSchema(schema);
|
|
25
|
+
return createActionBuilder(nextClient, metadata, config);
|
|
26
|
+
};
|
|
27
|
+
const inputType = (schema) => {
|
|
28
|
+
const nextClient = client.inputSchema(schema);
|
|
29
|
+
return createActionBuilder(nextClient, metadata, config);
|
|
30
|
+
};
|
|
31
|
+
function key(specOrGetQueryKey) {
|
|
32
|
+
const nextKeyConfig = resolveKeyConfig(specOrGetQueryKey);
|
|
33
|
+
return createActionBuilder(client, metadata, {
|
|
34
|
+
...config,
|
|
35
|
+
...nextKeyConfig,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const affects = (targets) => createActionBuilder(client, metadata, {
|
|
39
|
+
...config,
|
|
40
|
+
getAffects: typeof targets === 'function'
|
|
41
|
+
? targets
|
|
42
|
+
: () => targets,
|
|
43
|
+
});
|
|
44
|
+
const run = (serverCodeFn) => attachActionRuntime(client.action(async (actionArgs) => serverCodeFn(actionArgs)), {
|
|
45
|
+
feature: metadata.feature,
|
|
46
|
+
actionName: metadata.actionName,
|
|
47
|
+
requiresAuth: metadata.requiresAuth ?? false,
|
|
48
|
+
queryKeyPrefix: [metadata.feature, metadata.actionName],
|
|
49
|
+
querySpec: config?.querySpec,
|
|
50
|
+
invalidationQueryKeyPrefix: config?.invalidationQueryKeyPrefix,
|
|
51
|
+
getQueryKey: config?.getQueryKey,
|
|
52
|
+
getAffectedQueryKeys: config?.getAffects
|
|
53
|
+
? args => config
|
|
54
|
+
.getAffects?.(args)
|
|
55
|
+
.flatMap(resolveInvalidationTarget) ?? []
|
|
56
|
+
: undefined,
|
|
57
|
+
});
|
|
58
|
+
const runEffect = (effectFn, options) => run(actionArgs => {
|
|
59
|
+
const typedArgs = actionArgs;
|
|
60
|
+
const parsedInput = typedArgs.parsedInput;
|
|
61
|
+
const input = options?.input?.(parsedInput, typedArgs) ??
|
|
62
|
+
(isRecord(parsedInput) ? parsedInput : undefined);
|
|
63
|
+
const extra = options?.extra?.(parsedInput, typedArgs);
|
|
64
|
+
return runServerEffect(effectFn(parsedInput), {
|
|
65
|
+
scope: options?.scope ??
|
|
66
|
+
`app.actions.${toScopeSegment(metadata.feature)}.${metadata.actionName}`,
|
|
67
|
+
telemetrySpanName: options?.telemetrySpanName,
|
|
68
|
+
input,
|
|
69
|
+
extra,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const runOperation = (operationFn, options) => run(async (actionArgs) => {
|
|
73
|
+
const typedArgs = actionArgs;
|
|
74
|
+
const parsedInput = typedArgs.parsedInput;
|
|
75
|
+
const input = (options?.mapInput?.(parsedInput, typedArgs) ??
|
|
76
|
+
parsedInput);
|
|
77
|
+
const result = await Promise.resolve(operationFn(input));
|
|
78
|
+
if (options?.onSuccess) {
|
|
79
|
+
await options.onSuccess({
|
|
80
|
+
parsedInput,
|
|
81
|
+
input,
|
|
82
|
+
result: result,
|
|
83
|
+
actionArgs: typedArgs,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
});
|
|
88
|
+
const runDomainOperation = (operation, options) => {
|
|
89
|
+
if ('operation' in operation) {
|
|
90
|
+
return runOperation(operation.operation, options);
|
|
91
|
+
}
|
|
92
|
+
const operationRunner = layer(operation.layer).operation(operation.name, operation.run, {
|
|
93
|
+
defectLogMessage: operation.defectLogMessage,
|
|
94
|
+
defectPublicMessage: operation.defectPublicMessage,
|
|
95
|
+
extra: operation.extra,
|
|
96
|
+
telemetrySpanName: operation.telemetrySpanName,
|
|
97
|
+
requires: operation.requires,
|
|
98
|
+
concerns: operation.concerns,
|
|
99
|
+
contracts: operation.contracts,
|
|
100
|
+
});
|
|
101
|
+
return runOperation(operationRunner, options);
|
|
102
|
+
};
|
|
103
|
+
return { input, inputType, key, affects, run, runEffect, runOperation, runDomainOperation };
|
|
104
|
+
};
|
|
105
|
+
export const createFeatureActionsFactory = ({ actionClient, authActionClient }) => (feature) => ({
|
|
106
|
+
ALL: createFeatureAllQueryTarget(feature),
|
|
107
|
+
auth: (actionName) => createActionBuilder(withActionMetadata(authActionClient, {
|
|
108
|
+
actionName,
|
|
109
|
+
feature,
|
|
110
|
+
requiresAuth: true,
|
|
111
|
+
}), {
|
|
112
|
+
actionName,
|
|
113
|
+
feature,
|
|
114
|
+
requiresAuth: true,
|
|
115
|
+
}),
|
|
116
|
+
public: (actionName) => createActionBuilder(withActionMetadata(actionClient, {
|
|
117
|
+
actionName,
|
|
118
|
+
feature,
|
|
119
|
+
requiresAuth: false,
|
|
120
|
+
}), {
|
|
121
|
+
actionName,
|
|
122
|
+
feature,
|
|
123
|
+
requiresAuth: false,
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/actions/builder.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,+BAA+B,EAC/B,yBAAyB,GAI1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,EACL,eAAe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,mBAAmB,CACjB,kBAAkB,CAAC,YAAY,EAAE;QAC/B,UAAU;QACV,OAAO;QACP,YAAY,EAAE,KAAK;KACpB,CAAC,EACF;QACE,UAAU;QACV,OAAO;QACP,YAAY,EAAE,KAAK;KACpB,CACF;CACJ,CAAC,CAAC","sourcesContent":["import 'server-only';\n\nimport {\n attachActionRuntime,\n createFeatureAllQueryTarget,\n getActionQueryKeyPrefixFromSpec,\n resolveInvalidationTarget,\n type ActionInvalidationTarget,\n type ActionQueryKey,\n type ActionQuerySpec,\n} from '@ontahi/core/runtime/actions';\nimport {\n layer,\n runServerEffect,\n type EffectSuccessPayload,\n type LayerConcern,\n type OperationFailure,\n type OperationInput,\n type OperationRequirement,\n type OperationRuntimeError,\n} from '@ontahi/core/runtime/server';\nimport { isRecord } from '@ontahi/core/value/object';\nimport type { Effect } from 'effect';\nimport type {\n InputSchemaFactoryFn,\n MaybeBrandThrows,\n SafeActionClient,\n SafeActionFn,\n ServerCodeFn,\n} from 'next-safe-action';\n\nimport { type ActionMetadata, withActionMetadata } from './transport.js';\n\nconst toScopeSegment = (value: string) =>\n value.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase());\n\ntype InferClientMetadata<TClient> =\n TClient extends SafeActionClient<\n any,\n any,\n any,\n infer Metadata,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n ? Metadata\n : never;\n\ntype InferClientCtx<TClient> =\n TClient extends SafeActionClient<any, any, any, any, any, infer Ctx, any, any, any, any, any, any>\n ? Ctx\n : object;\n\ntype InferClientInputSchema<TClient> =\n TClient extends SafeActionClient<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n infer InputSchema,\n any,\n any,\n any,\n any\n >\n ? InputSchema\n : undefined;\n\ntype InferClientBindArgsSchemas<TClient> =\n TClient extends SafeActionClient<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n infer BindArgsSchemas,\n any,\n any\n >\n ? BindArgsSchemas\n : readonly [];\n\ntype InferStandardSchemaOutput<Schema> = Schema extends {\n readonly '~standard': {\n readonly types?: {\n readonly output: infer Output;\n };\n };\n}\n ? Output\n : undefined;\n\ntype InferClientParsedInput<TClient> = InferStandardSchemaOutput<InferClientInputSchema<TClient>>;\n\ntype ActionFnForClient<TClient, Data> =\n TClient extends SafeActionClient<\n infer ServerError,\n any,\n any,\n any,\n any,\n any,\n any,\n infer InputSchema,\n any,\n infer BindArgsSchemas,\n infer ShapedErrors,\n infer ThrowsValidationErrors\n >\n ? MaybeBrandThrows<\n SafeActionFn<ServerError, InputSchema, BindArgsSchemas, ShapedErrors, Data>,\n ThrowsValidationErrors\n >\n : never;\n\ntype ActionArgsForClient<TClient> = Parameters<\n ServerCodeFn<\n InferClientMetadata<TClient>,\n InferClientCtx<TClient>,\n InferClientInputSchema<TClient>,\n InferClientBindArgsSchemas<TClient>,\n unknown\n >\n>[0];\n\ntype ActionInputFnForClient<TClient, Data> = (\n parsedInput: InferClientParsedInput<TClient>,\n) => Data | Promise<Data>;\n\ntype MaybePromise<T> = T | Promise<T>;\n\ntype ActionOperationOptions<TClient, Data> = {\n mapInput?: (\n parsedInput: InferClientParsedInput<TClient>,\n actionArgs: ActionArgsForClient<TClient>,\n ) => unknown;\n onSuccess?: (args: {\n parsedInput: InferClientParsedInput<TClient>;\n input: unknown;\n result: Awaited<Data>;\n actionArgs: ActionArgsForClient<TClient>;\n }) => MaybePromise<unknown>;\n};\n\ntype DomainOperationForClient<TClient, Data> = {\n operation: ActionInputFnForClient<TClient, Data>;\n};\n\ntype CanonicalDomainOperationForClient<TClient> = {\n name: string;\n layer: string;\n run: (\n input: InferClientParsedInput<TClient>,\n ) => Effect.Effect<\n Record<string, unknown> | void | EffectSuccessPayload<Record<string, unknown> | void>,\n OperationFailure | OperationRuntimeError\n >;\n defectLogMessage?: string;\n defectPublicMessage?: string;\n extra?: (input: InferClientParsedInput<TClient>) => Record<string, unknown>;\n telemetrySpanName?: string;\n requires?: ReadonlyArray<OperationRequirement<InferClientParsedInput<TClient> & OperationInput>>;\n concerns?: ReadonlyArray<LayerConcern<InferClientParsedInput<TClient>, unknown>>;\n contracts?: unknown;\n};\n\ntype AnyDomainOperationForClient<TClient, Data> =\n | DomainOperationForClient<TClient, Data>\n | CanonicalDomainOperationForClient<TClient>;\n\ntype InvalidationResolver<TInput, TData> = (args: {\n input: TInput;\n data: TData;\n}) => ActionInvalidationTarget[];\n\ntype AnySafeActionClient = SafeActionClient<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\n\ntype ResolvedInputSchema<Schema> =\n Schema extends InputSchemaFactoryFn<any, infer NextSchema> ? NextSchema : Schema;\n\ntype NextClientForSchema<\n Client extends AnySafeActionClient,\n Schema extends Parameters<Client['inputSchema']>[0],\n> =\n Client extends SafeActionClient<\n infer ServerError,\n infer ErrorsFormat,\n infer MetadataSchema,\n infer Metadata,\n infer HasMetadata,\n infer Ctx,\n infer InputSchemaFn,\n infer CurrentInputSchema,\n infer OutputSchema,\n infer BindArgsSchemas,\n any,\n infer ThrowsValidationErrors\n >\n ? SafeActionClient<\n ServerError,\n ErrorsFormat,\n MetadataSchema,\n Metadata,\n HasMetadata,\n Ctx,\n InputSchemaFn,\n ResolvedInputSchema<Schema>,\n OutputSchema,\n BindArgsSchemas,\n any,\n ThrowsValidationErrors\n >\n : AnySafeActionClient;\n\ntype MetadataClient<Client extends AnySafeActionClient> = ReturnType<Client['metadata']>;\n\ntype ActionBuilder<Client extends AnySafeActionClient> = {\n input: <Schema extends Parameters<Client['inputSchema']>[0]>(\n schema: Schema,\n ) => ActionBuilder<NextClientForSchema<Client, Schema>>;\n inputType: <Schema extends Parameters<Client['inputSchema']>[0]>(\n schema: Schema,\n ) => ActionBuilder<NextClientForSchema<Client, Schema>>;\n key: {\n (querySpec: ActionQuerySpec<InferClientParsedInput<Client>>): ActionBuilder<Client>;\n (getQueryKey: (input: InferClientParsedInput<Client>) => ActionQueryKey): ActionBuilder<Client>;\n };\n affects: (\n targets:\n | ActionInvalidationTarget[]\n | InvalidationResolver<InferClientParsedInput<Client>, unknown>,\n ) => ActionBuilder<Client>;\n run: <Data>(\n serverCodeFn: ServerCodeFn<\n InferClientMetadata<Client>,\n InferClientCtx<Client>,\n InferClientInputSchema<Client>,\n InferClientBindArgsSchemas<Client>,\n Data\n >,\n ) => ActionFnForClient<Client, Data>;\n runEffect: <Data>(\n effectFn: (\n parsedInput: InferClientParsedInput<Client>,\n ) => Effect.Effect<Data | EffectSuccessPayload<Data>, unknown>,\n options?: {\n scope?: string;\n telemetrySpanName?: string;\n input?: (\n parsedInput: InferClientParsedInput<Client>,\n actionArgs: ActionArgsForClient<Client>,\n ) => Record<string, unknown> | undefined;\n extra?: (\n parsedInput: InferClientParsedInput<Client>,\n actionArgs: ActionArgsForClient<Client>,\n ) => Record<string, unknown> | undefined;\n },\n ) => ActionFnForClient<Client, Data>;\n runOperation: <Data>(\n operationFn: ActionInputFnForClient<Client, Data>,\n options?: ActionOperationOptions<Client, Data>,\n ) => ActionFnForClient<Client, Data>;\n runDomainOperation: <Data>(\n operation: AnyDomainOperationForClient<Client, Data>,\n options?: ActionOperationOptions<Client, Data>,\n ) => ActionFnForClient<Client, Data>;\n};\n\ntype ActionBuilderConfig<Client> = {\n querySpec?: ActionQuerySpec<InferClientParsedInput<Client>>;\n invalidationQueryKeyPrefix?: ActionQueryKey;\n getQueryKey?: (input: InferClientParsedInput<Client>) => ActionQueryKey;\n getAffects?: InvalidationResolver<InferClientParsedInput<Client>, unknown>;\n};\n\nconst createActionBuilder = <Client extends AnySafeActionClient>(\n client: Client,\n metadata: ActionMetadata,\n config?: ActionBuilderConfig<Client>,\n): ActionBuilder<Client> => {\n const resolveKeyConfig = (\n specOrGetQueryKey:\n | ActionQuerySpec<InferClientParsedInput<Client>>\n | ((input: InferClientParsedInput<Client>) => ActionQueryKey),\n ): Pick<\n ActionBuilderConfig<Client>,\n 'querySpec' | 'invalidationQueryKeyPrefix' | 'getQueryKey'\n > => {\n if (typeof specOrGetQueryKey === 'function') {\n const getQueryKey = specOrGetQueryKey as (\n input: InferClientParsedInput<Client>,\n ) => ActionQueryKey;\n\n return {\n getQueryKey,\n querySpec: undefined,\n invalidationQueryKeyPrefix: undefined,\n };\n }\n\n return {\n getQueryKey: undefined,\n querySpec: specOrGetQueryKey,\n invalidationQueryKeyPrefix: getActionQueryKeyPrefixFromSpec(specOrGetQueryKey),\n };\n };\n\n const input = <Schema extends Parameters<Client['inputSchema']>[0]>(schema: Schema) => {\n const nextClient = client.inputSchema(schema);\n return createActionBuilder<typeof nextClient>(nextClient, metadata, config as any);\n };\n\n const inputType = <Schema extends Parameters<Client['inputSchema']>[0]>(schema: Schema) => {\n const nextClient = client.inputSchema(schema);\n return createActionBuilder<typeof nextClient>(nextClient, metadata, config as any);\n };\n\n function key(\n querySpec: ActionQuerySpec<InferClientParsedInput<Client>>,\n ): ReturnType<typeof createActionBuilder<Client>>;\n function key(\n getQueryKey: (input: InferClientParsedInput<Client>) => ActionQueryKey,\n ): ReturnType<typeof createActionBuilder<Client>>;\n function key(\n specOrGetQueryKey:\n | ActionQuerySpec<InferClientParsedInput<Client>>\n | ((input: InferClientParsedInput<Client>) => ActionQueryKey),\n ) {\n const nextKeyConfig = resolveKeyConfig(specOrGetQueryKey);\n\n return createActionBuilder(client, metadata, {\n ...config,\n ...nextKeyConfig,\n });\n }\n\n const affects = (\n targets:\n | ActionInvalidationTarget[]\n | InvalidationResolver<InferClientParsedInput<Client>, unknown>,\n ) =>\n createActionBuilder(client, metadata, {\n ...config,\n getAffects:\n typeof targets === 'function'\n ? (targets as InvalidationResolver<InferClientParsedInput<Client>, unknown>)\n : () => targets,\n });\n\n const run = <Data>(\n serverCodeFn: ServerCodeFn<\n InferClientMetadata<Client>,\n InferClientCtx<Client>,\n InferClientInputSchema<Client>,\n InferClientBindArgsSchemas<Client>,\n Data\n >,\n ): ActionFnForClient<Client, Data> =>\n attachActionRuntime(\n client.action<Data>(async actionArgs =>\n serverCodeFn(actionArgs as unknown as Parameters<typeof serverCodeFn>[0]),\n ) as ActionFnForClient<Client, Data>,\n {\n feature: metadata.feature,\n actionName: metadata.actionName,\n requiresAuth: metadata.requiresAuth ?? false,\n queryKeyPrefix: [metadata.feature, metadata.actionName] as const,\n querySpec: config?.querySpec,\n invalidationQueryKeyPrefix: config?.invalidationQueryKeyPrefix,\n getQueryKey: config?.getQueryKey as\n | ((input: InferClientParsedInput<Client>) => ActionQueryKey)\n | undefined,\n getAffectedQueryKeys: config?.getAffects\n ? args =>\n config\n .getAffects?.(args as { input: InferClientParsedInput<Client>; data: unknown })\n .flatMap(resolveInvalidationTarget) ?? []\n : undefined,\n },\n ) as unknown as ActionFnForClient<Client, Data>;\n\n const runEffect = <Data>(\n effectFn: (\n parsedInput: InferClientParsedInput<Client>,\n ) => Effect.Effect<Data | EffectSuccessPayload<Data>, unknown>,\n options?: {\n scope?: string;\n telemetrySpanName?: string;\n input?: (\n parsedInput: InferClientParsedInput<Client>,\n actionArgs: ActionArgsForClient<Client>,\n ) => Record<string, unknown> | undefined;\n extra?: (\n parsedInput: InferClientParsedInput<Client>,\n actionArgs: ActionArgsForClient<Client>,\n ) => Record<string, unknown> | undefined;\n },\n ) =>\n run<Data>(actionArgs => {\n const typedArgs = actionArgs as ActionArgsForClient<Client>;\n const parsedInput = typedArgs.parsedInput as InferClientParsedInput<Client>;\n const input =\n options?.input?.(parsedInput, typedArgs) ??\n (isRecord(parsedInput) ? parsedInput : undefined);\n const extra = options?.extra?.(parsedInput, typedArgs);\n\n return runServerEffect(effectFn(parsedInput), {\n scope:\n options?.scope ??\n `app.actions.${toScopeSegment(metadata.feature)}.${metadata.actionName}`,\n telemetrySpanName: options?.telemetrySpanName,\n input,\n extra,\n });\n });\n\n const runOperation = <Data>(\n operationFn: ActionInputFnForClient<Client, Data>,\n options?: ActionOperationOptions<Client, Data>,\n ): ActionFnForClient<Client, Data> =>\n run<Data>(async actionArgs => {\n const typedArgs = actionArgs as ActionArgsForClient<Client>;\n const parsedInput = typedArgs.parsedInput as InferClientParsedInput<Client>;\n const input = (options?.mapInput?.(parsedInput, typedArgs) ??\n parsedInput) as InferClientParsedInput<Client>;\n const result = await Promise.resolve(operationFn(input));\n\n if (options?.onSuccess) {\n await options.onSuccess({\n parsedInput,\n input,\n result: result as Awaited<Data>,\n actionArgs: typedArgs,\n });\n }\n\n return result;\n });\n\n const runDomainOperation = <Data>(\n operation: AnyDomainOperationForClient<Client, Data>,\n options?: ActionOperationOptions<Client, Data>,\n ): ActionFnForClient<Client, Data> => {\n if ('operation' in operation) {\n return runOperation(operation.operation, options);\n }\n\n const operationRunner = layer(operation.layer).operation(\n operation.name,\n operation.run as never,\n {\n defectLogMessage: operation.defectLogMessage,\n defectPublicMessage: operation.defectPublicMessage,\n extra: operation.extra,\n telemetrySpanName: operation.telemetrySpanName,\n requires: operation.requires,\n concerns: operation.concerns,\n contracts: operation.contracts,\n } as never,\n ) as ActionInputFnForClient<Client, Data>;\n\n return runOperation(operationRunner, options);\n };\n\n return { input, inputType, key, affects, run, runEffect, runOperation, runDomainOperation };\n};\n\ntype FeatureActionsFactory = <\n PublicClient extends AnySafeActionClient,\n AuthClient extends AnySafeActionClient,\n>(clients: {\n actionClient: PublicClient;\n authActionClient: AuthClient;\n}) => (feature: string) => {\n ALL: ReturnType<typeof createFeatureAllQueryTarget>;\n auth: (actionName: string) => ActionBuilder<MetadataClient<AuthClient>>;\n public: (actionName: string) => ActionBuilder<MetadataClient<PublicClient>>;\n};\n\nexport const createFeatureActionsFactory: FeatureActionsFactory =\n ({ actionClient, authActionClient }) =>\n (feature: string) => ({\n ALL: createFeatureAllQueryTarget(feature),\n auth: (actionName: string) =>\n createActionBuilder(\n withActionMetadata(authActionClient, {\n actionName,\n feature,\n requiresAuth: true,\n }),\n {\n actionName,\n feature,\n requiresAuth: true,\n },\n ),\n public: (actionName: string) =>\n createActionBuilder(\n withActionMetadata(actionClient, {\n actionName,\n feature,\n requiresAuth: false,\n }),\n {\n actionName,\n feature,\n requiresAuth: false,\n },\n ),\n });\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC","sourcesContent":["export * from '@ontahi/core/runtime/actions';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/actions/server.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/actions/server.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC","sourcesContent":["export * from './transport.js';\nexport * from './builder.js';\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const actionMetadataSchema: z.ZodObject<{
|
|
4
|
+
actionName: z.ZodString;
|
|
5
|
+
feature: z.ZodString;
|
|
6
|
+
requiresAuth: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type ActionMetadata = z.infer<typeof actionMetadataSchema>;
|
|
9
|
+
export declare class UserFacingActionError extends Error {
|
|
10
|
+
readonly name = "UserFacingActionError";
|
|
11
|
+
}
|
|
12
|
+
export type CreateNextActionTransportOptions<TAuthContext extends object> = {
|
|
13
|
+
getAuthContext: () => Promise<TAuthContext | null | undefined>;
|
|
14
|
+
handleServerError?: (args: {
|
|
15
|
+
error: unknown;
|
|
16
|
+
metadata: ActionMetadata | undefined;
|
|
17
|
+
defaultMessage: string;
|
|
18
|
+
}) => string;
|
|
19
|
+
notAuthenticatedMessage?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const createNextActionTransport: <TAuthContext extends object>(options: CreateNextActionTransportOptions<TAuthContext>) => {
|
|
22
|
+
actionClient: import("next-safe-action").SafeActionClient<string, "flattened", z.ZodObject<{
|
|
23
|
+
actionName: z.ZodString;
|
|
24
|
+
feature: z.ZodString;
|
|
25
|
+
requiresAuth: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
+
}, z.core.$strip>, {
|
|
27
|
+
actionName: string;
|
|
28
|
+
feature: string;
|
|
29
|
+
requiresAuth?: boolean | undefined;
|
|
30
|
+
}, false, {}, undefined, undefined, undefined, readonly [], {
|
|
31
|
+
formErrors: string[];
|
|
32
|
+
fieldErrors: {};
|
|
33
|
+
} | undefined, false, false, {}>;
|
|
34
|
+
authActionClient: import("next-safe-action").SafeActionClient<string, "flattened", z.ZodObject<{
|
|
35
|
+
actionName: z.ZodString;
|
|
36
|
+
feature: z.ZodString;
|
|
37
|
+
requiresAuth: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
}, z.core.$strip>, {
|
|
39
|
+
actionName: string;
|
|
40
|
+
feature: string;
|
|
41
|
+
requiresAuth?: boolean | undefined;
|
|
42
|
+
}, false, Awaited<TAuthContext>, undefined, undefined, undefined, readonly [], {
|
|
43
|
+
formErrors: string[];
|
|
44
|
+
fieldErrors: {};
|
|
45
|
+
} | undefined, false, false, Awaited<TAuthContext>>;
|
|
46
|
+
};
|
|
47
|
+
export declare const withActionMetadata: <Client extends {
|
|
48
|
+
metadata: (data: ActionMetadata) => any;
|
|
49
|
+
}>(client: Client, metadata: ActionMetadata) => ReturnType<Client["metadata"]>;
|
|
50
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/actions/transport.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAOrB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,oBAAoB;;;;iBAI/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,2BAA2B;CACzC;AAED,MAAM,MAAM,gCAAgC,CAAC,YAAY,SAAS,MAAM,IAAI;IAC1E,cAAc,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAC/D,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE;QACzB,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;QACrC,cAAc,EAAE,MAAM,CAAC;KACxB,KAAK,MAAM,CAAC;IACb,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,YAAY,SAAS,MAAM,EACnE,SAAS,gCAAgC,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;CAsCxD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,MAAM,SAAS;IAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,GAAG,CAAA;CAAE,EAC3F,QAAQ,MAAM,EACd,UAAU,cAAc,KACvB,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAA8B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { createMiddleware, createSafeActionClient, DEFAULT_SERVER_ERROR_MESSAGE, } from 'next-safe-action';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const actionMetadataSchema = z.object({
|
|
5
|
+
actionName: z.string().min(1),
|
|
6
|
+
feature: z.string().min(1),
|
|
7
|
+
requiresAuth: z.boolean().optional(),
|
|
8
|
+
});
|
|
9
|
+
export class UserFacingActionError extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.name = 'UserFacingActionError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const createNextActionTransport = (options) => {
|
|
16
|
+
const baseActionClient = createSafeActionClient({
|
|
17
|
+
defineMetadataSchema: () => actionMetadataSchema,
|
|
18
|
+
defaultValidationErrorsShape: 'flattened',
|
|
19
|
+
handleServerError: (error, { metadata }) => {
|
|
20
|
+
if (error instanceof UserFacingActionError) {
|
|
21
|
+
return error.message;
|
|
22
|
+
}
|
|
23
|
+
return (options.handleServerError?.({
|
|
24
|
+
error,
|
|
25
|
+
metadata,
|
|
26
|
+
defaultMessage: DEFAULT_SERVER_ERROR_MESSAGE,
|
|
27
|
+
}) ?? DEFAULT_SERVER_ERROR_MESSAGE);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const authMiddleware = createMiddleware().define(async ({ next }) => {
|
|
31
|
+
const authContext = await options.getAuthContext();
|
|
32
|
+
if (!authContext) {
|
|
33
|
+
throw new UserFacingActionError(options.notAuthenticatedMessage ?? 'Not authenticated');
|
|
34
|
+
}
|
|
35
|
+
return next({ ctx: authContext });
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
actionClient: baseActionClient,
|
|
39
|
+
authActionClient: baseActionClient.use(authMiddleware),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export const withActionMetadata = (client, metadata) => client.metadata(metadata);
|
|
43
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/actions/transport.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MA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AAE,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,YAAY,EAAE,gBAAgB;QAC9B,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC;KACvD,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAc,EACd,QAAwB,EACQ,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC","sourcesContent":["import 'server-only';\n\nimport {\n createMiddleware,\n createSafeActionClient,\n DEFAULT_SERVER_ERROR_MESSAGE,\n} from 'next-safe-action';\nimport { z } from 'zod';\n\nexport const actionMetadataSchema = z.object({\n actionName: z.string().min(1),\n feature: z.string().min(1),\n requiresAuth: z.boolean().optional(),\n});\n\nexport type ActionMetadata = z.infer<typeof actionMetadataSchema>;\n\nexport class UserFacingActionError extends Error {\n readonly name = 'UserFacingActionError';\n}\n\nexport type CreateNextActionTransportOptions<TAuthContext extends object> = {\n getAuthContext: () => Promise<TAuthContext | null | undefined>;\n handleServerError?: (args: {\n error: unknown;\n metadata: ActionMetadata | undefined;\n defaultMessage: string;\n }) => string;\n notAuthenticatedMessage?: string;\n};\n\nexport const createNextActionTransport = <TAuthContext extends object>(\n options: CreateNextActionTransportOptions<TAuthContext>,\n) => {\n const baseActionClient = createSafeActionClient({\n defineMetadataSchema: () => actionMetadataSchema,\n defaultValidationErrorsShape: 'flattened',\n handleServerError: (error, { metadata }) => {\n if (error instanceof UserFacingActionError) {\n return error.message;\n }\n\n return (\n options.handleServerError?.({\n error,\n metadata,\n defaultMessage: DEFAULT_SERVER_ERROR_MESSAGE,\n }) ?? DEFAULT_SERVER_ERROR_MESSAGE\n );\n },\n });\n\n const authMiddleware = createMiddleware<{\n serverError: string;\n ctx: object;\n metadata: ActionMetadata;\n }>().define(async ({ next }) => {\n const authContext = await options.getAuthContext();\n\n if (!authContext) {\n throw new UserFacingActionError(options.notAuthenticatedMessage ?? 'Not authenticated');\n }\n\n return next({ ctx: authContext });\n });\n\n return {\n actionClient: baseActionClient,\n authActionClient: baseActionClient.use(authMiddleware),\n };\n};\n\nexport const withActionMetadata = <Client extends { metadata: (data: ActionMetadata) => any }>(\n client: Client,\n metadata: ActionMetadata,\n): ReturnType<Client['metadata']> => client.metadata(metadata);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,KAAK,gDAAgD,GACtD,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,GAE1C,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextOperationInvocationRouteHandler,\n type CreateNextOperationInvocationRouteHandlerOptions,\n} from './route.js';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type OperationInvocationDispatcher } from '@ontahi/core/runtime/operation-invocation';
|
|
2
|
+
export type CreateNextOperationInvocationRouteHandlerOptions = {
|
|
3
|
+
dispatcher: OperationInvocationDispatcher;
|
|
4
|
+
reportError?: (error: unknown, request: Request) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const createNextOperationInvocationRouteHandler: ({ dispatcher, reportError }: CreateNextOperationInvocationRouteHandlerOptions) => (request: Request) => Promise<Response>;
|
|
7
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,6BAA6B,EAEnC,MAAM,2CAA2C,CAAC;AAEnD,MAAM,MAAM,gDAAgD,GAAG;IAC7D,UAAU,EAAE,6BAA6B,CAAC;IAC1C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAKF,eAAO,MAAM,yCAAyC,GACnD,6BAA6B,gDAAgD,MACvE,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAsBzC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { operationInvocationProtocolError, parseOperationInvocationRequest, } from '@ontahi/core/runtime/operation-invocation';
|
|
2
|
+
const responseStatus = (response) => response.kind === 'protocol-error' ? 500 : 200;
|
|
3
|
+
export const createNextOperationInvocationRouteHandler = ({ dispatcher, reportError }) => async (request) => {
|
|
4
|
+
const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));
|
|
5
|
+
if (!parsedRequest.success) {
|
|
6
|
+
return Response.json(parsedRequest.error, { status: 400 });
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const response = await dispatcher(parsedRequest.request);
|
|
10
|
+
return Response.json(response, { status: responseStatus(response) });
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
reportError?.(error, request);
|
|
14
|
+
return Response.json(operationInvocationProtocolError('invocation_unavailable', 'Operation invocation is temporarily unavailable.'), { status: 500 });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAGhC,MAAM,2CAA2C,CAAC;AAOnD,MAAM,cAAc,GAAG,CAAC,QAA6C,EAAE,EAAE,CACvE,QAAQ,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAEjD,MAAM,CAAC,MAAM,yCAAyC,GACpD,CAAC,EAAE,UAAU,EAAE,WAAW,EAAoD,EAAE,EAAE,CAClF,KAAK,EAAE,OAAgB,EAAqB,EAAE;IAC5C,MAAM,aAAa,GAAG,+BAA+B,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9F,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAEzD,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAE9B,OAAO,QAAQ,CAAC,IAAI,CAClB,gCAAgC,CAC9B,wBAAwB,EACxB,kDAAkD,CACnD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n operationInvocationProtocolError,\n parseOperationInvocationRequest,\n type OperationInvocationDispatcher,\n type OperationInvocationProtocolResponse,\n} from '@ontahi/core/runtime/operation-invocation';\n\nexport type CreateNextOperationInvocationRouteHandlerOptions = {\n dispatcher: OperationInvocationDispatcher;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (response: OperationInvocationProtocolResponse) =>\n response.kind === 'protocol-error' ? 500 : 200;\n\nexport const createNextOperationInvocationRouteHandler =\n ({ dispatcher, reportError }: CreateNextOperationInvocationRouteHandlerOptions) =>\n async (request: Request): Promise<Response> => {\n const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));\n\n if (!parsedRequest.success) {\n return Response.json(parsedRequest.error, { status: 400 });\n }\n\n try {\n const response = await dispatcher(parsedRequest.request);\n\n return Response.json(response, { status: responseStatus(response) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n operationInvocationProtocolError(\n 'invocation_unavailable',\n 'Operation invocation is temporarily unavailable.',\n ),\n { status: 500 },\n );\n }\n };\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ontahi/runtime-nextjs",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Next.js action runtime and transport helpers for Ontahi applications",
|
|
5
|
+
"homepage": "https://github.com/javifernandes/ontahi/tree/main/packages/runtime-nextjs",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Javier Fernandes",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/javifernandes/ontahi.git",
|
|
11
|
+
"directory": "packages/runtime-nextjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "dist/actions/index.js",
|
|
20
|
+
"types": "dist/actions/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/actions/index.d.ts",
|
|
24
|
+
"import": "./dist/actions/index.js",
|
|
25
|
+
"require": "./dist/actions/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./actions": {
|
|
28
|
+
"types": "./dist/actions/index.d.ts",
|
|
29
|
+
"import": "./dist/actions/index.js",
|
|
30
|
+
"require": "./dist/actions/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./actions/server": {
|
|
33
|
+
"types": "./dist/actions/server.d.ts",
|
|
34
|
+
"import": "./dist/actions/server.js",
|
|
35
|
+
"require": "./dist/actions/server.js"
|
|
36
|
+
},
|
|
37
|
+
"./operation-invocation": {
|
|
38
|
+
"types": "./dist/operation-invocation/index.d.ts",
|
|
39
|
+
"import": "./dist/operation-invocation/index.js",
|
|
40
|
+
"require": "./dist/operation-invocation/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"provenance": true
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"effect": "^3.21.0",
|
|
49
|
+
"next-safe-action": "^8.3.0",
|
|
50
|
+
"server-only": "^0.0.1",
|
|
51
|
+
"zod": "^4.3.6",
|
|
52
|
+
"@ontahi/core": "0.1.0-alpha.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
56
|
+
"@types/react": "^18.3.0",
|
|
57
|
+
"@types/react-dom": "^18.3.0",
|
|
58
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
59
|
+
"next": "^14.2.0",
|
|
60
|
+
"react": "^18.3.0",
|
|
61
|
+
"react-dom": "^18.3.0",
|
|
62
|
+
"typescript": "^5.0.0",
|
|
63
|
+
"vitest": "^4.0.18"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@types/react": "^18.3.0 || ^19.0.0",
|
|
67
|
+
"@types/react-dom": "^18.3.0 || ^19.0.0",
|
|
68
|
+
"next": ">=14.2.0 <17",
|
|
69
|
+
"react": ">=18.3.0 <20",
|
|
70
|
+
"react-dom": ">=18.3.0 <20"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@types/react": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@types/react-dom": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=20.19.0"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "pnpm exec tsc -p tsconfig.build.json",
|
|
85
|
+
"build:watch": "pnpm exec tsc -p tsconfig.build.json --watch",
|
|
86
|
+
"test": "pnpm exec vitest run",
|
|
87
|
+
"test:coverage": "pnpm exec vitest run --coverage",
|
|
88
|
+
"test:watch": "pnpm exec vitest",
|
|
89
|
+
"typecheck": "pnpm exec tsc -p tsconfig.json",
|
|
90
|
+
"lint": "pnpm exec eslint \"src/**/*.ts\" \"test/**/*.ts\" --max-warnings 0",
|
|
91
|
+
"lint:fix": "pnpm exec eslint \"src/**/*.ts\" \"test/**/*.ts\" --fix --max-warnings 0"
|
|
92
|
+
}
|
|
93
|
+
}
|