@jay-framework/compiler-jay-stack 0.15.6 → 0.16.1
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/index.d.ts +4 -0
- package/dist/index.js +55 -12
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,10 @@ interface ActionMetadata {
|
|
|
60
60
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
61
61
|
/** Export name in the source module */
|
|
62
62
|
exportName: string;
|
|
63
|
+
/** Whether this is a streaming action (makeJayStream) */
|
|
64
|
+
isStreaming?: boolean;
|
|
65
|
+
/** Whether this action accepts file uploads (DL#131) */
|
|
66
|
+
acceptsFiles?: boolean;
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* Result of extracting actions from a module.
|
package/dist/index.js
CHANGED
|
@@ -314,6 +314,7 @@ function extractActionFromExpression(node) {
|
|
|
314
314
|
let current = node;
|
|
315
315
|
let method = "POST";
|
|
316
316
|
let explicitMethod = null;
|
|
317
|
+
let acceptsFiles = false;
|
|
317
318
|
while (tsBridge.isCallExpression(current)) {
|
|
318
319
|
const expr = current.expression;
|
|
319
320
|
if (tsBridge.isPropertyAccessExpression(expr) && expr.name.text === "withMethod") {
|
|
@@ -324,22 +325,36 @@ function extractActionFromExpression(node) {
|
|
|
324
325
|
current = expr.expression;
|
|
325
326
|
continue;
|
|
326
327
|
}
|
|
328
|
+
if (tsBridge.isPropertyAccessExpression(expr) && expr.name.text === "withFiles") {
|
|
329
|
+
acceptsFiles = true;
|
|
330
|
+
current = expr.expression;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
327
333
|
if (tsBridge.isPropertyAccessExpression(expr) && ["withServices", "withCaching", "withHandler", "withTimeout"].includes(expr.name.text)) {
|
|
328
334
|
current = expr.expression;
|
|
329
335
|
continue;
|
|
330
336
|
}
|
|
331
337
|
if (tsBridge.isIdentifier(expr)) {
|
|
332
338
|
const funcName = expr.text;
|
|
333
|
-
if (funcName === "makeJayAction" || funcName === "makeJayQuery") {
|
|
339
|
+
if (funcName === "makeJayAction" || funcName === "makeJayQuery" || funcName === "makeJayStream") {
|
|
334
340
|
const nameArg = current.arguments[0];
|
|
335
341
|
if (nameArg && tsBridge.isStringLiteral(nameArg)) {
|
|
342
|
+
if (funcName === "makeJayStream") {
|
|
343
|
+
return {
|
|
344
|
+
actionName: nameArg.text,
|
|
345
|
+
method: "POST",
|
|
346
|
+
isStreaming: true,
|
|
347
|
+
...acceptsFiles && { acceptsFiles: true }
|
|
348
|
+
};
|
|
349
|
+
}
|
|
336
350
|
method = funcName === "makeJayQuery" ? "GET" : "POST";
|
|
337
351
|
if (explicitMethod) {
|
|
338
352
|
method = explicitMethod;
|
|
339
353
|
}
|
|
340
354
|
return {
|
|
341
355
|
actionName: nameArg.text,
|
|
342
|
-
method
|
|
356
|
+
method,
|
|
357
|
+
...acceptsFiles && { acceptsFiles: true }
|
|
343
358
|
};
|
|
344
359
|
}
|
|
345
360
|
}
|
|
@@ -386,6 +401,7 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
386
401
|
}
|
|
387
402
|
const replacements = [];
|
|
388
403
|
let needsCreateActionCallerImport = false;
|
|
404
|
+
let needsCreateStreamCallerImport = false;
|
|
389
405
|
for (const imp of actionImports) {
|
|
390
406
|
const resolved = await resolveActionModule(imp.source, id);
|
|
391
407
|
if (!resolved) {
|
|
@@ -397,10 +413,18 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
397
413
|
for (const importName of imp.namedImports) {
|
|
398
414
|
const action = actions.find((a) => a.exportName === importName);
|
|
399
415
|
if (action) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
416
|
+
const filesOpt = action.acceptsFiles ? ", { acceptsFiles: true }" : "";
|
|
417
|
+
if (action.isStreaming) {
|
|
418
|
+
callerDeclarations.push(
|
|
419
|
+
`const ${importName} = createStreamCaller('${action.actionName}'${filesOpt});`
|
|
420
|
+
);
|
|
421
|
+
needsCreateStreamCallerImport = true;
|
|
422
|
+
} else {
|
|
423
|
+
callerDeclarations.push(
|
|
424
|
+
`const ${importName} = createActionCaller('${action.actionName}', '${action.method}'${filesOpt});`
|
|
425
|
+
);
|
|
426
|
+
needsCreateActionCallerImport = true;
|
|
427
|
+
}
|
|
404
428
|
} else {
|
|
405
429
|
getLogger().warn(
|
|
406
430
|
`[action-transform] Export '${importName}' from ${imp.source} is not a recognized action`
|
|
@@ -422,8 +446,13 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
422
446
|
for (const rep of replacements.sort((a, b) => b.start - a.start)) {
|
|
423
447
|
result = result.slice(0, rep.start) + rep.replacement + result.slice(rep.end);
|
|
424
448
|
}
|
|
425
|
-
|
|
426
|
-
|
|
449
|
+
const importNames = [];
|
|
450
|
+
if (needsCreateActionCallerImport)
|
|
451
|
+
importNames.push("createActionCaller");
|
|
452
|
+
if (needsCreateStreamCallerImport)
|
|
453
|
+
importNames.push("createStreamCaller");
|
|
454
|
+
if (importNames.length > 0) {
|
|
455
|
+
const importStatement = `import { ${importNames.join(", ")} } from '@jay-framework/stack-client-runtime';
|
|
427
456
|
`;
|
|
428
457
|
result = importStatement + result;
|
|
429
458
|
}
|
|
@@ -815,14 +844,28 @@ function jayStackCompiler(options = {}) {
|
|
|
815
844
|
getLogger().warn(`[action-transform] No actions found in ${actualPath}`);
|
|
816
845
|
return null;
|
|
817
846
|
}
|
|
847
|
+
const hasRegularActions = actions.some((a) => !a.isStreaming);
|
|
848
|
+
const hasStreamActions = actions.some((a) => a.isStreaming);
|
|
849
|
+
const importNames = [];
|
|
850
|
+
if (hasRegularActions)
|
|
851
|
+
importNames.push("createActionCaller");
|
|
852
|
+
if (hasStreamActions)
|
|
853
|
+
importNames.push("createStreamCaller");
|
|
818
854
|
const lines = [
|
|
819
|
-
`import {
|
|
855
|
+
`import { ${importNames.join(", ")} } from '@jay-framework/stack-client-runtime';`,
|
|
820
856
|
""
|
|
821
857
|
];
|
|
822
858
|
for (const action of actions) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
859
|
+
const filesOpt = action.acceptsFiles ? ", { acceptsFiles: true }" : "";
|
|
860
|
+
if (action.isStreaming) {
|
|
861
|
+
lines.push(
|
|
862
|
+
`export const ${action.exportName} = createStreamCaller('${action.actionName}'${filesOpt});`
|
|
863
|
+
);
|
|
864
|
+
} else {
|
|
865
|
+
lines.push(
|
|
866
|
+
`export const ${action.exportName} = createActionCaller('${action.actionName}', '${action.method}'${filesOpt});`
|
|
867
|
+
);
|
|
868
|
+
}
|
|
826
869
|
}
|
|
827
870
|
if (code.includes("ActionError")) {
|
|
828
871
|
lines.push(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/compiler-jay-stack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"test:watch": "vitest"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@jay-framework/compiler": "^0.
|
|
31
|
-
"@jay-framework/compiler-shared": "^0.
|
|
32
|
-
"@jay-framework/logger": "^0.
|
|
33
|
-
"@jay-framework/typescript-bridge": "^0.
|
|
34
|
-
"@jay-framework/vite-plugin": "^0.
|
|
30
|
+
"@jay-framework/compiler": "^0.16.1",
|
|
31
|
+
"@jay-framework/compiler-shared": "^0.16.1",
|
|
32
|
+
"@jay-framework/logger": "^0.16.1",
|
|
33
|
+
"@jay-framework/typescript-bridge": "^0.16.1",
|
|
34
|
+
"@jay-framework/vite-plugin": "^0.16.1",
|
|
35
35
|
"typescript": "^5.3.3",
|
|
36
36
|
"vite": "^5.0.11"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@jay-framework/dev-environment": "^0.
|
|
39
|
+
"@jay-framework/dev-environment": "^0.16.1",
|
|
40
40
|
"rimraf": "^5.0.5",
|
|
41
41
|
"tsup": "^8.0.1",
|
|
42
42
|
"vitest": "^1.2.1"
|