@dreamkit/dev 0.0.10 → 0.0.12

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.
@@ -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,qBAqJtC"}
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(() => generate(server), 300);
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,CAkD5E"}
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"}
@@ -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 = [{ toSolidLink: true }];
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: string[];
4
+ spec?: string[] | Record<string, string>;
5
5
  source: string;
6
- newSource: string;
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;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,UAqCF"}
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
- traverse(ast, {
6
- ImportDeclaration(path) {
7
- const { node } = path;
8
- if (node.source.value === options.source) {
9
- node.specifiers = node.specifiers.filter((spec) => {
10
- if (spec.type === "ImportSpecifier" &&
11
- spec.imported.type === "Identifier" &&
12
- options.spec.includes(spec.imported.name)) {
13
- changes++;
14
- ast.program.body.unshift(t.importDeclaration([
15
- t.importSpecifier(t.identifier(spec.imported.name), t.identifier(spec.imported.name)),
16
- ], t.stringLiteral(options.newSource)));
17
- return false;
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
- return true;
20
- });
21
- if (changes) {
22
- if (!node.specifiers.length)
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,UAgMpD"}
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.path.node.type === "VariableDeclarator" &&
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,2 @@
1
+ export declare const toSolidServerAction: import("../utils/transform.js").Transform<unknown>;
2
+ //# sourceMappingURL=to-solid-server-action.d.ts.map
@@ -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,oDAgF9B,CAAC"}
@@ -0,0 +1,126 @@
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
+ VariableDeclaration(path) {
29
+ const [dec] = path.node.declarations;
30
+ const init = dec.init;
31
+ if (path.parent.type === "Program" &&
32
+ dec.id.type === "Identifier" &&
33
+ init?.type === "CallExpression") {
34
+ const first = getFirstChain(init);
35
+ if (clientApiLoc.includes(first?.value.object.loc)) {
36
+ changes++;
37
+ const replaced = createServerAction(programPath, dec.id.name, init, false);
38
+ const index = programPath.node.body.findIndex((node) => node === path.node);
39
+ programPath.node.body.splice(index, 1, ...replaced);
40
+ }
41
+ }
42
+ },
43
+ ExportNamedDeclaration(path) {
44
+ if (path.node.declaration) {
45
+ if (path.node.declaration.type === "VariableDeclaration") {
46
+ const [dec] = path.node.declaration.declarations;
47
+ const init = dec.init;
48
+ if (dec.id.type === "Identifier" &&
49
+ init?.type === "CallExpression") {
50
+ const first = getFirstChain(init);
51
+ if (clientApiLoc.includes(first?.value.object.loc)) {
52
+ changes++;
53
+ const replaced = createServerAction(programPath, dec.id.name, init, true);
54
+ const index = programPath.node.body.findIndex((node) => node === path.node);
55
+ programPath.node.body.splice(index, 1, ...replaced);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ });
62
+ },
63
+ });
64
+ }
65
+ return changes;
66
+ },
67
+ });
68
+ function createServerAction(program, name, call, exported = false) {
69
+ const commonApi = program.scope.generateUid(`base_${name}`);
70
+ const originalFunc = program.scope.generateUid(`original_${name}`);
71
+ const serverApi = program.scope.generateUid(`server_${name}`);
72
+ const chain = parseCallsChain(call);
73
+ const serverMethods = ["self", "create"];
74
+ return [
75
+ // const baseFetchData = $api.params({});
76
+ createConst(commonApi, createCallChains({
77
+ ...chain,
78
+ calls: chain.calls.filter(({ name }) => !serverMethods.includes(name)),
79
+ })),
80
+ t.variableDeclaration("let", [
81
+ t.variableDeclarator(t.identifier(name), t.arrowFunctionExpression([t.identifier("params")], t.blockStatement([
82
+ // const serverApi = $serverApi.clone(baseFetchData.options).self({}).create(() => {})
83
+ createConst(serverApi, createCallChains({
84
+ ...chain,
85
+ calls: [
86
+ {
87
+ name: "clone",
88
+ arguments: [
89
+ t.memberExpression(t.identifier(commonApi), t.identifier("options")),
90
+ ],
91
+ },
92
+ ...chain.calls.filter(({ name }) => serverMethods.includes(name)),
93
+ ],
94
+ })),
95
+ // return await serverApi(params);
96
+ t.returnStatement(t.awaitExpression(t.callExpression(t.identifier(serverApi), [
97
+ t.identifier("params"),
98
+ ]))),
99
+ ], [t.directive(t.directiveLiteral("use server"))]), true)),
100
+ ]),
101
+ // const originalFetchData = fetchData;
102
+ createConst(originalFunc, t.identifier(name)),
103
+ // fetchData = baseFetchData.create(originalFetchData);
104
+ t.expressionStatement(t.assignmentExpression("=", t.identifier(name), createCallChains({
105
+ rootName: commonApi,
106
+ calls: [
107
+ {
108
+ name: "clone",
109
+ arguments: [
110
+ t.objectExpression([
111
+ t.objectProperty(t.identifier("context"), t.nullLiteral()),
112
+ ]),
113
+ ],
114
+ },
115
+ {
116
+ name: "create",
117
+ arguments: [t.identifier(originalFunc)],
118
+ },
119
+ ],
120
+ }))),
121
+ exported &&
122
+ t.exportNamedDeclaration(null, [
123
+ t.exportSpecifier(t.identifier(name), t.identifier(name)),
124
+ ]),
125
+ ].filter((v) => !!v);
126
+ }
@@ -6,7 +6,17 @@ import * as lexer from "es-module-lexer";
6
6
  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
- export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
9
+ export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean | string): 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;
@@ -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,E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AAG,EAAE,CAAC,CAAC,IAAI;gBAGrB,MAAM;WACX,CAAC,CAAC,gBAAgB;cAgBhC;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,uJAQ/C;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,YAoBrD;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,qBAG3D;AACD,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAExE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,yBAI5D;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,EAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,CAAC,CAAC,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
@@ -17,11 +17,65 @@ export function parseFile(code) {
17
17
  export function tryGenerate(ast, log) {
18
18
  if (ast) {
19
19
  const generated = generator(ast);
20
- if (log)
21
- console.log(generated);
20
+ if (log) {
21
+ if (typeof log === "string") {
22
+ console.log({ id: log, ...generated });
23
+ }
24
+ else {
25
+ console.log(generated);
26
+ }
27
+ }
22
28
  return generated;
23
29
  }
24
30
  }
31
+ export function parseCallsChain(input) {
32
+ let ref = input;
33
+ let rootName;
34
+ let calls = [];
35
+ while (true) {
36
+ if (ref.callee.type === "MemberExpression") {
37
+ if (ref.callee.property.type !== "Identifier")
38
+ throw new Error("Invalid chain");
39
+ calls.push({
40
+ name: ref.callee.property.name,
41
+ arguments: ref.arguments,
42
+ });
43
+ if (ref.callee.object.type === "Identifier") {
44
+ rootName = ref.callee.object.name;
45
+ break;
46
+ }
47
+ else if (ref.callee.object.type === "CallExpression") {
48
+ ref = ref.callee.object;
49
+ }
50
+ else {
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ return { rootName, calls: calls.reverse() };
56
+ }
57
+ export function createCallChains(chain) {
58
+ let ref = t.identifier(chain.rootName);
59
+ for (const call of chain.calls) {
60
+ ref = t.callExpression(t.memberExpression(ref, t.identifier(call.name)), call.arguments);
61
+ }
62
+ return ref;
63
+ }
64
+ export function removeChainCalls(input, names) {
65
+ const root = t.cloneNode(input);
66
+ let ref = root;
67
+ while (ref.type === "CallExpression") {
68
+ ref = t.callExpression(ref.callee, ref.arguments);
69
+ if (ref.callee.type === "MemberExpression") {
70
+ if (ref.callee.property.type === "Identifier") {
71
+ if (names.includes(ref.callee.property.name))
72
+ continue;
73
+ }
74
+ ref = ref.callee.object;
75
+ }
76
+ }
77
+ return root;
78
+ }
25
79
  export function getFirstChain(ref) {
26
80
  let lastMember;
27
81
  while (ref.type === "CallExpression") {
@@ -50,7 +104,10 @@ export async function analyzeModule(path) {
50
104
  export function findExportedNames(ast) {
51
105
  return ast.program.body
52
106
  .map((stm) => {
53
- if (stm.type === "ExportNamedDeclaration" && stm.declaration) {
107
+ if (stm.type === "ExportDefaultDeclaration") {
108
+ return "default";
109
+ }
110
+ else if (stm.type === "ExportNamedDeclaration" && stm.declaration) {
54
111
  if (stm.declaration.type === "VariableDeclaration") {
55
112
  const [dec] = stm.declaration.declarations;
56
113
  if (dec.id.type === "Identifier")
@@ -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,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAA0B,eAAe,EAAE,MAAM,UAAU,CAAC;AAEnE,QAAA,MAAM,WAAW;;;;;;;CAOhB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,eAAe,CAC/C,UAAU,CACR,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,GAC1C,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAC9B,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAC/C,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,GACvB,KAAK,CACZ,CAAC,CAAC,CAAC,CACL;CACF,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,CAClC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,CAAC,KACP,MAAM,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-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.10",
3
+ "version": "0.0.12",
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.4",
49
- "@dreamkit/schema": "0.0.3"
48
+ "@dreamkit/app": "0.0.5",
49
+ "@dreamkit/schema": "0.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/debug": "^4.1.12",