@arcote.tech/arc-adapter-db-sqlite 0.7.6 → 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
@@ -3000,10 +3000,11 @@ class ArcFunction {
3000
3000
  params: schema instanceof ArcObject ? schema : new ArcObject(schema)
3001
3001
  });
3002
3002
  }
3003
- withResult(schema) {
3003
+ withResult(...schemas) {
3004
+ const results = schemas.map((s) => s instanceof ArcObject ? s : new ArcObject(s));
3004
3005
  return new ArcFunction({
3005
3006
  ...this.data,
3006
- result: schema instanceof ArcObject ? schema : new ArcObject(schema)
3007
+ results
3007
3008
  });
3008
3009
  }
3009
3010
  query(elements) {
@@ -3031,6 +3032,12 @@ class ArcFunction {
3031
3032
  description: desc
3032
3033
  });
3033
3034
  }
3035
+ private() {
3036
+ return new ArcFunction({
3037
+ ...this.data,
3038
+ isPrivate: true
3039
+ });
3040
+ }
3034
3041
  handle(handler) {
3035
3042
  return new ArcFunction({
3036
3043
  ...this.data,
@@ -3052,8 +3059,8 @@ class ArcFunction {
3052
3059
  get params() {
3053
3060
  return this.data.params;
3054
3061
  }
3055
- get result() {
3056
- return this.data.result;
3062
+ get results() {
3063
+ return this.data.results;
3057
3064
  }
3058
3065
  async verifyProtections(tokens) {
3059
3066
  if (!this.data.protections || this.data.protections.length === 0) {
@@ -3077,7 +3084,7 @@ class ArcFunction {
3077
3084
  toJsonSchema() {
3078
3085
  return {
3079
3086
  params: this.data.params?.toJsonSchema?.() ?? null,
3080
- result: this.data.result?.toJsonSchema?.() ?? null
3087
+ results: this.data.results.map((r) => r.toJsonSchema())
3081
3088
  };
3082
3089
  }
3083
3090
  }
@@ -3129,7 +3136,7 @@ class ArcCommand extends ArcContextElement {
3129
3136
  this.data = data;
3130
3137
  this.#fn = fn ?? new ArcFunction({
3131
3138
  params: data.params,
3132
- result: null,
3139
+ results: data.results,
3133
3140
  queryElements: data.queryElements,
3134
3141
  mutationElements: data.mutationElements,
3135
3142
  protections: data.protections || [],
@@ -3160,7 +3167,8 @@ class ArcCommand extends ArcContextElement {
3160
3167
  }, newFn);
3161
3168
  }
3162
3169
  withResult(...schemas) {
3163
- return new ArcCommand({ ...this.data, results: schemas }, this.#fn);
3170
+ const newFn = this.#fn.withResult(...schemas);
3171
+ return new ArcCommand({ ...this.data, results: newFn.data.results }, newFn);
3164
3172
  }
3165
3173
  handle(handler) {
3166
3174
  const newFn = new ArcFunction({
@@ -3251,7 +3259,7 @@ class ArcListener extends ArcContextElement {
3251
3259
  this.data = data;
3252
3260
  this.#fn = fn ?? new ArcFunction({
3253
3261
  params: null,
3254
- result: null,
3262
+ results: [],
3255
3263
  queryElements: data.queryElements,
3256
3264
  mutationElements: data.mutationElements,
3257
3265
  protections: [],
@@ -3357,7 +3365,7 @@ class ArcRoute extends ArcContextElement {
3357
3365
  this.data = data;
3358
3366
  this.#fn = fn ?? new ArcFunction({
3359
3367
  params: null,
3360
- result: null,
3368
+ results: [],
3361
3369
  queryElements: data.queryElements,
3362
3370
  mutationElements: data.mutationElements,
3363
3371
  protections: data.protections || [],
@@ -4090,19 +4098,26 @@ function buildContextAccessor(context2, adapters, contextMethod, onCall) {
4090
4098
  if (typeof ctxFn !== "function")
4091
4099
  continue;
4092
4100
  const methods = ctxFn.call(element2, adapters);
4093
- if (!methods || typeof methods !== "object")
4101
+ if (!methods)
4102
+ continue;
4103
+ const elementName = element2.name;
4104
+ if (typeof methods === "function") {
4105
+ result[elementName] = (...args) => onCall({ element: elementName, method: "", args }, () => methods(...args));
4106
+ continue;
4107
+ }
4108
+ if (typeof methods !== "object")
4094
4109
  continue;
4095
4110
  const wrapped = {};
4096
4111
  for (const [methodName, method] of Object.entries(methods)) {
4097
4112
  if (typeof method !== "function")
4098
4113
  continue;
4099
- wrapped[methodName] = (...args) => onCall({ element: element2.name, method: methodName, args }, () => method(...args));
4114
+ wrapped[methodName] = (...args) => onCall({ element: elementName, method: methodName, args }, () => method(...args));
4100
4115
  }
4101
- result[element2.name] = wrapped;
4116
+ result[elementName] = wrapped;
4102
4117
  }
4103
4118
  return result;
4104
4119
  }
4105
- function executeDescriptor(descriptor, context2, adapters, contextMethod) {
4120
+ function executeDescriptor(descriptor, context2, adapters, contextMethod, options) {
4106
4121
  const element2 = context2.get(descriptor.element);
4107
4122
  if (!element2) {
4108
4123
  throw new Error(`Element '${descriptor.element}' not found in context`);
@@ -4112,10 +4127,19 @@ function executeDescriptor(descriptor, context2, adapters, contextMethod) {
4112
4127
  throw new Error(`Element '${descriptor.element}' has no ${contextMethod}`);
4113
4128
  }
4114
4129
  const methods = ctxFn.call(element2, adapters);
4130
+ if (typeof methods === "function") {
4131
+ if (options?.fromWire && methods.__isPrivate) {
4132
+ throw new Error(`Element "${descriptor.element}" is private and not callable from a client.`);
4133
+ }
4134
+ return methods(...descriptor.args);
4135
+ }
4115
4136
  const method = methods?.[descriptor.method];
4116
4137
  if (typeof method !== "function") {
4117
4138
  throw new Error(`Method '${descriptor.method}' not found on '${descriptor.element}'`);
4118
4139
  }
4140
+ if (options?.fromWire && method.__isPrivate) {
4141
+ throw new Error(`Method "${descriptor.element}.${descriptor.method}" is private and not callable from a client.`);
4142
+ }
4119
4143
  return method(...descriptor.args);
4120
4144
  }
4121
4145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
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.6"
23
+ "@arcote.tech/arc": "^0.7.8"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"