@jay-framework/compiler-jay-stack 0.15.5 → 0.16.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/dist/index.d.ts +2 -0
- package/dist/index.js +45 -12
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ 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;
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
65
67
|
* Result of extracting actions from a module.
|
package/dist/index.js
CHANGED
|
@@ -330,9 +330,16 @@ function extractActionFromExpression(node) {
|
|
|
330
330
|
}
|
|
331
331
|
if (tsBridge.isIdentifier(expr)) {
|
|
332
332
|
const funcName = expr.text;
|
|
333
|
-
if (funcName === "makeJayAction" || funcName === "makeJayQuery") {
|
|
333
|
+
if (funcName === "makeJayAction" || funcName === "makeJayQuery" || funcName === "makeJayStream") {
|
|
334
334
|
const nameArg = current.arguments[0];
|
|
335
335
|
if (nameArg && tsBridge.isStringLiteral(nameArg)) {
|
|
336
|
+
if (funcName === "makeJayStream") {
|
|
337
|
+
return {
|
|
338
|
+
actionName: nameArg.text,
|
|
339
|
+
method: "POST",
|
|
340
|
+
isStreaming: true
|
|
341
|
+
};
|
|
342
|
+
}
|
|
336
343
|
method = funcName === "makeJayQuery" ? "GET" : "POST";
|
|
337
344
|
if (explicitMethod) {
|
|
338
345
|
method = explicitMethod;
|
|
@@ -386,6 +393,7 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
386
393
|
}
|
|
387
394
|
const replacements = [];
|
|
388
395
|
let needsCreateActionCallerImport = false;
|
|
396
|
+
let needsCreateStreamCallerImport = false;
|
|
389
397
|
for (const imp of actionImports) {
|
|
390
398
|
const resolved = await resolveActionModule(imp.source, id);
|
|
391
399
|
if (!resolved) {
|
|
@@ -397,10 +405,17 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
397
405
|
for (const importName of imp.namedImports) {
|
|
398
406
|
const action = actions.find((a) => a.exportName === importName);
|
|
399
407
|
if (action) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
408
|
+
if (action.isStreaming) {
|
|
409
|
+
callerDeclarations.push(
|
|
410
|
+
`const ${importName} = createStreamCaller('${action.actionName}');`
|
|
411
|
+
);
|
|
412
|
+
needsCreateStreamCallerImport = true;
|
|
413
|
+
} else {
|
|
414
|
+
callerDeclarations.push(
|
|
415
|
+
`const ${importName} = createActionCaller('${action.actionName}', '${action.method}');`
|
|
416
|
+
);
|
|
417
|
+
needsCreateActionCallerImport = true;
|
|
418
|
+
}
|
|
404
419
|
} else {
|
|
405
420
|
getLogger().warn(
|
|
406
421
|
`[action-transform] Export '${importName}' from ${imp.source} is not a recognized action`
|
|
@@ -422,8 +437,13 @@ async function transformActionImports(code, id, resolveActionModule) {
|
|
|
422
437
|
for (const rep of replacements.sort((a, b) => b.start - a.start)) {
|
|
423
438
|
result = result.slice(0, rep.start) + rep.replacement + result.slice(rep.end);
|
|
424
439
|
}
|
|
425
|
-
|
|
426
|
-
|
|
440
|
+
const importNames = [];
|
|
441
|
+
if (needsCreateActionCallerImport)
|
|
442
|
+
importNames.push("createActionCaller");
|
|
443
|
+
if (needsCreateStreamCallerImport)
|
|
444
|
+
importNames.push("createStreamCaller");
|
|
445
|
+
if (importNames.length > 0) {
|
|
446
|
+
const importStatement = `import { ${importNames.join(", ")} } from '@jay-framework/stack-client-runtime';
|
|
427
447
|
`;
|
|
428
448
|
result = importStatement + result;
|
|
429
449
|
}
|
|
@@ -684,7 +704,7 @@ function createPluginClientImportResolver(options = {}) {
|
|
|
684
704
|
const pluginDetector = options.pluginDetector || createDefaultPluginDetector();
|
|
685
705
|
return {
|
|
686
706
|
name: "jay-stack:plugin-client-import",
|
|
687
|
-
enforce: "
|
|
707
|
+
enforce: "post",
|
|
688
708
|
configResolved(config) {
|
|
689
709
|
projectRoot = config.root || projectRoot;
|
|
690
710
|
isSSRBuild = !!config.build?.ssr;
|
|
@@ -815,14 +835,27 @@ function jayStackCompiler(options = {}) {
|
|
|
815
835
|
getLogger().warn(`[action-transform] No actions found in ${actualPath}`);
|
|
816
836
|
return null;
|
|
817
837
|
}
|
|
838
|
+
const hasRegularActions = actions.some((a) => !a.isStreaming);
|
|
839
|
+
const hasStreamActions = actions.some((a) => a.isStreaming);
|
|
840
|
+
const importNames = [];
|
|
841
|
+
if (hasRegularActions)
|
|
842
|
+
importNames.push("createActionCaller");
|
|
843
|
+
if (hasStreamActions)
|
|
844
|
+
importNames.push("createStreamCaller");
|
|
818
845
|
const lines = [
|
|
819
|
-
`import {
|
|
846
|
+
`import { ${importNames.join(", ")} } from '@jay-framework/stack-client-runtime';`,
|
|
820
847
|
""
|
|
821
848
|
];
|
|
822
849
|
for (const action of actions) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
850
|
+
if (action.isStreaming) {
|
|
851
|
+
lines.push(
|
|
852
|
+
`export const ${action.exportName} = createStreamCaller('${action.actionName}');`
|
|
853
|
+
);
|
|
854
|
+
} else {
|
|
855
|
+
lines.push(
|
|
856
|
+
`export const ${action.exportName} = createActionCaller('${action.actionName}', '${action.method}');`
|
|
857
|
+
);
|
|
858
|
+
}
|
|
826
859
|
}
|
|
827
860
|
if (code.includes("ActionError")) {
|
|
828
861
|
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.0",
|
|
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.0",
|
|
31
|
+
"@jay-framework/compiler-shared": "^0.16.0",
|
|
32
|
+
"@jay-framework/logger": "^0.16.0",
|
|
33
|
+
"@jay-framework/typescript-bridge": "^0.16.0",
|
|
34
|
+
"@jay-framework/vite-plugin": "^0.16.0",
|
|
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.0",
|
|
40
40
|
"rimraf": "^5.0.5",
|
|
41
41
|
"tsup": "^8.0.1",
|
|
42
42
|
"vitest": "^1.2.1"
|