next-action-plus 2.0.0 → 2.0.2
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/dist/codemod/bin.js +15 -3
- package/dist/index.d.ts +6 -5
- package/package.json +1 -1
package/dist/codemod/bin.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/codemod/bin.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { join, resolve } from "path";
|
|
6
|
+
|
|
3
7
|
// src/codemod/v2.ts
|
|
4
|
-
import ts from "typescript";
|
|
5
8
|
var REMOVED = ["ActionPlus", "ActionPlusError", "ActionPlusValidationError", "isActionPlusError", "isActionPlusValidationError", "schemaAvailable"];
|
|
6
9
|
var codemodV2 = (props) => {
|
|
7
|
-
const {
|
|
10
|
+
const { write: write2, typescript: ts } = props;
|
|
11
|
+
const project2 = ts.sys.resolvePath(props.project);
|
|
8
12
|
const configPath = ts.findConfigFile(project2, ts.sys.fileExists, "tsconfig.json");
|
|
9
13
|
if (!configPath) throw new Error(`next-action-plus codemod: no tsconfig.json found in ${project2}`);
|
|
10
14
|
const config = ts.getParsedCommandLineOfConfigFile(configPath, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: (diagnostic) => console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")) });
|
|
@@ -152,7 +156,15 @@ if (command !== "codemod" || version !== "v2") {
|
|
|
152
156
|
}
|
|
153
157
|
var write = rest.includes("--write");
|
|
154
158
|
var project = rest.find((argument) => !argument.startsWith("--")) ?? process.cwd();
|
|
155
|
-
var
|
|
159
|
+
var typescript = (() => {
|
|
160
|
+
try {
|
|
161
|
+
return createRequire(join(resolve(project), "package.json"))("typescript");
|
|
162
|
+
} catch {
|
|
163
|
+
console.error(`next-action-plus codemod: cannot find "typescript" in ${resolve(project)}. Run the codemod from your project folder, where typescript is installed.`);
|
|
164
|
+
return process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
})();
|
|
167
|
+
var report = codemodV2({ project, write, typescript });
|
|
156
168
|
for (const file of report.files) {
|
|
157
169
|
console.log(`
|
|
158
170
|
${write ? "changed" : "would change"} ${file.file} (${file.changes} edits)`);
|
package/dist/index.d.ts
CHANGED
|
@@ -87,9 +87,12 @@ type TActionData<D extends TActionDefinition, Output> = D['output'] extends TSch
|
|
|
87
87
|
type TActionResult<D extends TActionDefinition, Output> = D['response'] extends TResponseLambda ? TResponseApply<D['response'], TActionData<D, Output>, TErrorUnion<D['errors']>> : TActionData<D, Output>;
|
|
88
88
|
type TActionParams<D extends TActionDefinition> = [
|
|
89
89
|
...TActionArgs<D['args'], 'input'>,
|
|
90
|
-
...(D['input'] extends TSchema ? (undefined extends TSchemaInput<D['input']> ? [input?: TSchemaInput<D['input']>
|
|
90
|
+
...(D['input'] extends TSchema ? (undefined extends TSchemaInput<D['input']> ? [input?: TSchemaInput<D['input']>] : [input: TSchemaInput<D['input']>]) : [input?: unknown])
|
|
91
91
|
];
|
|
92
|
-
type TActionFunction<D extends TActionDefinition, Output> =
|
|
92
|
+
type TActionFunction<D extends TActionDefinition, Output> = D['input'] extends TSchema ? {
|
|
93
|
+
(...params: [...TActionArgs<D['args'], 'input'>, form: FormData]): Promise<TActionResult<D, Output>>;
|
|
94
|
+
(...params: TActionParams<D>): Promise<TActionResult<D, Output>>;
|
|
95
|
+
} : (...params: TActionParams<D>) => Promise<TActionResult<D, Output>>;
|
|
93
96
|
type TActionHandler<D extends TActionDefinition, Output, Extra = {}> = (props: TPrettify<TActionHandlerProps<D> & Extra>) => Promise<D['output'] extends TSchema ? TSchemaInput<D['output']> : Output>;
|
|
94
97
|
type TActionGateCheck<D extends TActionDefinition> = D['gate'] extends 'required' ? TTypeError<'This action has no gate: add an auth plugin with .use(...) or call .public()'> : unknown;
|
|
95
98
|
type TActionBuilder<D extends TActionDefinition> = {
|
|
@@ -129,9 +132,7 @@ type TActionBuilder<D extends TActionDefinition> = {
|
|
|
129
132
|
state: {
|
|
130
133
|
previous: unknown;
|
|
131
134
|
};
|
|
132
|
-
}>) => (...params: [...TActionArgs<D['args'], 'input'>, previous: TActionResult<D, Output> | null | undefined, ...
|
|
133
|
-
args: [];
|
|
134
|
-
}>>]) => Promise<TActionResult<D, Output>>;
|
|
135
|
+
}>) => (...params: [...TActionArgs<D['args'], 'input'>, previous: TActionResult<D, Output> | null | undefined, ...(D['input'] extends TSchema ? [input: TSchemaInput<D['input']> | FormData] : [input?: unknown])]) => Promise<TActionResult<D, Output>>;
|
|
135
136
|
};
|
|
136
137
|
|
|
137
138
|
declare const actionCreate: <const Required extends boolean = true, Lambda extends TResponseLambda = never>(props?: Omit<TActionOptions, "gate" | "response"> & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-action-plus",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Type-safe, secure-by-default Next.js Server Actions: any Standard Schema validator, gates for auth, typed errors, your own response shape, concurrency control, and drop-in adapters for auth, rate limits, locks, queues and telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|