@hypen-space/core 0.4.36 → 0.4.38

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 (80) hide show
  1. package/README.md +13 -14
  2. package/dist/app.js +289 -227
  3. package/dist/app.js.map +5 -5
  4. package/dist/components/builtin.js +289 -227
  5. package/dist/components/builtin.js.map +5 -5
  6. package/dist/context.js +60 -64
  7. package/dist/context.js.map +2 -2
  8. package/dist/datasource.js +80 -0
  9. package/dist/datasource.js.map +10 -0
  10. package/dist/disposable.js +60 -63
  11. package/dist/disposable.js.map +2 -2
  12. package/dist/events.js +60 -63
  13. package/dist/events.js.map +2 -2
  14. package/dist/hypen.js +78 -0
  15. package/dist/hypen.js.map +10 -0
  16. package/dist/index.browser.d.ts +2 -1
  17. package/dist/index.browser.js +303 -244
  18. package/dist/index.browser.js.map +6 -7
  19. package/dist/index.d.ts +0 -3
  20. package/dist/index.js +492 -180
  21. package/dist/index.js.map +6 -6
  22. package/dist/logger.js +60 -64
  23. package/dist/logger.js.map +2 -2
  24. package/dist/remote/client.js +243 -158
  25. package/dist/remote/client.js.map +6 -6
  26. package/dist/remote/index.d.ts +6 -5
  27. package/dist/remote/index.js +241 -1986
  28. package/dist/remote/index.js.map +6 -13
  29. package/dist/remote/session.js +151 -0
  30. package/dist/remote/session.js.map +10 -0
  31. package/dist/renderer.js +60 -63
  32. package/dist/renderer.js.map +2 -2
  33. package/dist/result.js +220 -0
  34. package/dist/result.js.map +10 -0
  35. package/dist/retry.js +329 -0
  36. package/dist/retry.js.map +11 -0
  37. package/dist/router.js +62 -70
  38. package/dist/router.js.map +2 -2
  39. package/dist/state.js +3 -8
  40. package/dist/state.js.map +2 -2
  41. package/package.json +11 -56
  42. package/src/index.browser.ts +5 -4
  43. package/src/index.ts +10 -23
  44. package/src/remote/index.ts +9 -5
  45. package/dist/discovery.d.ts +0 -90
  46. package/dist/discovery.js +0 -1334
  47. package/dist/discovery.js.map +0 -15
  48. package/dist/engine.browser.d.ts +0 -116
  49. package/dist/engine.browser.js +0 -479
  50. package/dist/engine.browser.js.map +0 -12
  51. package/dist/engine.d.ts +0 -107
  52. package/dist/engine.js +0 -543
  53. package/dist/engine.js.map +0 -12
  54. package/dist/loader.d.ts +0 -51
  55. package/dist/loader.js +0 -292
  56. package/dist/loader.js.map +0 -11
  57. package/dist/plugin.d.ts +0 -39
  58. package/dist/plugin.js +0 -685
  59. package/dist/plugin.js.map +0 -12
  60. package/dist/remote/server.d.ts +0 -188
  61. package/dist/remote/server.js +0 -2270
  62. package/dist/remote/server.js.map +0 -19
  63. package/src/discovery.ts +0 -527
  64. package/src/engine.browser.ts +0 -302
  65. package/src/engine.ts +0 -282
  66. package/src/loader.ts +0 -136
  67. package/src/plugin.ts +0 -220
  68. package/src/remote/server.ts +0 -879
  69. package/wasm-browser/README.md +0 -594
  70. package/wasm-browser/hypen_engine.d.ts +0 -389
  71. package/wasm-browser/hypen_engine.js +0 -1070
  72. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  73. package/wasm-browser/hypen_engine_bg.wasm.d.ts +0 -37
  74. package/wasm-browser/package.json +0 -24
  75. package/wasm-node/README.md +0 -594
  76. package/wasm-node/hypen_engine.d.ts +0 -327
  77. package/wasm-node/hypen_engine.js +0 -979
  78. package/wasm-node/hypen_engine_bg.wasm +0 -0
  79. package/wasm-node/hypen_engine_bg.wasm.d.ts +0 -37
  80. 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;