@bayoudhi/moose-lib-serverless 0.4.0 → 0.6.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.
- package/README.md +21 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/moose-tspc.js +339 -0
- package/package.json +5 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
5
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// stub-native:@514labs/kafka-javascript
|
|
9
|
+
var require_kafka_javascript = __commonJS({
|
|
10
|
+
"stub-native:@514labs/kafka-javascript"(exports2, module2) {
|
|
11
|
+
"use strict";
|
|
12
|
+
function createDeepProxy() {
|
|
13
|
+
var handler = {
|
|
14
|
+
get: function(_, prop) {
|
|
15
|
+
if (prop === "__esModule") return true;
|
|
16
|
+
if (prop === "default") return proxy;
|
|
17
|
+
if (typeof prop === "symbol") return void 0;
|
|
18
|
+
return proxy;
|
|
19
|
+
},
|
|
20
|
+
apply: function() {
|
|
21
|
+
return proxy;
|
|
22
|
+
},
|
|
23
|
+
construct: function() {
|
|
24
|
+
return proxy;
|
|
25
|
+
},
|
|
26
|
+
ownKeys: function() {
|
|
27
|
+
return ["length", "name", "prototype"];
|
|
28
|
+
},
|
|
29
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
30
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
31
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
},
|
|
35
|
+
getPrototypeOf: function() {
|
|
36
|
+
return proxy;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var proxy = new Proxy(function() {
|
|
40
|
+
}, handler);
|
|
41
|
+
return proxy;
|
|
42
|
+
}
|
|
43
|
+
module2.exports = createDeepProxy();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// src/moose-tspc.ts
|
|
48
|
+
var __create = Object.create;
|
|
49
|
+
var __defProp = Object.defineProperty;
|
|
50
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
51
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
52
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
53
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
54
|
+
var __copyProps = (to, from, except, desc) => {
|
|
55
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
56
|
+
for (let key of __getOwnPropNames2(from))
|
|
57
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
58
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
59
|
+
}
|
|
60
|
+
return to;
|
|
61
|
+
};
|
|
62
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
63
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
64
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
65
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
66
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
67
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
68
|
+
mod
|
|
69
|
+
));
|
|
70
|
+
var import_child_process = require("child_process");
|
|
71
|
+
var import_fs3 = require("fs");
|
|
72
|
+
var import_path3 = __toESM(require("path"));
|
|
73
|
+
var import_fs = require("fs");
|
|
74
|
+
var import_path = __toESM(require("path"));
|
|
75
|
+
var MOOSE_COMPILER_PLUGINS = [
|
|
76
|
+
{
|
|
77
|
+
transform: "./node_modules/@bayoudhi/moose-lib-serverless/dist/compilerPlugin.js"
|
|
78
|
+
// No longer using transformProgram - direct typia integration eliminates
|
|
79
|
+
// the need for program replacement and the associated incremental compilation issues
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
// Keep typia plugin for users who use typia directly (not through Moose resources)
|
|
83
|
+
transform: "typia/lib/transform"
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
var MOOSE_COMPILER_OPTIONS = {
|
|
87
|
+
experimentalDecorators: true,
|
|
88
|
+
esModuleInterop: true,
|
|
89
|
+
// Disable strict module syntax checking to avoid dual-package type conflicts
|
|
90
|
+
// This prevents errors where the same type imported with different resolution
|
|
91
|
+
// modes (CJS vs ESM) is treated as incompatible
|
|
92
|
+
verbatimModuleSyntax: false
|
|
93
|
+
};
|
|
94
|
+
function getSourceDir() {
|
|
95
|
+
return process.env.MOOSE_SOURCE_DIR || "app";
|
|
96
|
+
}
|
|
97
|
+
function detectModuleSystem(projectRoot2 = process.cwd()) {
|
|
98
|
+
const pkgPath = import_path.default.join(projectRoot2, "package.json");
|
|
99
|
+
if ((0, import_fs.existsSync)(pkgPath)) {
|
|
100
|
+
try {
|
|
101
|
+
const pkgContent = (0, import_fs.readFileSync)(pkgPath, "utf-8");
|
|
102
|
+
const pkg = JSON.parse(pkgContent);
|
|
103
|
+
if (pkg.type === "module") {
|
|
104
|
+
return "esm";
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.debug(
|
|
108
|
+
`[moose] Failed to parse package.json at ${pkgPath}, defaulting to CJS:`,
|
|
109
|
+
e
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return "cjs";
|
|
114
|
+
}
|
|
115
|
+
function getModuleOptions(moduleSystem) {
|
|
116
|
+
if (moduleSystem === "esm") {
|
|
117
|
+
return {
|
|
118
|
+
module: "ES2022",
|
|
119
|
+
moduleResolution: "bundler"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
module: "CommonJS",
|
|
124
|
+
moduleResolution: "Node"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
var import_fs2 = require("fs");
|
|
128
|
+
var import_path2 = __toESM(require("path"));
|
|
129
|
+
var import_client = require("@clickhouse/client");
|
|
130
|
+
var import_kafka_javascript = require_kafka_javascript();
|
|
131
|
+
var { Kafka } = import_kafka_javascript.KafkaJS;
|
|
132
|
+
function walkDirectory(dir, extensions) {
|
|
133
|
+
const results = [];
|
|
134
|
+
if (!(0, import_fs2.existsSync)(dir)) {
|
|
135
|
+
return results;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const entries = (0, import_fs2.readdirSync)(dir, { withFileTypes: true });
|
|
139
|
+
for (const entry of entries) {
|
|
140
|
+
const fullPath = import_path2.default.join(dir, entry.name);
|
|
141
|
+
if (entry.isDirectory()) {
|
|
142
|
+
if (entry.name !== "node_modules") {
|
|
143
|
+
results.push(...walkDirectory(fullPath, extensions));
|
|
144
|
+
}
|
|
145
|
+
} else if (entry.isFile()) {
|
|
146
|
+
const ext = import_path2.default.extname(entry.name);
|
|
147
|
+
if (extensions.includes(ext)) {
|
|
148
|
+
results.push(fullPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.debug(`[moose] Failed to read directory ${dir}:`, e);
|
|
154
|
+
}
|
|
155
|
+
return results;
|
|
156
|
+
}
|
|
157
|
+
function addJsExtensionToImports(content, fileDir) {
|
|
158
|
+
const fromPattern = /(from\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
159
|
+
const bareImportPattern = /(import\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
160
|
+
const dynamicPattern = /(import\s*\(\s*['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
161
|
+
let result = content;
|
|
162
|
+
result = result.replace(fromPattern, (match, prefix, importPath, quote) => {
|
|
163
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
164
|
+
});
|
|
165
|
+
result = result.replace(
|
|
166
|
+
bareImportPattern,
|
|
167
|
+
(match, prefix, importPath, quote) => {
|
|
168
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
result = result.replace(
|
|
172
|
+
dynamicPattern,
|
|
173
|
+
(match, prefix, importPath, quote) => {
|
|
174
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
function rewriteImportPath(match, prefix, importPath, quote, fileDir) {
|
|
180
|
+
if (/\.[cm]?js$/.test(importPath)) {
|
|
181
|
+
return match;
|
|
182
|
+
}
|
|
183
|
+
if (/\.json$/.test(importPath)) {
|
|
184
|
+
return match;
|
|
185
|
+
}
|
|
186
|
+
if (fileDir) {
|
|
187
|
+
const resolvedPath = import_path2.default.resolve(fileDir, importPath);
|
|
188
|
+
if ((0, import_fs2.existsSync)(`${resolvedPath}.js`)) {
|
|
189
|
+
return `${prefix}${importPath}.js${quote}`;
|
|
190
|
+
}
|
|
191
|
+
if ((0, import_fs2.existsSync)(import_path2.default.join(resolvedPath, "index.js"))) {
|
|
192
|
+
return `${prefix}${importPath}/index.js${quote}`;
|
|
193
|
+
}
|
|
194
|
+
if ((0, import_fs2.existsSync)(`${resolvedPath}.mjs`)) {
|
|
195
|
+
return `${prefix}${importPath}.mjs${quote}`;
|
|
196
|
+
}
|
|
197
|
+
if ((0, import_fs2.existsSync)(import_path2.default.join(resolvedPath, "index.mjs"))) {
|
|
198
|
+
return `${prefix}${importPath}/index.mjs${quote}`;
|
|
199
|
+
}
|
|
200
|
+
if ((0, import_fs2.existsSync)(`${resolvedPath}.cjs`)) {
|
|
201
|
+
return `${prefix}${importPath}.cjs${quote}`;
|
|
202
|
+
}
|
|
203
|
+
if ((0, import_fs2.existsSync)(import_path2.default.join(resolvedPath, "index.cjs"))) {
|
|
204
|
+
return `${prefix}${importPath}/index.cjs${quote}`;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return `${prefix}${importPath}.js${quote}`;
|
|
208
|
+
}
|
|
209
|
+
function rewriteImportExtensions(outDir2) {
|
|
210
|
+
const files = walkDirectory(outDir2, [".js", ".mjs"]);
|
|
211
|
+
for (const filePath of files) {
|
|
212
|
+
const content = (0, import_fs2.readFileSync)(filePath, "utf-8");
|
|
213
|
+
const fileDir = import_path2.default.dirname(filePath);
|
|
214
|
+
const rewritten = addJsExtensionToImports(content, fileDir);
|
|
215
|
+
if (content !== rewritten) {
|
|
216
|
+
(0, import_fs2.writeFileSync)(filePath, rewritten, "utf-8");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
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);
|
|
227
|
+
}
|
|
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 = {
|
|
236
|
+
extends: "./tsconfig.json",
|
|
237
|
+
compilerOptions: {
|
|
238
|
+
...MOOSE_COMPILER_OPTIONS,
|
|
239
|
+
...moduleOptions,
|
|
240
|
+
plugins: [...MOOSE_COMPILER_PLUGINS],
|
|
241
|
+
// 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
|
+
skipLibCheck: true,
|
|
244
|
+
skipDefaultLibCheck: true,
|
|
245
|
+
// Additional settings to handle module resolution conflicts
|
|
246
|
+
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
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
(0, import_fs3.writeFileSync)(tempTsconfigPath, JSON.stringify(buildTsconfig, null, 2));
|
|
258
|
+
console.log("Created temporary tsconfig with moose plugins...");
|
|
259
|
+
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
|
+
);
|
|
278
|
+
console.log("TypeScript compilation complete.");
|
|
279
|
+
} catch (compileError) {
|
|
280
|
+
const sourceDir = getSourceDir();
|
|
281
|
+
const outputIndexPath = import_path3.default.join(
|
|
282
|
+
projectRoot,
|
|
283
|
+
outDir,
|
|
284
|
+
sourceDir,
|
|
285
|
+
"index.js"
|
|
286
|
+
);
|
|
287
|
+
if ((0, import_fs3.existsSync)(outputIndexPath)) {
|
|
288
|
+
console.warn("");
|
|
289
|
+
console.warn("\u26A0\uFE0F BUILD SAFETY WARNING \u26A0\uFE0F");
|
|
290
|
+
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"
|
|
292
|
+
);
|
|
293
|
+
console.warn(
|
|
294
|
+
"TypeScript detected type errors but JavaScript was still emitted."
|
|
295
|
+
);
|
|
296
|
+
console.warn("");
|
|
297
|
+
console.warn(
|
|
298
|
+
"IMPORTANT: Type errors can indicate code that will fail at runtime."
|
|
299
|
+
);
|
|
300
|
+
console.warn(
|
|
301
|
+
"While this build will succeed, the resulting code may crash when:"
|
|
302
|
+
);
|
|
303
|
+
console.warn(" - Functions receive unexpected argument types");
|
|
304
|
+
console.warn(
|
|
305
|
+
" - Properties are accessed on potentially null/undefined values"
|
|
306
|
+
);
|
|
307
|
+
console.warn(" - Incorrect types flow through your application logic");
|
|
308
|
+
console.warn("");
|
|
309
|
+
console.warn(
|
|
310
|
+
"RECOMMENDATION: Run `npx tsc --noEmit` to review type errors before"
|
|
311
|
+
);
|
|
312
|
+
console.warn(
|
|
313
|
+
"deploying to production. Fix any errors that could cause runtime issues."
|
|
314
|
+
);
|
|
315
|
+
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"
|
|
317
|
+
);
|
|
318
|
+
console.warn("");
|
|
319
|
+
console.log("TypeScript compilation complete (with type warnings).");
|
|
320
|
+
} else {
|
|
321
|
+
console.error("Compilation failed - no output files generated.");
|
|
322
|
+
throw compileError;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (moduleSystem === "esm") {
|
|
326
|
+
console.log("Post-processing ESM imports to add .js extensions...");
|
|
327
|
+
const fullOutDir = import_path3.default.join(projectRoot, outDir);
|
|
328
|
+
rewriteImportExtensions(fullOutDir);
|
|
329
|
+
console.log("ESM import rewriting complete.");
|
|
330
|
+
}
|
|
331
|
+
console.log("Compilation complete.");
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error("Build process failed:", error);
|
|
334
|
+
process.exit(1);
|
|
335
|
+
} finally {
|
|
336
|
+
if ((0, import_fs3.existsSync)(tempTsconfigPath)) {
|
|
337
|
+
(0, import_fs3.unlinkSync)(tempTsconfigPath);
|
|
338
|
+
}
|
|
339
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bayoudhi/moose-lib-serverless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"./dist/compilerPlugin.js": "./dist/compilerPlugin.js"
|
|
23
23
|
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"moose-tspc": "./dist/moose-tspc.js"
|
|
26
|
+
},
|
|
24
27
|
"files": [
|
|
25
28
|
"dist",
|
|
26
29
|
"LICENSE",
|
|
@@ -44,6 +47,7 @@
|
|
|
44
47
|
"compiler-plugin"
|
|
45
48
|
],
|
|
46
49
|
"dependencies": {
|
|
50
|
+
"@514labs/moose-cli": "0.6.416",
|
|
47
51
|
"@clickhouse/client": "1.8.1",
|
|
48
52
|
"csv-parse": "^5.5.5",
|
|
49
53
|
"jose": "5.9.2",
|