elit 3.1.7 → 3.1.8

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/dist/build.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as BuildOptions, a as BuildResult } from './server-CRNme9Bc.mjs';
1
+ import { B as BuildOptions, a as BuildResult } from './server-BPVoq5Xi.mjs';
2
2
  import './http.mjs';
3
3
  import 'node:events';
4
4
  import './ws.mjs';
package/dist/cli.js CHANGED
@@ -1163,6 +1163,29 @@ var init_http = __esm({
1163
1163
  _setResolver(resolve2) {
1164
1164
  this._resolve = resolve2;
1165
1165
  }
1166
+ // Express.js-like methods
1167
+ json(data, statusCode = 200) {
1168
+ if (!this.headersSent) {
1169
+ this.setHeader("Content-Type", "application/json");
1170
+ }
1171
+ this.statusCode = statusCode;
1172
+ this.end(JSON.stringify(data));
1173
+ return this;
1174
+ }
1175
+ send(data) {
1176
+ if (typeof data === "object") {
1177
+ return this.json(data);
1178
+ }
1179
+ if (!this.headersSent) {
1180
+ this.setHeader("Content-Type", "text/plain");
1181
+ }
1182
+ this.end(String(data));
1183
+ return this;
1184
+ }
1185
+ status(code) {
1186
+ this.statusCode = code;
1187
+ return this;
1188
+ }
1166
1189
  };
1167
1190
  Server = class extends import_node_events.EventEmitter {
1168
1191
  constructor(requestListener) {
@@ -1412,7 +1435,7 @@ var require_package = __commonJS({
1412
1435
  "package.json"(exports2, module2) {
1413
1436
  module2.exports = {
1414
1437
  name: "elit",
1415
- version: "3.1.7",
1438
+ version: "3.1.8",
1416
1439
  description: "Optimized lightweight library for creating DOM elements with reactive state",
1417
1440
  main: "dist/index.js",
1418
1441
  module: "dist/index.mjs",
@@ -3103,26 +3126,66 @@ var Database = class {
3103
3126
  let stringCode;
3104
3127
  if (typeof code === "function") {
3105
3128
  const funcStr = code.toString();
3106
- const arrowMatch = funcStr.match(/^[\s]*\(?\s*\)?\s*=>\s*{?/);
3107
- const functionMatch = funcStr.match(/^[\s]*function\s*\(?[\w\s]*\)?\s*{/);
3108
- const match = arrowMatch || functionMatch;
3109
- const start = match ? match[0].length : 0;
3110
- const end = funcStr.lastIndexOf("}");
3111
- stringCode = funcStr.substring(start, end);
3112
- stringCode = stringCode.replace(/^[\s\r\n]+/, "").replace(/[\s\r\n]+$/, "");
3113
- stringCode = stringCode.replace(
3114
- /import\s*\(\s*([^)]+?)\s*\)\s*\.from\s*\(\s*(['"])([^'"]+)\2\s*\)/g,
3115
- (_, importArg, quote, modulePath) => {
3116
- const trimmed = importArg.trim();
3117
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
3118
- const inner = trimmed.slice(1, -1).trim();
3119
- return `import { ${inner} } from ${quote}${modulePath}${quote}`;
3120
- } else {
3121
- return `import ${trimmed} from ${quote}${modulePath}${quote}`;
3122
- }
3129
+ if (funcStr.includes("=>")) {
3130
+ const arrowIndex = funcStr.indexOf("=>");
3131
+ let start = arrowIndex + 2;
3132
+ while (start < funcStr.length && funcStr[start] === " ") start++;
3133
+ if (funcStr[start] === "{") start++;
3134
+ let end = funcStr.lastIndexOf("}");
3135
+ if (start < end) {
3136
+ stringCode = funcStr.substring(start, end);
3137
+ } else {
3138
+ stringCode = funcStr.substring(start);
3123
3139
  }
3124
- );
3125
- stringCode = stringCode.split("\n").map((line) => line.trim()).join("\n").trim();
3140
+ } else if (funcStr.includes("function")) {
3141
+ const funcIndex = funcStr.indexOf("function");
3142
+ let start = funcIndex + 8;
3143
+ while (start < funcStr.length && funcStr[start] === " ") start++;
3144
+ if (funcStr[start] === "(") start++;
3145
+ if (start < funcStr.length && funcStr[start] !== "(") {
3146
+ while (start < funcStr.length && funcStr[start] !== " " && funcStr[start] !== "(") start++;
3147
+ }
3148
+ if (funcStr[start] === "(") start++;
3149
+ while (start < funcStr.length && funcStr[start] === " ") start++;
3150
+ if (funcStr[start] === "{") start++;
3151
+ const end = funcStr.lastIndexOf("}");
3152
+ if (start < end) {
3153
+ stringCode = funcStr.substring(start, end);
3154
+ } else {
3155
+ stringCode = funcStr.substring(start);
3156
+ }
3157
+ } else {
3158
+ stringCode = funcStr;
3159
+ }
3160
+ stringCode = stringCode.trim();
3161
+ let importPos = 0;
3162
+ while ((importPos = stringCode.indexOf("import(", importPos)) !== -1) {
3163
+ const fromPos = stringCode.indexOf(".from(", importPos);
3164
+ if (fromPos === -1) break;
3165
+ const quoteStart = stringCode.indexOf("(", fromPos + 7) + 1;
3166
+ if (quoteStart === -1) break;
3167
+ const quoteChar = stringCode[quoteStart];
3168
+ if (quoteChar !== '"' && quoteChar !== "'") break;
3169
+ const quoteEnd = stringCode.indexOf(quoteChar, quoteStart + 1);
3170
+ if (quoteEnd === -1) break;
3171
+ const modulePath = stringCode.substring(quoteStart + 1, quoteEnd);
3172
+ const importArgEnd = fromPos - 1;
3173
+ const importArgStart = importPos + 7;
3174
+ const trimmed = stringCode.substring(importArgStart, importArgEnd).trim();
3175
+ let replacement;
3176
+ if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
3177
+ const inner = trimmed.slice(1, -1).trim();
3178
+ replacement = `import { ${inner} } from "${modulePath}"`;
3179
+ } else {
3180
+ replacement = `import ${trimmed} from "${modulePath}"`;
3181
+ }
3182
+ const before = stringCode.substring(0, importPos);
3183
+ const after = stringCode.substring(quoteEnd + 2);
3184
+ stringCode = before + replacement + after;
3185
+ }
3186
+ const lines = stringCode.split("\n");
3187
+ const trimmedLines = lines.map((line) => line.trim());
3188
+ stringCode = trimmedLines.join("\n").trim();
3126
3189
  } else {
3127
3190
  stringCode = code;
3128
3191
  }
@@ -3153,7 +3216,6 @@ var Database = class {
3153
3216
  return await this.vmRun(code, options);
3154
3217
  }
3155
3218
  };
3156
- var database = serverDatabase.database;
3157
3219
 
3158
3220
  // src/server.ts
3159
3221
  var ServerDatabase = class {
@@ -3168,7 +3230,7 @@ var ServerDatabase = class {
3168
3230
  }
3169
3231
  };
3170
3232
  var serverDatabase = new ServerDatabase();
3171
- var database2 = serverDatabase.database;
3233
+ var database = serverDatabase.database;
3172
3234
  var json = (res, data, status = 200) => (res.writeHead(status, { "Content-Type": "application/json" }), res.end(JSON.stringify(data)));
3173
3235
  var sendError = (res, code, msg) => {
3174
3236
  res.writeHead(code, { "Content-Type": "text/plain" });
@@ -3625,9 +3687,9 @@ function createDevServer(options) {
3625
3687
  if (config.mode === "dev") {
3626
3688
  clearImportMapCache();
3627
3689
  }
3628
- if (config.database) {
3629
- serverDatabase.initialize(config.database);
3630
- }
3690
+ serverDatabase.initialize(config.database ? config.database : {
3691
+ dir: resolve(process.cwd(), "databases")
3692
+ });
3631
3693
  const clientsToNormalize = config.clients?.length ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || "", index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, mode: config.mode }] : null;
3632
3694
  if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
3633
3695
  const normalizedClients = clientsToNormalize.map((client) => {
@@ -26,6 +26,6 @@ declare class Database {
26
26
  logs: any[];
27
27
  }>;
28
28
  }
29
- declare const database: () => Database | null;
29
+ declare function database(): Database;
30
30
 
31
31
  export { Database, type DatabaseConfig, database, database as default };
@@ -25,6 +25,6 @@ export declare class Database {
25
25
  logs: any[];
26
26
  }>;
27
27
  }
28
- export declare const database: () => Database | null;
28
+ export declare function database(): Database;
29
29
  export default database;
30
30
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAOzB,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CAC5C;AAED,qBAAa,QAAQ;IACjB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,C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