@blaxel/core 0.2.4-preview.1 → 0.2.4-preview.3

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,13 +1,135 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
7
4
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
8
- const crypto_1 = __importDefault(require("crypto"));
5
+ // Pure JS MD5 implementation (public domain, compact)
6
+ function md5(input) {
7
+ function cmn(q, a, b, x, s, t) {
8
+ a = (((a + q) | 0) + ((x + t) | 0)) | 0;
9
+ return (((a << s) | (a >>> (32 - s))) + b) | 0;
10
+ }
11
+ function ff(a, b, c, d, x, s, t) {
12
+ return cmn((b & c) | (~b & d), a, b, x, s, t);
13
+ }
14
+ function gg(a, b, c, d, x, s, t) {
15
+ return cmn((b & d) | (c & ~d), a, b, x, s, t);
16
+ }
17
+ function hh(a, b, c, d, x, s, t) {
18
+ return cmn(b ^ c ^ d, a, b, x, s, t);
19
+ }
20
+ function ii(a, b, c, d, x, s, t) {
21
+ return cmn(c ^ (b | ~d), a, b, x, s, t);
22
+ }
23
+ function md5cycle(x, k) {
24
+ let [a, b, c, d] = x;
25
+ a = ff(a, b, c, d, k[0], 7, -680876936);
26
+ d = ff(d, a, b, c, k[1], 12, -389564586);
27
+ c = ff(c, d, a, b, k[2], 17, 606105819);
28
+ b = ff(b, c, d, a, k[3], 22, -1044525330);
29
+ a = ff(a, b, c, d, k[4], 7, -176418897);
30
+ d = ff(d, a, b, c, k[5], 12, 1200080426);
31
+ c = ff(c, d, a, b, k[6], 17, -1473231341);
32
+ b = ff(b, c, d, a, k[7], 22, -45705983);
33
+ a = ff(a, b, c, d, k[8], 7, 1770035416);
34
+ d = ff(d, a, b, c, k[9], 12, -1958414417);
35
+ c = ff(c, d, a, b, k[10], 17, -42063);
36
+ b = ff(b, c, d, a, k[11], 22, -1990404162);
37
+ a = ff(a, b, c, d, k[12], 7, 1804603682);
38
+ d = ff(d, a, b, c, k[13], 12, -40341101);
39
+ c = ff(c, d, a, b, k[14], 17, -1502002290);
40
+ b = ff(b, c, d, a, k[15], 22, 1236535329);
41
+ a = gg(a, b, c, d, k[1], 5, -165796510);
42
+ d = gg(d, a, b, c, k[6], 9, -1069501632);
43
+ c = gg(c, d, a, b, k[11], 14, 643717713);
44
+ b = gg(b, c, d, a, k[0], 20, -373897302);
45
+ a = gg(a, b, c, d, k[5], 5, -701558691);
46
+ d = gg(d, a, b, c, k[10], 9, 38016083);
47
+ c = gg(c, d, a, b, k[15], 14, -660478335);
48
+ b = gg(b, c, d, a, k[4], 20, -405537848);
49
+ a = gg(a, b, c, d, k[9], 5, 568446438);
50
+ d = gg(d, a, b, c, k[14], 9, -1019803690);
51
+ c = gg(c, d, a, b, k[3], 14, -187363961);
52
+ b = gg(b, c, d, a, k[8], 20, 1163531501);
53
+ a = gg(a, b, c, d, k[13], 5, -1444681467);
54
+ d = gg(d, a, b, c, k[2], 9, -51403784);
55
+ c = gg(c, d, a, b, k[7], 14, 1735328473);
56
+ b = gg(b, c, d, a, k[12], 20, -1926607734);
57
+ a = hh(a, b, c, d, k[5], 4, -378558);
58
+ d = hh(d, a, b, c, k[8], 11, -2022574463);
59
+ c = hh(c, d, a, b, k[11], 16, 1839030562);
60
+ b = hh(b, c, d, a, k[14], 23, -35309556);
61
+ a = hh(a, b, c, d, k[1], 4, -1530992060);
62
+ d = hh(d, a, b, c, k[4], 11, 1272893353);
63
+ c = hh(c, d, a, b, k[7], 16, -155497632);
64
+ b = hh(b, c, d, a, k[10], 23, -1094730640);
65
+ a = hh(a, b, c, d, k[13], 4, 681279174);
66
+ d = hh(d, a, b, c, k[0], 11, -358537222);
67
+ c = hh(c, d, a, b, k[3], 16, -722521979);
68
+ b = hh(b, c, d, a, k[6], 23, 76029189);
69
+ a = hh(a, b, c, d, k[9], 4, -640364487);
70
+ d = hh(d, a, b, c, k[12], 11, -421815835);
71
+ c = hh(c, d, a, b, k[15], 16, 530742520);
72
+ b = hh(b, c, d, a, k[2], 23, -995338651);
73
+ a = ii(a, b, c, d, k[0], 6, -198630844);
74
+ d = ii(d, a, b, c, k[7], 10, 1126891415);
75
+ c = ii(c, d, a, b, k[14], 15, -1416354905);
76
+ b = ii(b, c, d, a, k[5], 21, -57434055);
77
+ a = ii(a, b, c, d, k[12], 6, 1700485571);
78
+ d = ii(d, a, b, c, k[3], 10, -1894986606);
79
+ c = ii(c, d, a, b, k[10], 15, -1051523);
80
+ b = ii(b, c, d, a, k[1], 21, -2054922799);
81
+ a = ii(a, b, c, d, k[8], 6, 1873313359);
82
+ d = ii(d, a, b, c, k[15], 10, -30611744);
83
+ c = ii(c, d, a, b, k[6], 15, -1560198380);
84
+ b = ii(b, c, d, a, k[13], 21, 1309151649);
85
+ a = ii(a, b, c, d, k[4], 6, -145523070);
86
+ d = ii(d, a, b, c, k[11], 10, -1120210379);
87
+ c = ii(c, d, a, b, k[2], 15, 718787259);
88
+ b = ii(b, c, d, a, k[9], 21, -343485551);
89
+ x[0] = (a + x[0]) | 0;
90
+ x[1] = (b + x[1]) | 0;
91
+ x[2] = (c + x[2]) | 0;
92
+ x[3] = (d + x[3]) | 0;
93
+ }
94
+ function md5blk(s) {
95
+ const md5blks = [];
96
+ for (let i = 0; i < 64; i += 4) {
97
+ md5blks[i >> 2] =
98
+ s.charCodeAt(i) +
99
+ (s.charCodeAt(i + 1) << 8) +
100
+ (s.charCodeAt(i + 2) << 16) +
101
+ (s.charCodeAt(i + 3) << 24);
102
+ }
103
+ return md5blks;
104
+ }
105
+ function md51(s) {
106
+ let n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i;
107
+ for (i = 64; i <= n; i += 64) {
108
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
109
+ }
110
+ s = s.substring(i - 64);
111
+ const tail = Array(16).fill(0);
112
+ for (i = 0; i < s.length; i++)
113
+ tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
114
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
115
+ if (i > 55) {
116
+ md5cycle(state, tail);
117
+ tail.fill(0);
118
+ }
119
+ tail[14] = n * 8;
120
+ md5cycle(state, tail);
121
+ return state;
122
+ }
123
+ function rhex(n) {
124
+ let s = '', j = 0;
125
+ for (; j < 4; j++)
126
+ s += ('0' + ((n >> (j * 8 + 4)) & 0x0f).toString(16)).slice(-2) + ((n >> (j * 8)) & 0x0f).toString(16);
127
+ return s;
128
+ }
129
+ return md51(input).map(rhex).join('');
130
+ }
9
131
  function getAlphanumericLimitedHash(input, maxSize = 48) {
10
- const hash = crypto_1.default.createHash('md5').update(input).digest('hex');
132
+ const hash = md5(input);
11
133
  return hash.length > maxSize ? hash.substring(0, maxSize) : hash;
12
134
  }
13
135
  function getGlobalUniqueHash(workspace, type, name) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const internal_1 = require("./internal");
5
+ (0, vitest_1.describe)('getAlphanumericLimitedHash', () => {
6
+ (0, vitest_1.it)('returns correct MD5 hash for a known string', () => {
7
+ // MD5 of 'hello' is 5d41402abc4b2a76b9719d911017c592
8
+ (0, vitest_1.expect)((0, internal_1.getAlphanumericLimitedHash)('hello')).toBe('05d04104002a0bc04b02a0760b907109d0910100170c5092');
9
+ });
10
+ (0, vitest_1.it)('respects the maxSize parameter', () => {
11
+ const hash = (0, internal_1.getAlphanumericLimitedHash)('hello', 8);
12
+ (0, vitest_1.expect)(hash.length).toBe(8);
13
+ (0, vitest_1.expect)(hash).toBe('05d04104');
14
+ });
15
+ (0, vitest_1.it)('returns full hash if maxSize is larger than hash', () => {
16
+ const hash = (0, internal_1.getAlphanumericLimitedHash)('hello', 64);
17
+ (0, vitest_1.expect)(hash).toBe('05d04104002a0bc04b02a0760b907109d0910100170c5092');
18
+ });
19
+ });
20
+ (0, vitest_1.describe)('getGlobalUniqueHash', () => {
21
+ (0, vitest_1.it)('returns a hash for the combined workspace, type, and name', () => {
22
+ // The input string will be 'ws-type-name'
23
+ const expected = (0, internal_1.getAlphanumericLimitedHash)('ws-type-name', 48);
24
+ (0, vitest_1.expect)((0, internal_1.getGlobalUniqueHash)('ws', 'type', 'name')).toBe(expected);
25
+ });
26
+ (0, vitest_1.it)('returns a 48-character hash by default', () => {
27
+ const hash = (0, internal_1.getGlobalUniqueHash)('a', 'b', 'c');
28
+ (0, vitest_1.expect)(hash.length).toBeLessThanOrEqual(48);
29
+ });
30
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const vitest_1 = require("vitest");
37
+ // Import your SDK entry point or a function to test
38
+ const sdk = __importStar(require("./index"));
39
+ (0, vitest_1.describe)('SDK Browser Integration', () => {
40
+ (0, vitest_1.it)('should load the SDK without Node.js-only modules', () => {
41
+ // Example: check that SDK loads and a function exists
42
+ (0, vitest_1.expect)(typeof sdk).toBe('object');
43
+ // Add more specific tests for your SDK as needed
44
+ });
45
+ });
@@ -6,6 +6,12 @@ export type CopyResponse = {
6
6
  source: string;
7
7
  destination: string;
8
8
  };
9
+ export type WatchEvent = {
10
+ op: "CREATE" | "WRITE" | "REMOVE";
11
+ path: string;
12
+ name: string;
13
+ content?: string;
14
+ };
9
15
  export declare class SandboxFileSystem extends SandboxAction {
10
16
  constructor(sandbox: Sandbox);
11
17
  mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
@@ -14,7 +20,7 @@ export declare class SandboxFileSystem extends SandboxAction {
14
20
  rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
15
21
  ls(path: string): Promise<Directory>;
16
22
  cp(source: string, destination: string): Promise<CopyResponse>;
17
- watch(path: string, callback: (filePath: string, content?: string) => void | Promise<void>, options?: {
23
+ watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
18
24
  onError?: (error: Error) => void;
19
25
  withContent: boolean;
20
26
  }): {
@@ -146,20 +146,29 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
146
146
  let lines = buffer.split('\n');
147
147
  buffer = lines.pop();
148
148
  for (const line of lines) {
149
- const filePath = line.trim();
150
- if (!filePath)
149
+ const trimmed = line.trim();
150
+ if (!trimmed)
151
151
  continue;
152
- if (options?.withContent) {
152
+ const fileEvent = JSON.parse(line.trim());
153
+ if (options?.withContent && ["CREATE", "WRITE"].includes(fileEvent.op)) {
153
154
  try {
155
+ let filePath = "";
156
+ if (fileEvent.path.endsWith("/")) {
157
+ filePath = fileEvent.path + fileEvent.name;
158
+ }
159
+ else {
160
+ filePath = fileEvent.path + "/" + fileEvent.name;
161
+ }
154
162
  const content = await this.read(filePath);
155
- await callback(filePath, content);
163
+ await callback({ ...fileEvent, content });
156
164
  }
157
165
  catch (e) {
158
- await callback(filePath, undefined);
166
+ console.log(e);
167
+ await callback({ ...fileEvent, content: undefined });
159
168
  }
160
169
  }
161
170
  else {
162
- await callback(filePath);
171
+ await callback(fileEvent);
163
172
  }
164
173
  }
165
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.4-preview.1",
3
+ "version": "0.2.4-preview.3",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -66,13 +66,19 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@eslint/js": "^9.26.0",
69
+ "@testing-library/dom": "^9.3.0",
69
70
  "@types/ws": "^8.18.1",
71
+ "jsdom": "^26.1.0",
70
72
  "typescript": "^5.0.0",
71
- "typescript-eslint": "^8.31.1"
73
+ "typescript-eslint": "^8.31.1",
74
+ "vite": "^5.2.0",
75
+ "vitest": "^1.5.0"
72
76
  },
73
77
  "scripts": {
74
78
  "lint": "eslint src/",
75
79
  "dev": "tsc --watch",
76
- "build": "tsc"
80
+ "build": "tsc",
81
+ "test": "vitest --run",
82
+ "test:watch": "vitest --watch"
77
83
  }
78
84
  }