@dreamkit/dev 0.0.10 → 0.0.11
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/lib/adapters/solid-start/dev-server.d.ts.map +1 -1
- package/lib/adapters/solid-start/dev-server.js +14 -2
- package/lib/plugins/dreamkit.d.ts.map +1 -1
- package/lib/plugins/dreamkit.js +6 -1
- package/lib/transforms/replace-import-spec.d.ts +3 -2
- package/lib/transforms/replace-import-spec.d.ts.map +1 -1
- package/lib/transforms/replace-import-spec.js +72 -21
- package/lib/transforms/to-solid-route.d.ts.map +1 -1
- package/lib/transforms/to-solid-route.js +2 -1
- package/lib/transforms/to-solid-server-action.d.ts +2 -0
- package/lib/transforms/to-solid-server-action.d.ts.map +1 -0
- package/lib/transforms/to-solid-server-action.js +111 -0
- package/lib/utils/ast.d.ts +10 -0
- package/lib/utils/ast.d.ts.map +1 -1
- package/lib/utils/ast.js +48 -0
- package/lib/utils/transform.d.ts +1 -0
- package/lib/utils/transform.d.ts.map +1 -1
- package/lib/utils/transform.js +2 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAKzD,OAAO,EAML,QAAQ,EAET,MAAM,sBAAsB,CAAC;AAsB9B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDhC;AAuCD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,qBAA0B,
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAKzD,OAAO,EAML,QAAQ,EAET,MAAM,sBAAsB,CAAC;AAsB9B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDhC;AAuCD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,qBAA0B,qBAiKtC"}
|
|
@@ -79,7 +79,7 @@ function addVinxiEntryRoutes(vinxiApp, objectId, objectValue, entryPath) {
|
|
|
79
79
|
filePath: entryPath,
|
|
80
80
|
};
|
|
81
81
|
if (!objectValue.$options.path) {
|
|
82
|
-
console.warn("Missing route path", { id: objectId });
|
|
82
|
+
console.warn("Missing route path at dreamkit entry", { id: objectId });
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
routes._addRoute(vinxiRoute);
|
|
@@ -128,7 +128,19 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
128
128
|
await server.stop();
|
|
129
129
|
}
|
|
130
130
|
async function onDevStart() {
|
|
131
|
-
const tryGenerate = createDelayedFunction(() =>
|
|
131
|
+
const tryGenerate = createDelayedFunction(async () => {
|
|
132
|
+
const paths = new Set();
|
|
133
|
+
server.app.routes.forEach(async (route) => {
|
|
134
|
+
const path = route.$options.path;
|
|
135
|
+
if (path) {
|
|
136
|
+
if (paths.has(path)) {
|
|
137
|
+
console.warn("Duplicated route path", { path });
|
|
138
|
+
}
|
|
139
|
+
paths.add(path);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
await generate(server);
|
|
143
|
+
}, 300);
|
|
132
144
|
server.app
|
|
133
145
|
.on("change", (data) => {
|
|
134
146
|
if (isRoute(data.value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,CAuD5E"}
|
package/lib/plugins/dreamkit.js
CHANGED
|
@@ -28,7 +28,12 @@ export function dreamkitPlugin(inOptions = {}) {
|
|
|
28
28
|
const searchParams = new URLSearchParams(searchString);
|
|
29
29
|
const dreamkitPickEntry = searchParams.get("dk-pick-entry");
|
|
30
30
|
const picks = searchParams.getAll("pick");
|
|
31
|
-
const transforms = [
|
|
31
|
+
const transforms = [
|
|
32
|
+
{
|
|
33
|
+
toSolidLink: true,
|
|
34
|
+
toSolidServerAction: true,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
32
37
|
if (dreamkitPickEntry) {
|
|
33
38
|
transforms.push({
|
|
34
39
|
pickExport: [dreamkitPickEntry],
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ParseResult } from "@babel/parser";
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
export declare function replaceImportSpec(ast: ParseResult<t.File>, options: {
|
|
4
|
-
spec
|
|
4
|
+
spec?: string[] | Record<string, string>;
|
|
5
5
|
source: string;
|
|
6
|
-
newSource
|
|
6
|
+
newSource?: string;
|
|
7
|
+
onRenameSpec?: (prev: string, next: string) => void;
|
|
7
8
|
}): number;
|
|
8
9
|
//# sourceMappingURL=replace-import-spec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EACxB,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EACxB,OAAO,EAAE;IACP,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD,UA6FF"}
|
|
@@ -2,29 +2,80 @@ import { traverse } from "../utils/babel.js";
|
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
export function replaceImportSpec(ast, options) {
|
|
4
4
|
let changes = 0;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
if (Array.isArray(options.spec) && options.newSource) {
|
|
6
|
+
const specArray = options.spec;
|
|
7
|
+
traverse(ast, {
|
|
8
|
+
ImportDeclaration(path) {
|
|
9
|
+
const { node } = path;
|
|
10
|
+
if (node.source.value === options.source) {
|
|
11
|
+
node.specifiers = node.specifiers.filter((spec) => {
|
|
12
|
+
if (spec.type === "ImportSpecifier" &&
|
|
13
|
+
spec.imported.type === "Identifier" &&
|
|
14
|
+
specArray.includes(spec.imported.name)) {
|
|
15
|
+
changes++;
|
|
16
|
+
ast.program.body.unshift(t.importDeclaration([
|
|
17
|
+
t.importSpecifier(t.identifier(spec.imported.name), t.identifier(spec.imported.name)),
|
|
18
|
+
], t.stringLiteral(options.newSource)));
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
if (changes) {
|
|
24
|
+
if (!node.specifiers.length)
|
|
25
|
+
path.remove();
|
|
18
26
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else if (options.spec) {
|
|
32
|
+
const specMap = options.spec;
|
|
33
|
+
traverse(ast, {
|
|
34
|
+
ImportDeclaration(path) {
|
|
35
|
+
const { node } = path;
|
|
36
|
+
if (node.source.value === options.source) {
|
|
37
|
+
path.traverse({
|
|
38
|
+
ImportSpecifier(spec) {
|
|
39
|
+
if (spec.node.imported.type === "Identifier") {
|
|
40
|
+
const specName = spec.node.imported.name;
|
|
41
|
+
if (specMap[specName]) {
|
|
42
|
+
const newSpecName = specMap[specName];
|
|
43
|
+
const newSpecNameAlias = spec.scope.generateUid(newSpecName);
|
|
44
|
+
options.onRenameSpec?.(specName, newSpecNameAlias);
|
|
45
|
+
changes++;
|
|
46
|
+
spec.scope.rename(specName, newSpecNameAlias);
|
|
47
|
+
spec.node.imported = t.identifier(newSpecName);
|
|
48
|
+
if (options.newSource) {
|
|
49
|
+
spec.remove();
|
|
50
|
+
ast.program.body.unshift(t.importDeclaration([
|
|
51
|
+
t.importSpecifier(t.identifier(newSpecNameAlias), t.identifier(newSpecName)),
|
|
52
|
+
], t.stringLiteral(options.newSource)));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
if (changes && !node.specifiers.length)
|
|
23
59
|
path.remove();
|
|
24
|
-
path.scope.crawl();
|
|
25
60
|
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (options.newSource) {
|
|
65
|
+
traverse(ast, {
|
|
66
|
+
ImportDeclaration(path) {
|
|
67
|
+
if (path.node.source.value === options.source) {
|
|
68
|
+
changes++;
|
|
69
|
+
path.node.source = t.stringLiteral(options.newSource);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (changes)
|
|
75
|
+
traverse(ast, {
|
|
76
|
+
Program(programPath) {
|
|
77
|
+
programPath.scope.crawl();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
29
80
|
return changes;
|
|
30
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,UAiMpD"}
|
|
@@ -37,7 +37,8 @@ export function toSolidRoute(ast) {
|
|
|
37
37
|
// export default login
|
|
38
38
|
dec.type === "Identifier") {
|
|
39
39
|
const bind = programPath.scope.bindings[dec.name];
|
|
40
|
-
if (bind
|
|
40
|
+
if (bind &&
|
|
41
|
+
bind.path.node.type === "VariableDeclarator" &&
|
|
41
42
|
bind.path.node.init) {
|
|
42
43
|
dec = bind.path.node.init;
|
|
43
44
|
path.remove();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-solid-server-action.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-server-action.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,mBAAmB,oDAwD9B,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createCallChains, createConst, defineTransform, getFirstChain, parseCallsChain, } from "../utils/ast.js";
|
|
2
|
+
import { traverse } from "../utils/babel.js";
|
|
3
|
+
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
4
|
+
import * as t from "@babel/types";
|
|
5
|
+
export const toSolidServerAction = defineTransform({
|
|
6
|
+
onlyIf: (code) => code.includes("$api") && code.includes("dreamkit"),
|
|
7
|
+
run: (ast) => {
|
|
8
|
+
let apiId;
|
|
9
|
+
let changes = replaceImportSpec(ast, {
|
|
10
|
+
spec: { $api: "$serverApi" },
|
|
11
|
+
source: "dreamkit",
|
|
12
|
+
newSource: "dreamkit/adapters/solid.js",
|
|
13
|
+
onRenameSpec(prev, next) {
|
|
14
|
+
apiId = next;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (apiId) {
|
|
18
|
+
let clientApiLoc = [];
|
|
19
|
+
traverse(ast, {
|
|
20
|
+
Program(programPath) {
|
|
21
|
+
const binds = programPath.scope.bindings[apiId];
|
|
22
|
+
programPath.traverse;
|
|
23
|
+
binds.referencePaths.forEach((path) => {
|
|
24
|
+
if (path.node.loc)
|
|
25
|
+
clientApiLoc.push(path.node.loc);
|
|
26
|
+
});
|
|
27
|
+
programPath.traverse({
|
|
28
|
+
ExportNamedDeclaration(path) {
|
|
29
|
+
if (path.node.declaration) {
|
|
30
|
+
if (path.node.declaration.type === "VariableDeclaration") {
|
|
31
|
+
const [dec] = path.node.declaration.declarations;
|
|
32
|
+
const init = dec.init;
|
|
33
|
+
if (dec.id.type === "Identifier" &&
|
|
34
|
+
init?.type === "CallExpression") {
|
|
35
|
+
const first = getFirstChain(init);
|
|
36
|
+
if (clientApiLoc.includes(first?.value.object.loc)) {
|
|
37
|
+
changes++;
|
|
38
|
+
const replaced = createServerAction(programPath, dec.id.name, init, true);
|
|
39
|
+
const index = programPath.node.body.findIndex((node) => node === path.node);
|
|
40
|
+
programPath.node.body.splice(index, 1, ...replaced);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return changes;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
function createServerAction(program, name, call, exported = false) {
|
|
54
|
+
const commonApi = program.scope.generateUid(`base_${name}`);
|
|
55
|
+
const originalFunc = program.scope.generateUid(`original_${name}`);
|
|
56
|
+
const serverApi = program.scope.generateUid(`server_${name}`);
|
|
57
|
+
const chain = parseCallsChain(call);
|
|
58
|
+
const serverMethods = ["self", "create"];
|
|
59
|
+
return [
|
|
60
|
+
// const baseFetchData = $api.params({});
|
|
61
|
+
createConst(commonApi, createCallChains({
|
|
62
|
+
...chain,
|
|
63
|
+
calls: chain.calls.filter(({ name }) => !serverMethods.includes(name)),
|
|
64
|
+
})),
|
|
65
|
+
t.variableDeclaration("let", [
|
|
66
|
+
t.variableDeclarator(t.identifier(name), t.arrowFunctionExpression([t.identifier("params")], t.blockStatement([
|
|
67
|
+
// const serverApi = $serverApi.clone(baseFetchData.options).self({}).create(() => {})
|
|
68
|
+
createConst(serverApi, createCallChains({
|
|
69
|
+
...chain,
|
|
70
|
+
calls: [
|
|
71
|
+
{
|
|
72
|
+
name: "clone",
|
|
73
|
+
arguments: [
|
|
74
|
+
t.memberExpression(t.identifier(commonApi), t.identifier("options")),
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
...chain.calls.filter(({ name }) => serverMethods.includes(name)),
|
|
78
|
+
],
|
|
79
|
+
})),
|
|
80
|
+
// return await serverApi(params);
|
|
81
|
+
t.returnStatement(t.awaitExpression(t.callExpression(t.identifier(serverApi), [
|
|
82
|
+
t.identifier("params"),
|
|
83
|
+
]))),
|
|
84
|
+
], [t.directive(t.directiveLiteral("use server"))]), true)),
|
|
85
|
+
]),
|
|
86
|
+
// const originalFetchData = fetchData;
|
|
87
|
+
createConst(originalFunc, t.identifier(name)),
|
|
88
|
+
// fetchData = baseFetchData.create(originalFetchData);
|
|
89
|
+
t.expressionStatement(t.assignmentExpression("=", t.identifier(name), createCallChains({
|
|
90
|
+
rootName: commonApi,
|
|
91
|
+
calls: [
|
|
92
|
+
{
|
|
93
|
+
name: "clone",
|
|
94
|
+
arguments: [
|
|
95
|
+
t.objectExpression([
|
|
96
|
+
t.objectProperty(t.identifier("context"), t.nullLiteral()),
|
|
97
|
+
]),
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "create",
|
|
102
|
+
arguments: [t.identifier(originalFunc)],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
}))),
|
|
106
|
+
exported &&
|
|
107
|
+
t.exportNamedDeclaration(null, [
|
|
108
|
+
t.exportSpecifier(t.identifier(name), t.identifier(name)),
|
|
109
|
+
]),
|
|
110
|
+
].filter((v) => !!v);
|
|
111
|
+
}
|
package/lib/utils/ast.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export declare function parseCode(input: string | string[]): t.Statement[];
|
|
|
7
7
|
export type ParseFileResult = ParseResult<t.File>;
|
|
8
8
|
export declare function parseFile(code: string): ParseResult<t.File>;
|
|
9
9
|
export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
|
|
10
|
+
export type Chain = {
|
|
11
|
+
rootName: string;
|
|
12
|
+
calls: {
|
|
13
|
+
name: string;
|
|
14
|
+
arguments: any[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
export declare function parseCallsChain(input: t.CallExpression): Chain;
|
|
18
|
+
export declare function createCallChains(chain: Chain): t.CallExpression | t.Identifier;
|
|
19
|
+
export declare function removeChainCalls(input: t.CallExpression, names: string[]): t.CallExpression;
|
|
10
20
|
export declare function getFirstChain(ref: t.Node): {
|
|
11
21
|
identifier: string;
|
|
12
22
|
value: t.MemberExpression;
|
package/lib/utils/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AAIzC,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,iBAIjD;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAElD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,uBAKrC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,OAAO,0DAM1E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI;gBAGrB,MAAM;WACX,CAAC,CAAC,gBAAgB;cAg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C,UAAU,EAAE,oBAiBrB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,EAC5B,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,CAAC,CAAC,UAAU,EAAO,oBAqB1B;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,CAAC,EAAE,EACf,MAAM,EAAE,MAAM,GACb;KAAG,CAAC,IAAI,CAAC,GAAG,MAAM;CAAE,CAkBtB"}
|
package/lib/utils/ast.js
CHANGED
|
@@ -22,6 +22,54 @@ export function tryGenerate(ast, log) {
|
|
|
22
22
|
return generated;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export function parseCallsChain(input) {
|
|
26
|
+
let ref = input;
|
|
27
|
+
let rootName;
|
|
28
|
+
let calls = [];
|
|
29
|
+
while (true) {
|
|
30
|
+
if (ref.callee.type === "MemberExpression") {
|
|
31
|
+
if (ref.callee.property.type !== "Identifier")
|
|
32
|
+
throw new Error("Invalid chain");
|
|
33
|
+
calls.push({
|
|
34
|
+
name: ref.callee.property.name,
|
|
35
|
+
arguments: ref.arguments,
|
|
36
|
+
});
|
|
37
|
+
if (ref.callee.object.type === "Identifier") {
|
|
38
|
+
rootName = ref.callee.object.name;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
else if (ref.callee.object.type === "CallExpression") {
|
|
42
|
+
ref = ref.callee.object;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { rootName, calls: calls.reverse() };
|
|
50
|
+
}
|
|
51
|
+
export function createCallChains(chain) {
|
|
52
|
+
let ref = t.identifier(chain.rootName);
|
|
53
|
+
for (const call of chain.calls) {
|
|
54
|
+
ref = t.callExpression(t.memberExpression(ref, t.identifier(call.name)), call.arguments);
|
|
55
|
+
}
|
|
56
|
+
return ref;
|
|
57
|
+
}
|
|
58
|
+
export function removeChainCalls(input, names) {
|
|
59
|
+
const root = t.cloneNode(input);
|
|
60
|
+
let ref = root;
|
|
61
|
+
while (ref.type === "CallExpression") {
|
|
62
|
+
ref = t.callExpression(ref.callee, ref.arguments);
|
|
63
|
+
if (ref.callee.type === "MemberExpression") {
|
|
64
|
+
if (ref.callee.property.type === "Identifier") {
|
|
65
|
+
if (names.includes(ref.callee.property.name))
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
ref = ref.callee.object;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return root;
|
|
72
|
+
}
|
|
25
73
|
export function getFirstChain(ref) {
|
|
26
74
|
let lastMember;
|
|
27
75
|
while (ref.type === "CallExpression") {
|
package/lib/utils/transform.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const $transforms: {
|
|
|
11
11
|
replaceImportSpec: typeof replaceImportSpec;
|
|
12
12
|
toSolidRoute: typeof toSolidRoute;
|
|
13
13
|
toSolidLink: Transform<unknown>;
|
|
14
|
+
toSolidServerAction: Transform<unknown>;
|
|
14
15
|
};
|
|
15
16
|
export type TransformObject = {
|
|
16
17
|
[K in keyof typeof $transforms]?: TrueIfUndefined<Parameters<(typeof $transforms)[K] extends Transform<any> ? (typeof $transforms)[K]["run"] : (typeof $transforms)[K] extends TransformRun<any> ? (typeof $transforms)[K] : never>[1]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EA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EF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,+BAuBtE;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,GAAG,KAAK,EAAE,eAAe,EAAE;;;EAI5B;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAG1D;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AAE7D,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,EACV,GAAG,UAAU,EAAE,eAAe,EAAE,UAQjC;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,EAAE,CAK9D"}
|
package/lib/utils/transform.js
CHANGED
|
@@ -4,6 +4,7 @@ import { pickExport } from "../transforms/pick-export.js";
|
|
|
4
4
|
import { replaceImportSpec } from "../transforms/replace-import-spec.js";
|
|
5
5
|
import { toSolidLink } from "../transforms/to-solid-link.js";
|
|
6
6
|
import { toSolidRoute } from "../transforms/to-solid-route.js";
|
|
7
|
+
import { toSolidServerAction } from "../transforms/to-solid-server-action.js";
|
|
7
8
|
import { tryGenerate, parseFile } from "./ast.js";
|
|
8
9
|
const $transforms = {
|
|
9
10
|
pickExport,
|
|
@@ -12,6 +13,7 @@ const $transforms = {
|
|
|
12
13
|
replaceImportSpec,
|
|
13
14
|
toSolidRoute,
|
|
14
15
|
toSolidLink,
|
|
16
|
+
toSolidServerAction,
|
|
15
17
|
};
|
|
16
18
|
export function transformCode(code, ...input) {
|
|
17
19
|
let ast;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamkit/dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Development tools for DreamKit.",
|
|
5
5
|
"homepage": "https://dreamkit.dev",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"rollup": "^4.26.0",
|
|
46
46
|
"vite-plugin-solid": "^2.10.2",
|
|
47
47
|
"vite-tsconfig-paths": "^5.1.2",
|
|
48
|
-
"@dreamkit/app": "0.0.
|
|
49
|
-
"@dreamkit/schema": "0.0.
|
|
48
|
+
"@dreamkit/app": "0.0.5",
|
|
49
|
+
"@dreamkit/schema": "0.0.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.12",
|