@bayoudhi/moose-lib-serverless 0.7.2 → 0.7.4

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,9 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __create2 = Object.create;
4
+ var __defProp2 = Object.defineProperty;
5
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
7
+ var __getProtoOf2 = Object.getPrototypeOf;
8
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
4
9
  var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps2 = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames2(from))
15
+ if (!__hasOwnProp2.call(to, key) && key !== except)
16
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
6
19
  };
20
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
7
28
 
8
29
  // stub-native:@514labs/kafka-javascript
9
30
  var require_kafka_javascript = __commonJS({
@@ -48,12 +69,12 @@ var require_kafka_javascript = __commonJS({
48
69
  var __create = Object.create;
49
70
  var __defProp = Object.defineProperty;
50
71
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
51
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
72
+ var __getOwnPropNames = Object.getOwnPropertyNames;
52
73
  var __getProtoOf = Object.getPrototypeOf;
53
74
  var __hasOwnProp = Object.prototype.hasOwnProperty;
54
75
  var __copyProps = (to, from, except, desc) => {
55
76
  if (from && typeof from === "object" || typeof from === "function") {
56
- for (let key of __getOwnPropNames2(from))
77
+ for (let key of __getOwnPropNames(from))
57
78
  if (!__hasOwnProp.call(to, key) && key !== except)
58
79
  __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
59
80
  }
@@ -91,11 +112,43 @@ var MOOSE_COMPILER_OPTIONS = {
91
112
  // modes (CJS vs ESM) is treated as incompatible
92
113
  verbatimModuleSyntax: false
93
114
  };
115
+ var MOOSE_MODULE_OPTIONS = {
116
+ module: "NodeNext",
117
+ moduleResolution: "NodeNext"
118
+ };
94
119
  function getSourceDir() {
95
120
  return process.env.MOOSE_SOURCE_DIR || "app";
96
121
  }
97
- function detectModuleSystem(projectRoot2 = process.cwd()) {
98
- const pkgPath = import_path.default.join(projectRoot2, "package.json");
122
+ var DEFAULT_OUT_DIR = ".moose/compiled";
123
+ function readUserOutDir(projectRoot = process.cwd()) {
124
+ try {
125
+ let content = (0, import_fs.readFileSync)(
126
+ import_path.default.join(projectRoot, "tsconfig.json"),
127
+ "utf-8"
128
+ );
129
+ if (content.charCodeAt(0) === 65279) {
130
+ content = content.slice(1);
131
+ }
132
+ const tsconfig = eval(`(${content})`);
133
+ return tsconfig.compilerOptions?.outDir || null;
134
+ } catch {
135
+ return null;
136
+ }
137
+ }
138
+ function getOutDir(projectRoot3 = process.cwd()) {
139
+ const userOutDir2 = readUserOutDir(projectRoot3);
140
+ return userOutDir2 || DEFAULT_OUT_DIR;
141
+ }
142
+ function getCompiledIndexPath(projectRoot3 = process.cwd()) {
143
+ const outDir2 = getOutDir(projectRoot3);
144
+ const sourceDir = getSourceDir();
145
+ return import_path.default.resolve(projectRoot3, outDir2, sourceDir, "index.js");
146
+ }
147
+ function hasCompiledArtifacts(projectRoot3 = process.cwd()) {
148
+ return (0, import_fs.existsSync)(getCompiledIndexPath(projectRoot3));
149
+ }
150
+ function detectModuleSystem(projectRoot3 = process.cwd()) {
151
+ const pkgPath = import_path.default.join(projectRoot3, "package.json");
99
152
  if ((0, import_fs.existsSync)(pkgPath)) {
100
153
  try {
101
154
  const pkgContent = (0, import_fs.readFileSync)(pkgPath, "utf-8");
@@ -124,6 +177,15 @@ function getModuleOptions(moduleSystem) {
124
177
  moduleResolution: "Node"
125
178
  };
126
179
  }
180
+ async function loadModule(modulePath, projectRoot3 = process.cwd()) {
181
+ const moduleSystem = detectModuleSystem(projectRoot3);
182
+ if (moduleSystem === "esm") {
183
+ const { pathToFileURL } = await import("url");
184
+ const fileUrl = pathToFileURL(modulePath).href;
185
+ return await import(fileUrl);
186
+ }
187
+ return require(modulePath);
188
+ }
127
189
  var import_fs2 = require("fs");
128
190
  var import_path2 = __toESM(require("path"));
129
191
  var import_client = require("@clickhouse/client");
@@ -154,11 +216,11 @@ function walkDirectory(dir, extensions) {
154
216
  }
155
217
  return results;
156
218
  }
157
- function addJsExtensionToImports(content, fileDir) {
219
+ function addJsExtensionToImports(content2, fileDir) {
158
220
  const fromPattern = /(from\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
159
221
  const bareImportPattern = /(import\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
160
222
  const dynamicPattern = /(import\s*\(\s*['"])(\.\.?\/[^'"]*?)(['"])/g;
161
- let result = content;
223
+ let result = content2;
162
224
  result = result.replace(fromPattern, (match, prefix, importPath, quote) => {
163
225
  return rewriteImportPath(match, prefix, importPath, quote, fileDir);
164
226
  });
@@ -209,86 +271,84 @@ function rewriteImportPath(match, prefix, importPath, quote, fileDir) {
209
271
  function rewriteImportExtensions(outDir2) {
210
272
  const files = walkDirectory(outDir2, [".js", ".mjs"]);
211
273
  for (const filePath of files) {
212
- const content = (0, import_fs2.readFileSync)(filePath, "utf-8");
274
+ const content2 = (0, import_fs2.readFileSync)(filePath, "utf-8");
213
275
  const fileDir = import_path2.default.dirname(filePath);
214
- const rewritten = addJsExtensionToImports(content, fileDir);
215
- if (content !== rewritten) {
276
+ const rewritten = addJsExtensionToImports(content2, fileDir);
277
+ if (content2 !== rewritten) {
216
278
  (0, import_fs2.writeFileSync)(filePath, rewritten, "utf-8");
217
279
  }
218
280
  }
219
281
  }
220
- var outDir = process.argv[2] || ".moose/compiled";
221
- var projectRoot = process.cwd();
222
- var tsconfigPath = import_path3.default.join(projectRoot, "tsconfig.json");
223
- var tempTsconfigPath = import_path3.default.join(projectRoot, "tsconfig.moose-build.json");
224
- if (!(0, import_fs3.existsSync)(tsconfigPath)) {
225
- console.error("Error: tsconfig.json not found in", projectRoot);
226
- process.exit(1);
282
+ var args = process.argv.slice(2);
283
+ var watchMode = args.includes("--watch");
284
+ var cliOutDir = args.find((arg) => !arg.startsWith("--"));
285
+ var projectRoot2 = process.cwd();
286
+ var tsconfigPath = import_path3.default.join(projectRoot2, "tsconfig.json");
287
+ var tempTsconfigPath = import_path3.default.join(projectRoot2, "tsconfig.moose-build.json");
288
+ var userOutDir = readUserOutDir(projectRoot2);
289
+ var outDir = cliOutDir || userOutDir || DEFAULT_OUT_DIR;
290
+ var shouldAddOutDir = cliOutDir !== void 0 || !userOutDir;
291
+ function emitEvent(event) {
292
+ console.log(JSON.stringify(event));
227
293
  }
228
- console.log(`Compiling TypeScript to ${outDir}...`);
229
- try {
230
- const moduleSystem = detectModuleSystem(projectRoot);
231
- const moduleOptions = getModuleOptions(moduleSystem);
232
- console.log(
233
- `Using ${moduleSystem.toUpperCase()} module output (detected from package.json)...`
234
- );
235
- const buildTsconfig = {
294
+ function createBuildTsconfig(moduleOptions) {
295
+ return {
236
296
  extends: "./tsconfig.json",
237
297
  compilerOptions: {
238
298
  ...MOOSE_COMPILER_OPTIONS,
239
299
  ...moduleOptions,
240
300
  plugins: [...MOOSE_COMPILER_PLUGINS],
241
301
  // Skip type checking of declaration files to avoid dual-package conflicts
242
- // This must be in compilerOptions (not just CLI flag) to fully work
243
302
  skipLibCheck: true,
244
303
  skipDefaultLibCheck: true,
245
304
  // Additional settings to handle module resolution conflicts
246
305
  allowSyntheticDefaultImports: true,
247
- // IMPORTANT: Build Safety Trade-off
248
- // noEmitOnError: false allows JavaScript emission even with type errors.
249
- // This is intentional for Docker builds to succeed even when TypeScript
250
- // finds type issues. The trade-off is that type errors that could cause
251
- // runtime failures will not block the build - they will be logged as
252
- // warnings below. For strict type safety, users should run `npx tsc --noEmit`
253
- // before building to catch type errors that could indicate runtime issues.
254
- noEmitOnError: false
306
+ // In watch mode, we want to block on errors (noEmitOnError: true)
307
+ // In build mode, we allow emission with errors for Docker builds
308
+ noEmitOnError: watchMode,
309
+ // Enable incremental compilation for faster rebuilds
310
+ incremental: true,
311
+ tsBuildInfoFile: import_path3.default.join(outDir, ".tsbuildinfo")
255
312
  }
256
313
  };
314
+ }
315
+ function runSingleCompilation(moduleSystem) {
316
+ const moduleOptions = getModuleOptions(moduleSystem);
317
+ const buildTsconfig = createBuildTsconfig(moduleOptions);
318
+ buildTsconfig.compilerOptions.noEmitOnError = false;
257
319
  (0, import_fs3.writeFileSync)(tempTsconfigPath, JSON.stringify(buildTsconfig, null, 2));
258
320
  console.log("Created temporary tsconfig with moose plugins...");
321
+ const tspcArgs = [
322
+ "tspc",
323
+ "-p",
324
+ tempTsconfigPath,
325
+ "--rootDir",
326
+ ".",
327
+ "--sourceMap",
328
+ "--inlineSources"
329
+ ];
330
+ if (shouldAddOutDir) {
331
+ tspcArgs.push("--outDir", outDir);
332
+ }
259
333
  try {
260
- (0, import_child_process.execFileSync)(
261
- "npx",
262
- [
263
- "tspc",
264
- "-p",
265
- tempTsconfigPath,
266
- "--outDir",
267
- outDir,
268
- "--rootDir",
269
- ".",
270
- "--sourceMap",
271
- "--inlineSources"
272
- ],
273
- {
274
- stdio: "inherit",
275
- cwd: projectRoot
276
- }
277
- );
334
+ (0, import_child_process.execFileSync)("npx", tspcArgs, {
335
+ stdio: "inherit",
336
+ cwd: projectRoot2
337
+ });
278
338
  console.log("TypeScript compilation complete.");
279
339
  } catch (compileError) {
280
340
  const sourceDir = getSourceDir();
281
341
  const outputIndexPath = import_path3.default.join(
282
- projectRoot,
342
+ projectRoot2,
283
343
  outDir,
284
344
  sourceDir,
285
345
  "index.js"
286
346
  );
287
347
  if ((0, import_fs3.existsSync)(outputIndexPath)) {
288
348
  console.warn("");
289
- console.warn("\u26A0\uFE0F BUILD SAFETY WARNING \u26A0\uFE0F");
349
+ console.warn("BUILD SAFETY WARNING");
290
350
  console.warn(
291
- "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"
351
+ "==============================================================="
292
352
  );
293
353
  console.warn(
294
354
  "TypeScript detected type errors but JavaScript was still emitted."
@@ -313,7 +373,7 @@ try {
313
373
  "deploying to production. Fix any errors that could cause runtime issues."
314
374
  );
315
375
  console.warn(
316
- "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"
376
+ "==============================================================="
317
377
  );
318
378
  console.warn("");
319
379
  console.log("TypeScript compilation complete (with type warnings).");
@@ -324,16 +384,162 @@ try {
324
384
  }
325
385
  if (moduleSystem === "esm") {
326
386
  console.log("Post-processing ESM imports to add .js extensions...");
327
- const fullOutDir = import_path3.default.join(projectRoot, outDir);
387
+ const fullOutDir = import_path3.default.join(projectRoot2, outDir);
328
388
  rewriteImportExtensions(fullOutDir);
329
389
  console.log("ESM import rewriting complete.");
330
390
  }
331
- console.log("Compilation complete.");
391
+ }
392
+ function runWatchCompilation(moduleSystem) {
393
+ const moduleOptions = getModuleOptions(moduleSystem);
394
+ const buildTsconfig = createBuildTsconfig(moduleOptions);
395
+ (0, import_fs3.writeFileSync)(tempTsconfigPath, JSON.stringify(buildTsconfig, null, 2));
396
+ const fullOutDir = import_path3.default.join(projectRoot2, outDir);
397
+ if (!(0, import_fs3.existsSync)(fullOutDir)) {
398
+ (0, import_fs3.mkdirSync)(fullOutDir, { recursive: true });
399
+ }
400
+ let currentDiagnostics = [];
401
+ let errorCount = 0;
402
+ let warningCount = 0;
403
+ const tspcArgs = [
404
+ "tspc",
405
+ "-p",
406
+ tempTsconfigPath,
407
+ "--rootDir",
408
+ ".",
409
+ "--sourceMap",
410
+ "--inlineSources",
411
+ "--watch",
412
+ "--preserveWatchOutput"
413
+ ];
414
+ if (shouldAddOutDir) {
415
+ tspcArgs.splice(6, 0, "--outDir", outDir);
416
+ }
417
+ const tspcProcess = (0, import_child_process.spawn)("npx", tspcArgs, {
418
+ cwd: projectRoot2,
419
+ stdio: ["ignore", "pipe", "pipe"]
420
+ });
421
+ const cleanup = () => {
422
+ if ((0, import_fs3.existsSync)(tempTsconfigPath)) {
423
+ (0, import_fs3.unlinkSync)(tempTsconfigPath);
424
+ }
425
+ tspcProcess.kill();
426
+ };
427
+ process.on("SIGINT", () => {
428
+ cleanup();
429
+ process.exit(0);
430
+ });
431
+ process.on("SIGTERM", () => {
432
+ cleanup();
433
+ process.exit(0);
434
+ });
435
+ let buffer = "";
436
+ const stripAnsi = (str) => str.replace(
437
+ /[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[-a-zA-Z\d/#&.:=?%@~_]*)*)?[\u0007])|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))/g,
438
+ ""
439
+ );
440
+ const compilationStartedRegex = /Starting compilation in watch mode|Starting incremental compilation/;
441
+ const compilationCompleteRegex = /Found\s+(\d+)\s+error(?:s)?\..*Watching for file changes/;
442
+ const diagnosticRegex = /\(\d+,\d+\):\s*(error|warning)\s+TS\d+:/;
443
+ const processLine = (line) => {
444
+ const cleanLine = stripAnsi(line);
445
+ if (compilationStartedRegex.test(cleanLine)) {
446
+ currentDiagnostics = [];
447
+ errorCount = 0;
448
+ warningCount = 0;
449
+ emitEvent({ event: "compile_start" });
450
+ } else if (compilationCompleteRegex.test(cleanLine)) {
451
+ const match = cleanLine.match(/Found\s+(\d+)\s+error(?:s)?\./);
452
+ if (match) {
453
+ errorCount = parseInt(match[1], 10);
454
+ }
455
+ if (errorCount === 0 && moduleSystem === "esm") {
456
+ try {
457
+ rewriteImportExtensions(fullOutDir);
458
+ } catch (e) {
459
+ console.error("Warning: ESM import rewriting failed:", e);
460
+ }
461
+ }
462
+ if (errorCount > 0) {
463
+ emitEvent({
464
+ event: "compile_error",
465
+ errors: errorCount,
466
+ warnings: warningCount,
467
+ diagnostics: currentDiagnostics
468
+ });
469
+ } else {
470
+ emitEvent({
471
+ event: "compile_complete",
472
+ errors: 0,
473
+ warnings: warningCount,
474
+ diagnostics: warningCount > 0 ? currentDiagnostics : void 0
475
+ });
476
+ }
477
+ } else if (diagnosticRegex.test(cleanLine)) {
478
+ currentDiagnostics.push(cleanLine.trim());
479
+ if (cleanLine.includes(": error ")) {
480
+ errorCount++;
481
+ } else if (cleanLine.includes(": warning ")) {
482
+ warningCount++;
483
+ }
484
+ }
485
+ };
486
+ tspcProcess.stdout.on("data", (data) => {
487
+ buffer += data.toString();
488
+ const lines = buffer.split("\n");
489
+ buffer = lines.pop() || "";
490
+ for (const line of lines) {
491
+ if (line.trim()) {
492
+ processLine(line);
493
+ }
494
+ }
495
+ });
496
+ tspcProcess.stderr.on("data", (data) => {
497
+ process.stderr.write(data.toString());
498
+ });
499
+ tspcProcess.on("error", (err) => {
500
+ console.error("Failed to start tspc:", err);
501
+ cleanup();
502
+ process.exit(1);
503
+ });
504
+ tspcProcess.on("exit", (code) => {
505
+ cleanup();
506
+ if (code !== 0) {
507
+ process.exit(code || 1);
508
+ }
509
+ });
510
+ }
511
+ function writeCompileConfig() {
512
+ const mooseDir = import_path3.default.join(projectRoot2, ".moose");
513
+ if (!(0, import_fs3.existsSync)(mooseDir)) {
514
+ (0, import_fs3.mkdirSync)(mooseDir, { recursive: true });
515
+ }
516
+ const configPath = import_path3.default.join(mooseDir, ".compile-config.json");
517
+ (0, import_fs3.writeFileSync)(configPath, JSON.stringify({ outDir }, null, 2));
518
+ }
519
+ if (!(0, import_fs3.existsSync)(tsconfigPath)) {
520
+ console.error("Error: tsconfig.json not found in", projectRoot2);
521
+ process.exit(1);
522
+ }
523
+ try {
524
+ writeCompileConfig();
525
+ const moduleSystem = detectModuleSystem(projectRoot2);
526
+ if (watchMode) {
527
+ runWatchCompilation(moduleSystem);
528
+ } else {
529
+ console.log(`Compiling TypeScript to ${outDir}...`);
530
+ console.log(
531
+ `Using ${moduleSystem.toUpperCase()} module output (detected from package.json)...`
532
+ );
533
+ runSingleCompilation(moduleSystem);
534
+ console.log("Compilation complete.");
535
+ if ((0, import_fs3.existsSync)(tempTsconfigPath)) {
536
+ (0, import_fs3.unlinkSync)(tempTsconfigPath);
537
+ }
538
+ }
332
539
  } catch (error) {
333
540
  console.error("Build process failed:", error);
334
- process.exit(1);
335
- } finally {
336
541
  if ((0, import_fs3.existsSync)(tempTsconfigPath)) {
337
542
  (0, import_fs3.unlinkSync)(tempTsconfigPath);
338
543
  }
544
+ process.exit(1);
339
545
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bayoudhi/moose-lib-serverless",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Serverless-compatible subset of @514labs/moose-lib for AWS Lambda and edge runtimes. Provides OlapTable, Stream, Workflow, View, and other Moose SDK classes without native C++ dependencies (Kafka, Temporal). Includes a patched compiler plugin for type-driven schema injection.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -59,7 +59,7 @@
59
59
  "typescript": "~5.9.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@514labs/moose-lib": "workspace:*",
62
+ "@514labs/moose-lib": "0.6.417",
63
63
  "tsup": "^8.4.0"
64
64
  },
65
65
  "peerDependencies": {