@hypen-space/core 0.4.37 → 0.4.39

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 (85) hide show
  1. package/README.md +13 -14
  2. package/dist/app.js +304 -227
  3. package/dist/app.js.map +5 -5
  4. package/dist/components/builtin.d.ts +17 -0
  5. package/dist/components/builtin.js +336 -256
  6. package/dist/components/builtin.js.map +6 -6
  7. package/dist/context.d.ts +11 -20
  8. package/dist/context.js +69 -101
  9. package/dist/context.js.map +3 -3
  10. package/dist/datasource.js +80 -0
  11. package/dist/datasource.js.map +10 -0
  12. package/dist/disposable.js +60 -63
  13. package/dist/disposable.js.map +2 -2
  14. package/dist/events.js +60 -63
  15. package/dist/events.js.map +2 -2
  16. package/dist/hypen.js +78 -0
  17. package/dist/hypen.js.map +10 -0
  18. package/dist/index.browser.d.ts +2 -1
  19. package/dist/index.browser.js +327 -281
  20. package/dist/index.browser.js.map +7 -8
  21. package/dist/index.d.ts +0 -3
  22. package/dist/index.js +547 -246
  23. package/dist/index.js.map +9 -9
  24. package/dist/logger.js +60 -64
  25. package/dist/logger.js.map +2 -2
  26. package/dist/remote/client.js +258 -158
  27. package/dist/remote/client.js.map +6 -6
  28. package/dist/remote/index.d.ts +6 -5
  29. package/dist/remote/index.js +255 -1985
  30. package/dist/remote/index.js.map +6 -13
  31. package/dist/remote/session.js +151 -0
  32. package/dist/remote/session.js.map +10 -0
  33. package/dist/renderer.js +60 -63
  34. package/dist/renderer.js.map +2 -2
  35. package/dist/result.js +235 -0
  36. package/dist/result.js.map +10 -0
  37. package/dist/retry.js +344 -0
  38. package/dist/retry.js.map +11 -0
  39. package/dist/router.js +62 -70
  40. package/dist/router.js.map +2 -2
  41. package/dist/state.js +3 -8
  42. package/dist/state.js.map +2 -2
  43. package/package.json +11 -56
  44. package/src/components/builtin.ts +78 -56
  45. package/src/context.ts +22 -65
  46. package/src/index.browser.ts +5 -4
  47. package/src/index.ts +10 -23
  48. package/src/remote/index.ts +9 -5
  49. package/src/result.ts +11 -0
  50. package/dist/discovery.d.ts +0 -90
  51. package/dist/discovery.js +0 -1334
  52. package/dist/discovery.js.map +0 -15
  53. package/dist/engine.browser.d.ts +0 -116
  54. package/dist/engine.browser.js +0 -479
  55. package/dist/engine.browser.js.map +0 -12
  56. package/dist/engine.d.ts +0 -107
  57. package/dist/engine.js +0 -543
  58. package/dist/engine.js.map +0 -12
  59. package/dist/loader.d.ts +0 -51
  60. package/dist/loader.js +0 -292
  61. package/dist/loader.js.map +0 -11
  62. package/dist/plugin.d.ts +0 -39
  63. package/dist/plugin.js +0 -685
  64. package/dist/plugin.js.map +0 -12
  65. package/dist/remote/server.d.ts +0 -188
  66. package/dist/remote/server.js +0 -2270
  67. package/dist/remote/server.js.map +0 -19
  68. package/src/discovery.ts +0 -527
  69. package/src/engine.browser.ts +0 -302
  70. package/src/engine.ts +0 -282
  71. package/src/loader.ts +0 -136
  72. package/src/plugin.ts +0 -220
  73. package/src/remote/server.ts +0 -879
  74. package/wasm-browser/README.md +0 -594
  75. package/wasm-browser/hypen_engine.d.ts +0 -389
  76. package/wasm-browser/hypen_engine.js +0 -1070
  77. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  78. package/wasm-browser/hypen_engine_bg.wasm.d.ts +0 -37
  79. package/wasm-browser/package.json +0 -24
  80. package/wasm-node/README.md +0 -594
  81. package/wasm-node/hypen_engine.d.ts +0 -327
  82. package/wasm-node/hypen_engine.js +0 -979
  83. package/wasm-node/hypen_engine_bg.wasm +0 -0
  84. package/wasm-node/hypen_engine_bg.wasm.d.ts +0 -37
  85. package/wasm-node/package.json +0 -22
package/src/plugin.ts DELETED
@@ -1,220 +0,0 @@
1
- /**
2
- * Enhanced Bun Plugin for Hypen
3
- *
4
- * Automatically pairs .hypen templates with their TypeScript modules.
5
- *
6
- * Usage:
7
- * import Counter from "./Counter.hypen";
8
- * // Returns: { module, template, name: "Counter" }
9
- *
10
- * Supported conventions:
11
- * 1. Sibling: Name.ts + Name.hypen
12
- * 2. Folder: Name/component.ts + Name/component.hypen
13
- * 3. Index: Name/index.ts + Name/index.hypen
14
- */
15
-
16
- import type { BunPlugin } from "bun";
17
- import { readFileSync, existsSync } from "fs";
18
- import { dirname, basename, join, resolve } from "path";
19
- import { frameworkLoggers } from "./logger.js";
20
-
21
- export interface HypenPluginOptions {
22
- /**
23
- * Enable debug logging
24
- */
25
- debug?: boolean;
26
-
27
- /**
28
- * Custom patterns for finding module files
29
- * Default: ["sibling", "component", "index"]
30
- */
31
- patterns?: ("sibling" | "component" | "index")[];
32
- }
33
-
34
- /**
35
- * Find the matching TypeScript module for a .hypen file
36
- */
37
- function findModulePath(
38
- hypenPath: string,
39
- patterns: ("sibling" | "component" | "index")[]
40
- ): string | null {
41
- const dir = dirname(hypenPath);
42
- const baseName = basename(hypenPath, ".hypen");
43
- const parentDir = dirname(dir);
44
- const folderName = basename(dir);
45
-
46
- for (const pattern of patterns) {
47
- let candidatePath: string | null = null;
48
-
49
- switch (pattern) {
50
- case "sibling":
51
- // Name.hypen -> Name.ts (same directory)
52
- candidatePath = join(dir, `${baseName}.ts`);
53
- break;
54
-
55
- case "component":
56
- // Name/component.hypen -> Name/component.ts
57
- if (baseName === "component") {
58
- candidatePath = join(dir, "component.ts");
59
- }
60
- break;
61
-
62
- case "index":
63
- // Name/index.hypen -> Name/index.ts
64
- if (baseName === "index") {
65
- candidatePath = join(dir, "index.ts");
66
- }
67
- break;
68
- }
69
-
70
- if (candidatePath && existsSync(candidatePath)) {
71
- return candidatePath;
72
- }
73
- }
74
-
75
- return null;
76
- }
77
-
78
- /**
79
- * Determine the component name from the file path
80
- */
81
- function getComponentName(hypenPath: string): string {
82
- const baseName = basename(hypenPath, ".hypen");
83
-
84
- // If file is component.hypen or index.hypen, use parent folder name
85
- if (baseName === "component" || baseName === "index") {
86
- return basename(dirname(hypenPath));
87
- }
88
-
89
- // Otherwise use the file name
90
- return baseName;
91
- }
92
-
93
- /**
94
- * Parse import statements from Hypen DSL (for future use)
95
- */
96
- function parseImports(
97
- text: string
98
- ): Array<{ names: string[]; source: string }> {
99
- const imports: Array<{ names: string[]; source: string }> = [];
100
- const importRegex =
101
- /import\s+(?:\{([^}]+)\}|(\w+))\s+from\s+["']([^"']+)["']/g;
102
-
103
- let match;
104
- while ((match = importRegex.exec(text)) !== null) {
105
- const [, namedImports, defaultImport, source] = match;
106
-
107
- if (!source) continue;
108
-
109
- let names: string[];
110
- if (namedImports) {
111
- names = namedImports
112
- .split(",")
113
- .map((n) => n.trim())
114
- .filter((n) => n.length > 0);
115
- } else if (defaultImport) {
116
- names = [defaultImport];
117
- } else {
118
- continue;
119
- }
120
-
121
- imports.push({ names, source });
122
- }
123
-
124
- return imports;
125
- }
126
-
127
- /**
128
- * Remove import statements from Hypen template
129
- */
130
- function removeImports(text: string): string {
131
- return text.replace(
132
- /import\s+(?:\{[^}]+\}|\w+)\s+from\s+["'][^"']+["']\s*/g,
133
- ""
134
- );
135
- }
136
-
137
- /**
138
- * Create the enhanced Hypen plugin for Bun
139
- */
140
- export function hypenPlugin(options: HypenPluginOptions = {}): BunPlugin {
141
- const { debug = false, patterns = ["sibling", "component", "index"] } =
142
- options;
143
-
144
- const log = debug
145
- ? (...args: unknown[]) => frameworkLoggers.plugin.debug(...args)
146
- : () => {};
147
-
148
- return {
149
- name: "hypen-loader",
150
- async setup(build) {
151
- build.onLoad({ filter: /\.hypen$/ }, async (args) => {
152
- const hypenPath = resolve(args.path);
153
- log("Loading:", hypenPath);
154
-
155
- // Read the template
156
- const templateRaw = readFileSync(hypenPath, "utf-8");
157
-
158
- // Parse and remove imports
159
- const imports = parseImports(templateRaw);
160
- const template = removeImports(templateRaw).trim();
161
-
162
- if (imports.length > 0) {
163
- log("Found imports:", imports);
164
- }
165
-
166
- // Get component name
167
- const componentName = getComponentName(hypenPath);
168
- log("Component name:", componentName);
169
-
170
- // Find matching module
171
- const modulePath = findModulePath(hypenPath, patterns);
172
- log("Module path:", modulePath);
173
-
174
- let contents: string;
175
-
176
- if (modulePath) {
177
- // Has a TypeScript module - import it
178
- const relativeModulePath = modulePath.replace(/\.ts$/, ".js");
179
- contents = `
180
- import _module from "${relativeModulePath}";
181
- export const module = _module;
182
- export const template = ${JSON.stringify(template)};
183
- export const name = ${JSON.stringify(componentName)};
184
- export default { module: _module, template: ${JSON.stringify(template)}, name: ${JSON.stringify(componentName)} };
185
- `;
186
- } else {
187
- // No TypeScript module - create stateless component
188
- log("No module found, creating stateless component");
189
- contents = `
190
- import { app } from "@hypen-space/core";
191
- const _module = app.defineState({}).build();
192
- export const module = _module;
193
- export const template = ${JSON.stringify(template)};
194
- export const name = ${JSON.stringify(componentName)};
195
- export default { module: _module, template: ${JSON.stringify(template)}, name: ${JSON.stringify(componentName)} };
196
- `;
197
- }
198
-
199
- return {
200
- contents,
201
- loader: "js",
202
- };
203
- });
204
- },
205
- };
206
- }
207
-
208
- /**
209
- * Default plugin instance with standard options
210
- */
211
- export const defaultHypenPlugin = hypenPlugin();
212
-
213
- /**
214
- * Register the plugin globally (call this in your preload file)
215
- */
216
- export function registerHypenPlugin(options?: HypenPluginOptions): void {
217
- Bun.plugin(hypenPlugin(options));
218
- }
219
-
220
- export default hypenPlugin;