@arcote.tech/arc-adapter-db-sqlite-wasm 0.7.28 → 0.7.30

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 (2) hide show
  1. package/dist/index.js +57 -4
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2911,12 +2911,35 @@ class ArcContextElement extends ArcFragmentBase {
2911
2911
  types = ["context-element"];
2912
2912
  __contextId;
2913
2913
  __contextName;
2914
+ __contextPath;
2914
2915
  get id() {
2915
2916
  return this.name;
2916
2917
  }
2918
+ __declStack;
2917
2919
  constructor(name) {
2918
2920
  super();
2919
2921
  this.name = name;
2922
+ this.__declStack = new Error().stack;
2923
+ }
2924
+ getSourceLocation() {
2925
+ const stack = this.__declStack;
2926
+ if (!stack)
2927
+ return;
2928
+ for (const raw of stack.split(`
2929
+ `).slice(1)) {
2930
+ const m = raw.match(/\(?((?:file:\/\/)?[^()\s]+?):(\d+):(\d+)\)?$/);
2931
+ if (!m)
2932
+ continue;
2933
+ let file = m[1];
2934
+ if (file.startsWith("file://"))
2935
+ file = file.slice(7);
2936
+ const isCoreInternal = /packages\/core\/(src|dist)\//.test(file) && !/\.test\.tsx?$/.test(file);
2937
+ if (file.includes("node_modules") || isCoreInternal || file.includes("native:") || !file.includes("/")) {
2938
+ continue;
2939
+ }
2940
+ return { file, line: Number(m[2]) };
2941
+ }
2942
+ return;
2920
2943
  }
2921
2944
  _seeds;
2922
2945
  getSeeds() {
@@ -3298,6 +3321,34 @@ class ArcFunction {
3298
3321
  };
3299
3322
  }
3300
3323
  }
3324
+ function serializeParams(schema, params) {
3325
+ if (schema && typeof schema.serialize === "function") {
3326
+ return schema.serialize(params ?? {});
3327
+ }
3328
+ return params;
3329
+ }
3330
+ function deserializeParams(schema, params) {
3331
+ if (schema && typeof schema.deserialize === "function") {
3332
+ return schema.deserialize(params ?? {});
3333
+ }
3334
+ return params;
3335
+ }
3336
+ function deserializeResult(schemas, value) {
3337
+ const list = Array.isArray(schemas) ? schemas : undefined;
3338
+ if (!list || list.length !== 1)
3339
+ return value;
3340
+ const schema = list[0];
3341
+ if (!schema || typeof schema.deserialize !== "function")
3342
+ return value;
3343
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
3344
+ return value;
3345
+ }
3346
+ try {
3347
+ return schema.deserialize(value);
3348
+ } catch {
3349
+ return value;
3350
+ }
3351
+ }
3301
3352
  class AggregateBase {
3302
3353
  value;
3303
3354
  _id;
@@ -3424,7 +3475,8 @@ class ArcCommand extends ArcContextElement {
3424
3475
  scope: adapters.scope.scopeName,
3425
3476
  token: adapters.scope.getToken()
3426
3477
  } : undefined;
3427
- return await adapters.commandWire.executeCommand(this.data.name, params, wireAuth);
3478
+ const wireResult = await adapters.commandWire.executeCommand(this.data.name, serializeParams(this.data.params, params), wireAuth);
3479
+ return deserializeResult(this.data.results, wireResult);
3428
3480
  };
3429
3481
  return Object.assign(executeFunc, { params: this.data.params });
3430
3482
  }
@@ -3432,10 +3484,11 @@ class ArcCommand extends ArcContextElement {
3432
3484
  if (!this.data.handler) {
3433
3485
  throw new Error(`Command "${this.data.name}" has no handler`);
3434
3486
  }
3435
- this.#fn.validateParams(params);
3487
+ const input = deserializeParams(this.data.params, params);
3488
+ this.#fn.validateParams(input);
3436
3489
  await this.#fn.authorize(adapters);
3437
3490
  const context2 = this.buildCommandContext(adapters);
3438
- return await this.data.handler(context2, params);
3491
+ return await this.data.handler(context2, input);
3439
3492
  }
3440
3493
  buildCommandContext(adapters) {
3441
3494
  const context2 = this.#fn.buildContext(adapters);
@@ -4338,7 +4391,7 @@ function extractDatabaseAgnosticSchema(arcObject, tableName) {
4338
4391
  columns
4339
4392
  };
4340
4393
  }
4341
- var dateValidator = typeValidatorBuilder("Date", (value) => value instanceof Date);
4394
+ var dateValidator = typeValidatorBuilder("Date", (value) => value instanceof Date && !isNaN(value.getTime()));
4342
4395
  function buildContextAccessor(context2, adapters, contextMethod, onCall) {
4343
4396
  const result = {};
4344
4397
  for (const element2 of context2.elements) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite-wasm",
3
- "version": "0.7.28",
3
+ "version": "0.7.30",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "dev": "bun build ./src/index.ts ./src/worker.ts --outdir ./dist --target browser --format esm --watch"
40
40
  },
41
41
  "peerDependencies": {
42
- "@arcote.tech/arc": "^0.7.28",
42
+ "@arcote.tech/arc": "^0.7.30",
43
43
  "@sqlite.org/sqlite-wasm": "^3.46.0-build1"
44
44
  },
45
45
  "devDependencies": {