@arcote.tech/arc-adapter-db-sqlite-wasm 0.7.7 → 0.7.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.
Files changed (2) hide show
  1. package/dist/index.js +37 -13
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2997,10 +2997,11 @@ class ArcFunction {
2997
2997
  params: schema instanceof ArcObject ? schema : new ArcObject(schema)
2998
2998
  });
2999
2999
  }
3000
- withResult(schema) {
3000
+ withResult(...schemas) {
3001
+ const results = schemas.map((s) => s instanceof ArcObject ? s : new ArcObject(s));
3001
3002
  return new ArcFunction({
3002
3003
  ...this.data,
3003
- result: schema instanceof ArcObject ? schema : new ArcObject(schema)
3004
+ results
3004
3005
  });
3005
3006
  }
3006
3007
  query(elements) {
@@ -3028,6 +3029,12 @@ class ArcFunction {
3028
3029
  description: desc
3029
3030
  });
3030
3031
  }
3032
+ private() {
3033
+ return new ArcFunction({
3034
+ ...this.data,
3035
+ isPrivate: true
3036
+ });
3037
+ }
3031
3038
  handle(handler) {
3032
3039
  return new ArcFunction({
3033
3040
  ...this.data,
@@ -3049,8 +3056,8 @@ class ArcFunction {
3049
3056
  get params() {
3050
3057
  return this.data.params;
3051
3058
  }
3052
- get result() {
3053
- return this.data.result;
3059
+ get results() {
3060
+ return this.data.results;
3054
3061
  }
3055
3062
  async verifyProtections(tokens) {
3056
3063
  if (!this.data.protections || this.data.protections.length === 0) {
@@ -3074,7 +3081,7 @@ class ArcFunction {
3074
3081
  toJsonSchema() {
3075
3082
  return {
3076
3083
  params: this.data.params?.toJsonSchema?.() ?? null,
3077
- result: this.data.result?.toJsonSchema?.() ?? null
3084
+ results: this.data.results.map((r) => r.toJsonSchema())
3078
3085
  };
3079
3086
  }
3080
3087
  }
@@ -3126,7 +3133,7 @@ class ArcCommand extends ArcContextElement {
3126
3133
  this.data = data;
3127
3134
  this.#fn = fn ?? new ArcFunction({
3128
3135
  params: data.params,
3129
- result: null,
3136
+ results: data.results,
3130
3137
  queryElements: data.queryElements,
3131
3138
  mutationElements: data.mutationElements,
3132
3139
  protections: data.protections || [],
@@ -3157,7 +3164,8 @@ class ArcCommand extends ArcContextElement {
3157
3164
  }, newFn);
3158
3165
  }
3159
3166
  withResult(...schemas) {
3160
- return new ArcCommand({ ...this.data, results: schemas }, this.#fn);
3167
+ const newFn = this.#fn.withResult(...schemas);
3168
+ return new ArcCommand({ ...this.data, results: newFn.data.results }, newFn);
3161
3169
  }
3162
3170
  handle(handler) {
3163
3171
  const newFn = new ArcFunction({
@@ -3248,7 +3256,7 @@ class ArcListener extends ArcContextElement {
3248
3256
  this.data = data;
3249
3257
  this.#fn = fn ?? new ArcFunction({
3250
3258
  params: null,
3251
- result: null,
3259
+ results: [],
3252
3260
  queryElements: data.queryElements,
3253
3261
  mutationElements: data.mutationElements,
3254
3262
  protections: [],
@@ -3354,7 +3362,7 @@ class ArcRoute extends ArcContextElement {
3354
3362
  this.data = data;
3355
3363
  this.#fn = fn ?? new ArcFunction({
3356
3364
  params: null,
3357
- result: null,
3365
+ results: [],
3358
3366
  queryElements: data.queryElements,
3359
3367
  mutationElements: data.mutationElements,
3360
3368
  protections: data.protections || [],
@@ -4087,19 +4095,26 @@ function buildContextAccessor(context2, adapters, contextMethod, onCall) {
4087
4095
  if (typeof ctxFn !== "function")
4088
4096
  continue;
4089
4097
  const methods = ctxFn.call(element2, adapters);
4090
- if (!methods || typeof methods !== "object")
4098
+ if (!methods)
4099
+ continue;
4100
+ const elementName = element2.name;
4101
+ if (typeof methods === "function") {
4102
+ result[elementName] = (...args) => onCall({ element: elementName, method: "", args }, () => methods(...args));
4103
+ continue;
4104
+ }
4105
+ if (typeof methods !== "object")
4091
4106
  continue;
4092
4107
  const wrapped = {};
4093
4108
  for (const [methodName, method] of Object.entries(methods)) {
4094
4109
  if (typeof method !== "function")
4095
4110
  continue;
4096
- wrapped[methodName] = (...args) => onCall({ element: element2.name, method: methodName, args }, () => method(...args));
4111
+ wrapped[methodName] = (...args) => onCall({ element: elementName, method: methodName, args }, () => method(...args));
4097
4112
  }
4098
- result[element2.name] = wrapped;
4113
+ result[elementName] = wrapped;
4099
4114
  }
4100
4115
  return result;
4101
4116
  }
4102
- function executeDescriptor(descriptor, context2, adapters, contextMethod) {
4117
+ function executeDescriptor(descriptor, context2, adapters, contextMethod, options) {
4103
4118
  const element2 = context2.get(descriptor.element);
4104
4119
  if (!element2) {
4105
4120
  throw new Error(`Element '${descriptor.element}' not found in context`);
@@ -4109,10 +4124,19 @@ function executeDescriptor(descriptor, context2, adapters, contextMethod) {
4109
4124
  throw new Error(`Element '${descriptor.element}' has no ${contextMethod}`);
4110
4125
  }
4111
4126
  const methods = ctxFn.call(element2, adapters);
4127
+ if (typeof methods === "function") {
4128
+ if (options?.fromWire && methods.__isPrivate) {
4129
+ throw new Error(`Element "${descriptor.element}" is private and not callable from a client.`);
4130
+ }
4131
+ return methods(...descriptor.args);
4132
+ }
4112
4133
  const method = methods?.[descriptor.method];
4113
4134
  if (typeof method !== "function") {
4114
4135
  throw new Error(`Method '${descriptor.method}' not found on '${descriptor.element}'`);
4115
4136
  }
4137
+ if (options?.fromWire && method.__isPrivate) {
4138
+ throw new Error(`Method "${descriptor.element}.${descriptor.method}" is private and not callable from a client.`);
4139
+ }
4116
4140
  return method(...descriptor.args);
4117
4141
  }
4118
4142
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite-wasm",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
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.7",
42
+ "@arcote.tech/arc": "^0.7.8",
43
43
  "@sqlite.org/sqlite-wasm": "^3.46.0-build1"
44
44
  },
45
45
  "devDependencies": {