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

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
@@ -2914,12 +2914,35 @@ class ArcContextElement extends ArcFragmentBase {
2914
2914
  types = ["context-element"];
2915
2915
  __contextId;
2916
2916
  __contextName;
2917
+ __contextPath;
2917
2918
  get id() {
2918
2919
  return this.name;
2919
2920
  }
2921
+ __declStack;
2920
2922
  constructor(name) {
2921
2923
  super();
2922
2924
  this.name = name;
2925
+ this.__declStack = new Error().stack;
2926
+ }
2927
+ getSourceLocation() {
2928
+ const stack = this.__declStack;
2929
+ if (!stack)
2930
+ return;
2931
+ for (const raw of stack.split(`
2932
+ `).slice(1)) {
2933
+ const m = raw.match(/\(?((?:file:\/\/)?[^()\s]+?):(\d+):(\d+)\)?$/);
2934
+ if (!m)
2935
+ continue;
2936
+ let file = m[1];
2937
+ if (file.startsWith("file://"))
2938
+ file = file.slice(7);
2939
+ const isCoreInternal = /packages\/core\/(src|dist)\//.test(file) && !/\.test\.tsx?$/.test(file);
2940
+ if (file.includes("node_modules") || isCoreInternal || file.includes("native:") || !file.includes("/")) {
2941
+ continue;
2942
+ }
2943
+ return { file, line: Number(m[2]) };
2944
+ }
2945
+ return;
2923
2946
  }
2924
2947
  _seeds;
2925
2948
  getSeeds() {
@@ -3301,6 +3324,34 @@ class ArcFunction {
3301
3324
  };
3302
3325
  }
3303
3326
  }
3327
+ function serializeParams(schema, params) {
3328
+ if (schema && typeof schema.serialize === "function") {
3329
+ return schema.serialize(params ?? {});
3330
+ }
3331
+ return params;
3332
+ }
3333
+ function deserializeParams(schema, params) {
3334
+ if (schema && typeof schema.deserialize === "function") {
3335
+ return schema.deserialize(params ?? {});
3336
+ }
3337
+ return params;
3338
+ }
3339
+ function deserializeResult(schemas, value) {
3340
+ const list = Array.isArray(schemas) ? schemas : undefined;
3341
+ if (!list || list.length !== 1)
3342
+ return value;
3343
+ const schema = list[0];
3344
+ if (!schema || typeof schema.deserialize !== "function")
3345
+ return value;
3346
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
3347
+ return value;
3348
+ }
3349
+ try {
3350
+ return schema.deserialize(value);
3351
+ } catch {
3352
+ return value;
3353
+ }
3354
+ }
3304
3355
  class AggregateBase {
3305
3356
  value;
3306
3357
  _id;
@@ -3427,7 +3478,8 @@ class ArcCommand extends ArcContextElement {
3427
3478
  scope: adapters.scope.scopeName,
3428
3479
  token: adapters.scope.getToken()
3429
3480
  } : undefined;
3430
- return await adapters.commandWire.executeCommand(this.data.name, params, wireAuth);
3481
+ const wireResult = await adapters.commandWire.executeCommand(this.data.name, serializeParams(this.data.params, params), wireAuth);
3482
+ return deserializeResult(this.data.results, wireResult);
3431
3483
  };
3432
3484
  return Object.assign(executeFunc, { params: this.data.params });
3433
3485
  }
@@ -3435,10 +3487,11 @@ class ArcCommand extends ArcContextElement {
3435
3487
  if (!this.data.handler) {
3436
3488
  throw new Error(`Command "${this.data.name}" has no handler`);
3437
3489
  }
3438
- this.#fn.validateParams(params);
3490
+ const input = deserializeParams(this.data.params, params);
3491
+ this.#fn.validateParams(input);
3439
3492
  await this.#fn.authorize(adapters);
3440
3493
  const context2 = this.buildCommandContext(adapters);
3441
- return await this.data.handler(context2, params);
3494
+ return await this.data.handler(context2, input);
3442
3495
  }
3443
3496
  buildCommandContext(adapters) {
3444
3497
  const context2 = this.#fn.buildContext(adapters);
@@ -4341,7 +4394,7 @@ function extractDatabaseAgnosticSchema(arcObject, tableName) {
4341
4394
  columns
4342
4395
  };
4343
4396
  }
4344
- var dateValidator = typeValidatorBuilder("Date", (value) => value instanceof Date);
4397
+ var dateValidator = typeValidatorBuilder("Date", (value) => value instanceof Date && !isNaN(value.getTime()));
4345
4398
  function buildContextAccessor(context2, adapters, contextMethod, onCall) {
4346
4399
  const result = {};
4347
4400
  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",
3
- "version": "0.7.28",
3
+ "version": "0.7.29",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "test": "bun test"
21
21
  },
22
22
  "peerDependencies": {
23
- "@arcote.tech/arc": "^0.7.28"
23
+ "@arcote.tech/arc": "^0.7.29"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"