@bubblelab/bubble-runtime 0.1.0

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 (70) hide show
  1. package/LICENSE.txt +202 -0
  2. package/dist/extraction/BubbleParser.d.ts +80 -0
  3. package/dist/extraction/BubbleParser.d.ts.map +1 -0
  4. package/dist/extraction/BubbleParser.js +926 -0
  5. package/dist/extraction/BubbleParser.js.map +1 -0
  6. package/dist/extraction/index.d.ts +2 -0
  7. package/dist/extraction/index.d.ts.map +1 -0
  8. package/dist/extraction/index.js +4 -0
  9. package/dist/extraction/index.js.map +1 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +8 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/injection/BubbleInjector.d.ts +71 -0
  15. package/dist/injection/BubbleInjector.d.ts.map +1 -0
  16. package/dist/injection/BubbleInjector.js +326 -0
  17. package/dist/injection/BubbleInjector.js.map +1 -0
  18. package/dist/injection/LoggerInjector.d.ts +33 -0
  19. package/dist/injection/LoggerInjector.d.ts.map +1 -0
  20. package/dist/injection/LoggerInjector.js +154 -0
  21. package/dist/injection/LoggerInjector.js.map +1 -0
  22. package/dist/injection/index.d.ts +3 -0
  23. package/dist/injection/index.d.ts.map +1 -0
  24. package/dist/injection/index.js +3 -0
  25. package/dist/injection/index.js.map +1 -0
  26. package/dist/parse/BubbleScript.d.ts +141 -0
  27. package/dist/parse/BubbleScript.d.ts.map +1 -0
  28. package/dist/parse/BubbleScript.js +513 -0
  29. package/dist/parse/BubbleScript.js.map +1 -0
  30. package/dist/parse/index.d.ts +3 -0
  31. package/dist/parse/index.d.ts.map +1 -0
  32. package/dist/parse/index.js +3 -0
  33. package/dist/parse/index.js.map +1 -0
  34. package/dist/parse/traceDependencies.d.ts +18 -0
  35. package/dist/parse/traceDependencies.d.ts.map +1 -0
  36. package/dist/parse/traceDependencies.js +181 -0
  37. package/dist/parse/traceDependencies.js.map +1 -0
  38. package/dist/runtime/BubbleRunner.d.ts +91 -0
  39. package/dist/runtime/BubbleRunner.d.ts.map +1 -0
  40. package/dist/runtime/BubbleRunner.js +586 -0
  41. package/dist/runtime/BubbleRunner.js.map +1 -0
  42. package/dist/runtime/index.d.ts +2 -0
  43. package/dist/runtime/index.d.ts.map +1 -0
  44. package/dist/runtime/index.js +2 -0
  45. package/dist/runtime/index.js.map +1 -0
  46. package/dist/runtime/types.d.ts +29 -0
  47. package/dist/runtime/types.d.ts.map +1 -0
  48. package/dist/runtime/types.js +2 -0
  49. package/dist/runtime/types.js.map +1 -0
  50. package/dist/types/index.d.ts +8 -0
  51. package/dist/types/index.d.ts.map +1 -0
  52. package/dist/types/index.js +2 -0
  53. package/dist/types/index.js.map +1 -0
  54. package/dist/utils/bubble-helper.d.ts +11 -0
  55. package/dist/utils/bubble-helper.d.ts.map +1 -0
  56. package/dist/utils/bubble-helper.js +15 -0
  57. package/dist/utils/bubble-helper.js.map +1 -0
  58. package/dist/utils/parameter-formatter.d.ts +22 -0
  59. package/dist/utils/parameter-formatter.d.ts.map +1 -0
  60. package/dist/utils/parameter-formatter.js +219 -0
  61. package/dist/utils/parameter-formatter.js.map +1 -0
  62. package/dist/validation/BubbleValidator.d.ts +43 -0
  63. package/dist/validation/BubbleValidator.d.ts.map +1 -0
  64. package/dist/validation/BubbleValidator.js +172 -0
  65. package/dist/validation/BubbleValidator.js.map +1 -0
  66. package/dist/validation/index.d.ts +27 -0
  67. package/dist/validation/index.d.ts.map +1 -0
  68. package/dist/validation/index.js +126 -0
  69. package/dist/validation/index.js.map +1 -0
  70. package/package.json +47 -0
@@ -0,0 +1,126 @@
1
+ import { validateScript } from './BubbleValidator.js';
2
+ import { BubbleScript } from '../parse/BubbleScript.js';
3
+ /**
4
+ * Validates a BubbleFlow TypeScript code
5
+ * This focuses purely on validation without extraction
6
+ *
7
+ * @param code - The TypeScript code to validate
8
+ * @returns ValidationResult with success status and errors
9
+ */
10
+ export async function validateBubbleFlow(code) {
11
+ const errors = [];
12
+ try {
13
+ // Step 1: Basic syntax and structure validation
14
+ const validationResult = validateScript(code);
15
+ if (!validationResult.success) {
16
+ errors.push(...Object.values(validationResult.errors || {}));
17
+ }
18
+ // Step 2: Validate BubbleFlow class requirements
19
+ const structuralErrors = validateBubbleFlowStructure(code);
20
+ errors.push(...structuralErrors);
21
+ // Step 3: Validate bubble usage (only registered bubbles)
22
+ const bubbleErrors = validateBubbleUsage(code);
23
+ errors.push(...bubbleErrors);
24
+ return {
25
+ valid: errors.length === 0,
26
+ errors: errors.length > 0 ? errors : undefined,
27
+ };
28
+ }
29
+ catch (error) {
30
+ const errorMessage = error instanceof Error ? error.message : 'Unknown validation error';
31
+ return {
32
+ valid: false,
33
+ errors: [errorMessage],
34
+ };
35
+ }
36
+ }
37
+ /**
38
+ * Validates a BubbleFlow TypeScript code and extracts bubble parameters
39
+ * This is the main entry point for bubble runtime validation with extraction
40
+ *
41
+ * @param code - The TypeScript code to validate
42
+ * @returns ValidationAndExtractionResult with success status, errors, and extracted parameters
43
+ */
44
+ export async function validateAndExtract(code, bubbleFactory) {
45
+ // First validate the code
46
+ const validationResult = await validateBubbleFlow(code);
47
+ // If validation fails, return early
48
+ if (!validationResult.valid) {
49
+ return validationResult;
50
+ }
51
+ // If validation passes, extract bubble parameters
52
+ try {
53
+ const script = new BubbleScript(code, bubbleFactory);
54
+ return {
55
+ ...validationResult,
56
+ bubbleParameters: script.getParsedBubbles(),
57
+ inputSchema: script.getPayloadJsonSchema() || {},
58
+ };
59
+ }
60
+ catch (error) {
61
+ const errorMessage = error instanceof Error ? error.message : 'Extraction failed';
62
+ return {
63
+ valid: false,
64
+ errors: [errorMessage],
65
+ };
66
+ }
67
+ }
68
+ /**
69
+ * Validates BubbleFlow class structure requirements
70
+ */
71
+ function validateBubbleFlowStructure(code) {
72
+ const errors = [];
73
+ // Check for BubbleFlow import
74
+ if (!code.includes("from '@bubblelab/bubble-core'") &&
75
+ !code.includes('from "@bubblelab/bubble-core"')) {
76
+ errors.push('Missing BubbleFlow import from @bubblelab/bubble-core');
77
+ }
78
+ // Check for class that extends BubbleFlow
79
+ const bubbleFlowClassRegex = /class\s+(\w+)\s+extends\s+BubbleFlow/;
80
+ const bubbleFlowMatch = bubbleFlowClassRegex.exec(code);
81
+ if (!bubbleFlowMatch) {
82
+ errors.push('Code must contain a class that extends BubbleFlow');
83
+ return errors;
84
+ }
85
+ const className = bubbleFlowMatch[1];
86
+ // Check for handle method in the BubbleFlow class
87
+ const handleMethodRegex = new RegExp(`class\\s+${className}\\s+extends\\s+BubbleFlow[\\s\\S]*?async\\s+handle\\s*\\(`, 's');
88
+ if (!handleMethodRegex.test(code)) {
89
+ // Align with test that looks for abstract member implementation errors
90
+ errors.push('does not implement inherited abstract member');
91
+ }
92
+ // Check for export
93
+ if (!code.includes(`export class ${className}`)) {
94
+ errors.push(`Class ${className} must be exported`);
95
+ }
96
+ return errors;
97
+ }
98
+ /**
99
+ * Validates that only registered bubbles are used
100
+ */
101
+ function validateBubbleUsage(code) {
102
+ const errors = [];
103
+ // Extract imported bubble types
104
+ const importRegex = /import\s*{([^}]+)}\s*from\s*['"]@nodex\/bubble-core['"]/;
105
+ const importMatch = importRegex.exec(code);
106
+ if (!importMatch) {
107
+ return errors; // No bubble imports found, which is fine
108
+ }
109
+ const importedBubbles = importMatch[1]
110
+ .split(',')
111
+ .map((item) => item.trim())
112
+ .filter((item) => item.endsWith('Bubble'))
113
+ .map((item) => item.replace(/\s+as\s+\w+/, '')) // Remove aliases
114
+ .filter((item) => item !== 'BubbleFlow');
115
+ // Find all bubble instantiations
116
+ const bubbleInstantiationRegex = /new\s+(\w+Bubble)\s*\(/g;
117
+ let match;
118
+ while ((match = bubbleInstantiationRegex.exec(code)) !== null) {
119
+ const bubbleClass = match[1];
120
+ if (!importedBubbles.includes(bubbleClass)) {
121
+ errors.push(`Unregistered bubble class: ${bubbleClass}. All bubble classes must be imported from @bubblelab/bubble-core`);
122
+ }
123
+ }
124
+ return errors;
125
+ }
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAaxD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAY;IAEZ,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,gDAAgD;QAChD,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC9B,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QAC/D,CAAC;QAED,iDAAiD;QACjD,MAAM,gBAAgB,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;QAEjC,0DAA0D;QAC1D,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;QAE7B,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC/C,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC;QACtE,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EA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C,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB;SAChE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;IAE3C,iCAAiC;IACjC,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;IAC3D,IAAI,KAAK,CAAC;IAEV,OAAO,CAAC,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9D,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CACT,8BAA8B,WAAW,mEAAmE,CAC7G,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@bubblelab/bubble-runtime",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "LICENSE.txt"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/bubblelabai/BubbleLab.git",
16
+ "directory": "packages/bubble-runtime"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ }
23
+ },
24
+ "dependencies": {
25
+ "@typescript-eslint/scope-manager": "=8.43.0",
26
+ "@typescript-eslint/typescript-estree": "=8.43.0",
27
+ "typescript": "^5.4.5",
28
+ "zod": "^3.24.1",
29
+ "@bubblelab/bubble-core": "0.1.0",
30
+ "@bubblelab/shared-schemas": "1.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bun": "^1.2.21",
34
+ "@types/node": "^20.12.12",
35
+ "@vitest/ui": "^3.2.4",
36
+ "vitest": "^3.2.4"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "dev": "tsc --watch",
41
+ "typecheck": "tsc --noEmit",
42
+ "test": "vitest run --exclude='**/*.integration.test.{ts,tsx,js,jsx}'",
43
+ "test:coverage": "vitest run --coverage",
44
+ "test:watch": "vitest",
45
+ "lint": "eslint . --ext .ts,.tsx"
46
+ }
47
+ }