@kithinji/pod 1.0.21 → 1.0.22

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.
Files changed (39) hide show
  1. package/README.md +439 -0
  2. package/dist/main.js +5 -5
  3. package/dist/main.js.map +2 -2
  4. package/package.json +31 -8
  5. package/build.js +0 -22
  6. package/src/add/component/component.ts +0 -496
  7. package/src/add/component/index.ts +0 -1
  8. package/src/add/index.ts +0 -3
  9. package/src/add/module/index.ts +0 -1
  10. package/src/add/module/module.ts +0 -545
  11. package/src/add/new/index.ts +0 -198
  12. package/src/config/config.ts +0 -141
  13. package/src/config/index.ts +0 -1
  14. package/src/deploy/deploy.ts +0 -592
  15. package/src/deploy/index.ts +0 -1
  16. package/src/dev/index.ts +0 -1
  17. package/src/dev/project.ts +0 -45
  18. package/src/dev/server.ts +0 -191
  19. package/src/docker/docker.ts +0 -697
  20. package/src/docker/index.ts +0 -1
  21. package/src/macros/expand_macros.ts +0 -791
  22. package/src/macros/index.ts +0 -2
  23. package/src/macros/macro_executer.ts +0 -189
  24. package/src/main.ts +0 -106
  25. package/src/plugins/analyzers/graph.ts +0 -279
  26. package/src/plugins/css/index.ts +0 -25
  27. package/src/plugins/generators/generate_controller.ts +0 -308
  28. package/src/plugins/generators/generate_rsc.ts +0 -274
  29. package/src/plugins/generators/generate_server_component.ts +0 -455
  30. package/src/plugins/generators/tsx_server_stub.ts +0 -315
  31. package/src/plugins/index.ts +0 -3
  32. package/src/plugins/my.ts +0 -282
  33. package/src/plugins/transformers/j2d.ts +0 -1080
  34. package/src/store/index.ts +0 -1
  35. package/src/store/store.ts +0 -44
  36. package/src/utils/cases.ts +0 -15
  37. package/src/utils/create.ts +0 -26
  38. package/src/utils/index.ts +0 -2
  39. package/tsconfig.json +0 -27
@@ -1,455 +0,0 @@
1
- import { parseSync, printSync } from "@swc/core";
2
- import type {
3
- ClassDeclaration,
4
- Decorator,
5
- ImportDeclaration,
6
- ModuleItem,
7
- } from "@swc/core";
8
-
9
- interface MethodParam {
10
- name: string;
11
- type: string;
12
- }
13
-
14
- interface ComponentMethod {
15
- name: string;
16
- params: MethodParam[];
17
- returnType: string;
18
- isAsync: boolean;
19
- }
20
-
21
- interface ClassStub {
22
- name: string;
23
- propsType: string;
24
- decorators: string[];
25
- constructorParams: string[];
26
- methods: ComponentMethod[];
27
- }
28
-
29
- interface ImportMap {
30
- [localName: string]: string;
31
- }
32
-
33
- export function generateServerComponent(
34
- filePath: string,
35
- code: string
36
- ): string {
37
- const ast = parseSync(code, {
38
- syntax: "typescript",
39
- tsx: filePath.endsWith("x"),
40
- decorators: true,
41
- });
42
-
43
- const importMap: ImportMap = {};
44
- for (const item of ast.body) {
45
- if (item.type === "ImportDeclaration") {
46
- const decl = item as ImportDeclaration;
47
- for (const specifier of decl.specifiers ?? []) {
48
- let localName: string;
49
- if (specifier.type === "ImportSpecifier") {
50
- localName = specifier.local.value;
51
- } else if (specifier.type === "ImportDefaultSpecifier") {
52
- localName = specifier.local.value;
53
- } else {
54
- continue;
55
- }
56
- importMap[localName] = decl.source.value;
57
- }
58
- }
59
- }
60
-
61
- const preservedNodes: ModuleItem[] = [];
62
- const stubbedClasses: ClassStub[] = [];
63
-
64
- for (const item of ast.body) {
65
- let shouldStub = false;
66
-
67
- if (
68
- item.type === "ExportDeclaration" &&
69
- item.declaration?.type === "ClassDeclaration"
70
- ) {
71
- const classDecl = item.declaration as ClassDeclaration;
72
-
73
- if (hasComponentDecorator(classDecl.decorators)) {
74
- shouldStub = true;
75
- const stub = extractClassStub(classDecl);
76
- if (stub) {
77
- stubbedClasses.push(stub);
78
- }
79
- }
80
- }
81
-
82
- if (!shouldStub) {
83
- preservedNodes.push(item);
84
- }
85
- }
86
-
87
- const preservedCode =
88
- preservedNodes.length > 0
89
- ? printSync({
90
- type: "Module",
91
- span: ast.span,
92
- body: preservedNodes,
93
- interpreter: ast.interpreter,
94
- }).code
95
- : "";
96
-
97
- const stubCode = stubbedClasses
98
- .map((stub) => generateStubCode(stub))
99
- .join("\n\n");
100
-
101
- return `
102
- ${preservedCode}
103
- ${stubCode}
104
- `.trim();
105
- }
106
-
107
- function hasComponentDecorator(decorators?: Decorator[]): boolean {
108
- if (!decorators) return false;
109
-
110
- return decorators.some((decorator) => {
111
- const expr = decorator.expression;
112
-
113
- if (expr.type === "CallExpression") {
114
- if (
115
- expr.callee.type === "Identifier" &&
116
- expr.callee.value === "Component"
117
- ) {
118
- return true;
119
- }
120
- }
121
-
122
- if (expr.type === "Identifier" && expr.value === "Component") {
123
- return true;
124
- }
125
-
126
- return false;
127
- });
128
- }
129
-
130
- function extractClassStub(classDecl: ClassDeclaration): ClassStub | null {
131
- const className = classDecl.identifier?.value;
132
- if (!className) return null;
133
-
134
- let propsType = "{}";
135
- const decorators: string[] = [];
136
- const constructorParams: string[] = [];
137
-
138
- if (classDecl.decorators) {
139
- for (const dec of classDecl.decorators) {
140
- const str = stringifyDecorator(dec);
141
- if (str) decorators.push(str);
142
- }
143
- }
144
-
145
- for (const member of classDecl.body) {
146
- if (member.type === "ClassProperty") {
147
- if (member.key.type === "Identifier" && member.key.value === "props") {
148
- propsType = extractPropsType(member);
149
- }
150
- } else if (member.type === "Constructor") {
151
- for (const param of member.params) {
152
- const paramStr = stringifyParam(param);
153
- if (paramStr) constructorParams.push(paramStr);
154
- }
155
- }
156
- }
157
-
158
- const methods = extractMethods(classDecl);
159
-
160
- return {
161
- name: className,
162
- propsType,
163
- decorators,
164
- constructorParams,
165
- methods,
166
- };
167
- }
168
-
169
- export function stringifyDecorator(decorator: Decorator): string {
170
- const exprCode = printSync({
171
- type: "Module",
172
- span: { start: 0, end: 0, ctxt: 0 },
173
- body: [
174
- {
175
- type: "ExpressionStatement",
176
- expression: decorator.expression,
177
- span: { start: 0, end: 0, ctxt: 0 },
178
- },
179
- ],
180
- interpreter: "",
181
- }).code;
182
-
183
- const cleanCode = exprCode.replace(/^#!.*\n/, "").trim();
184
-
185
- return `@${cleanCode.replace(/;$/, "")}`;
186
- }
187
-
188
- function extractPropsType(member: any): string {
189
- const typeAnn = member.typeAnnotation?.typeAnnotation;
190
- if (!typeAnn) return "{}";
191
-
192
- if (typeAnn.type === "TsTypeLiteral") {
193
- const props: string[] = [];
194
- for (const m of typeAnn.members) {
195
- if (m.type === "TsPropertySignature") {
196
- const key = m.key.type === "Identifier" ? m.key.value : "?";
197
- const t = m.typeAnnotation
198
- ? stringifyType(m.typeAnnotation.typeAnnotation)
199
- : "any";
200
- props.push(`${key}: ${t}`);
201
- }
202
- }
203
- return `{ ${props.join("; ")} }`;
204
- }
205
-
206
- return stringifyType(typeAnn);
207
- }
208
-
209
- function stringifyParam(param: any): string {
210
- let decorators: string[] = [];
211
- if (param.decorators) {
212
- for (const d of param.decorators) {
213
- const str = stringifyDecorator(d);
214
- if (str) decorators.push(str);
215
- }
216
- }
217
- const decoratorPrefix = decorators.length ? decorators.join(" ") + " " : "";
218
-
219
- let typeName = "any";
220
- let paramName = "";
221
- let accessibility = "";
222
-
223
- if (param.type === "TsParameterProperty") {
224
- accessibility = param.accessibility || "";
225
- const inner = param.param;
226
- if (inner.type !== "Identifier") return "";
227
-
228
- paramName = inner.value;
229
- if (inner.typeAnnotation?.typeAnnotation) {
230
- typeName = extractTypeName(inner.typeAnnotation.typeAnnotation);
231
- }
232
- } else if (param.type === "Parameter") {
233
- const pat = param.pat;
234
- if (pat.type !== "Identifier") return "";
235
-
236
- paramName = pat.value;
237
- if (pat.typeAnnotation?.typeAnnotation) {
238
- typeName = extractTypeName(pat.typeAnnotation.typeAnnotation);
239
- }
240
- } else {
241
- return "";
242
- }
243
-
244
- const accessPrefix = accessibility ? `${accessibility} ` : "";
245
- const result = `${decoratorPrefix}${accessPrefix}${paramName}: ${typeName}`;
246
-
247
- return result;
248
- }
249
-
250
- function extractTypeName(typeNode: any): string {
251
- if (
252
- typeNode.type === "TsTypeReference" &&
253
- typeNode.typeName.type === "Identifier"
254
- ) {
255
- return typeNode.typeName.value;
256
- }
257
- return stringifyType(typeNode);
258
- }
259
-
260
- function extractMethods(classDecl: ClassDeclaration): ComponentMethod[] {
261
- const methods: ComponentMethod[] = [];
262
-
263
- for (const member of classDecl.body) {
264
- if (member.type === "ClassMethod") {
265
- const method = member as any;
266
-
267
- const methodName =
268
- method.key.type === "Identifier" ? method.key.value : "";
269
-
270
- if (!methodName) {
271
- continue;
272
- }
273
-
274
- const params = extractMethodParams(method.function.params || []);
275
- const returnType = extractReturnType(method.function.returnType);
276
- const isAsync = method.function.async || false;
277
-
278
- methods.push({
279
- name: methodName,
280
- params,
281
- returnType,
282
- isAsync,
283
- });
284
- }
285
- }
286
-
287
- return methods;
288
- }
289
-
290
- function extractMethodParams(params: any[]): MethodParam[] {
291
- const result: MethodParam[] = [];
292
-
293
- for (const param of params) {
294
- if (param.type === "Parameter") {
295
- const pat = param.pat as any;
296
-
297
- if (pat.type === "Identifier") {
298
- const name = pat.value;
299
- const type = pat.typeAnnotation?.typeAnnotation
300
- ? stringifyType(pat.typeAnnotation.typeAnnotation)
301
- : "any";
302
-
303
- result.push({
304
- name,
305
- type,
306
- });
307
- }
308
- }
309
- }
310
-
311
- return result;
312
- }
313
-
314
- function extractReturnType(returnType?: any): string {
315
- if (!returnType || !returnType.typeAnnotation) {
316
- return "any";
317
- }
318
-
319
- const type = returnType.typeAnnotation;
320
-
321
- if (type.type === "TsTypeReference") {
322
- const typeName = type.typeName;
323
- if (typeName.type === "Identifier" && typeName.value === "Promise") {
324
- if (type.typeParams && type.typeParams.params.length > 0) {
325
- return stringifyType(type.typeParams.params[0]);
326
- }
327
- }
328
- }
329
-
330
- return stringifyType(type);
331
- }
332
-
333
- function stringifyType(typeNode: any): string {
334
- if (!typeNode) return "any";
335
-
336
- switch (typeNode.type) {
337
- case "TsKeywordType":
338
- return typeNode.kind;
339
-
340
- case "TsTypeReference":
341
- if (typeNode.typeName.type === "Identifier") {
342
- const baseName = typeNode.typeName.value;
343
- if (typeNode.typeParams && typeNode.typeParams.params.length > 0) {
344
- const params = typeNode.typeParams.params
345
- .map(stringifyType)
346
- .join(", ");
347
- return `${baseName}<${params}>`;
348
- }
349
- return baseName;
350
- }
351
- return "any";
352
-
353
- case "TsArrayType":
354
- return `${stringifyType(typeNode.elemType)}[]`;
355
-
356
- case "TsUnionType":
357
- return typeNode.types.map(stringifyType).join(" | ");
358
-
359
- case "TsIntersectionType":
360
- return typeNode.types.map(stringifyType).join(" & ");
361
-
362
- case "TsTypeLiteral":
363
- const props = typeNode.members
364
- .map((member: any) => {
365
- if (member.type === "TsPropertySignature") {
366
- const key =
367
- member.key.type === "Identifier" ? member.key.value : "";
368
- const type = member.typeAnnotation
369
- ? stringifyType(member.typeAnnotation.typeAnnotation)
370
- : "any";
371
- return `${key}: ${type}`;
372
- }
373
- return "";
374
- })
375
- .filter(Boolean);
376
- return `{ ${props.join("; ")} }`;
377
-
378
- default:
379
- return "any";
380
- }
381
- }
382
-
383
- function generateStubCode(stub: ClassStub): string {
384
- const className = stub.name;
385
-
386
- const build = stub.methods.find((p) => p.name == "build");
387
-
388
- if (build == undefined) {
389
- throw new Error("Component has no build function");
390
- }
391
-
392
- const decoratorsStr =
393
- stub.decorators.length > 0 ? stub.decorators.join("\n") + "\n" : "";
394
-
395
- return `import {
396
- Inject as _Inject,
397
- getCurrentInjector as _getCurrentInjector,
398
- OrcaComponent as _OrcaComponent,
399
- JSX as _JSX,
400
- OSC as _OSC,
401
- HttpClient as _HttpClient,
402
- symbolValueReviver as _symbolValueReviver
403
- } from "@kithinji/orca";
404
-
405
-
406
- ${decoratorsStr}export class ${className} extends _OrcaComponent {
407
- props!: any;
408
-
409
- constructor(
410
- @_Inject("OSC_URL", { maybe: true }) private oscUrl?: string,
411
- private readonly http: _HttpClient,
412
- ${stub.constructorParams.join(", ")}
413
- ) {
414
- super();
415
-
416
- if(this.oscUrl === undefined) {
417
- throw new Error("Server component requires osc url be defined");
418
- }
419
- }
420
-
421
- build() {
422
- const root = document.createElement("div");
423
- root.textContent = "loading...";
424
-
425
- const injector = _getCurrentInjector();
426
-
427
- if(injector == null) {
428
- throw new Error("Injector is null");
429
- }
430
-
431
- const osc = new _OSC(root);
432
-
433
- const subscription = this.http.post<_JSX.Element>(
434
- \`\${this.oscUrl}?c=${className}\`, {
435
- body: this.props,
436
- reviver: _symbolValueReviver,
437
- }
438
- ).subscribe((jsx: _JSX.Element) => {
439
- const action = jsx.action || "insert";
440
-
441
- if (action === "insert") {
442
- osc.handleInsert(jsx);
443
- } else if (action === "update") {
444
- osc.handleUpdate(jsx);
445
- } else {
446
- console.warn(\`Unknown action: \${action}\`);
447
- }
448
- });
449
-
450
- this.pushDrop(() => subscription.unsubscribe());
451
-
452
- return root;
453
- }
454
- }`;
455
- }