apps 0.0.1-beta.93 → 0.0.1-beta.94

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/js/index.js CHANGED
@@ -139,6 +139,31 @@ var decoderDocument = (decoder) => {
139
139
  const document = Schema_exports.toJsonSchemaDocument(decoder);
140
140
  return Schema_exports.decodeUnknownSync(JsonObject)({ ...document.schema, $defs: document.definitions });
141
141
  };
142
+ var accountBranches = (variants) => {
143
+ const groups = /* @__PURE__ */ new Map();
144
+ for (const [accountId, schema] of variants) {
145
+ const key = JSON.stringify(schema);
146
+ const group = groups.get(key);
147
+ if (group === void 0) groups.set(key, { schema, first: accountId, rest: [] });
148
+ else group.rest.push(accountId);
149
+ }
150
+ return {
151
+ type: "object",
152
+ anyOf: [...groups.values()].map(({ schema, first, rest }, index) => ({
153
+ type: "object",
154
+ properties: {
155
+ accountId: rest.length === 0 ? { type: "string", const: first } : { type: "string", enum: [first, ...rest] },
156
+ input: nestJsonSchema(schema, `#/anyOf/${index}/properties/input`)
157
+ },
158
+ required: ["accountId", "input"]
159
+ }))
160
+ };
161
+ };
162
+ var outputBranches = (outputs) => ({
163
+ anyOf: [...new Map(outputs.map((output) => [JSON.stringify(output), output])).values()].map(
164
+ (output, index) => nestJsonSchema(output, `#/anyOf/${index}`)
165
+ )
166
+ });
142
167
  var declaresOutput = (operation) => {
143
168
  if (operation.output !== void 0) return true;
144
169
  const property = Object.getOwnPropertyDescriptor(operation, "outputSchema");
@@ -161,20 +186,9 @@ var combineOperation = (accounts) => {
161
186
  ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
162
187
  )
163
188
  );
164
- const inputSchema = () => ({
165
- type: "object",
166
- anyOf: [...accounts].map(([accountId, operation], index) => ({
167
- type: "object",
168
- properties: {
169
- accountId: { type: "string", const: accountId },
170
- input: nestJsonSchema(
171
- decoderDocument(operation.input),
172
- `#/anyOf/${index}/properties/input`
173
- )
174
- },
175
- required: ["accountId", "input"]
176
- }))
177
- });
189
+ const inputSchema = () => accountBranches(
190
+ [...accounts].map(([accountId, operation]) => [accountId, decoderDocument(operation.input)])
191
+ );
178
192
  const declaration2 = operationDeclaration({
179
193
  kind,
180
194
  ...first.description === void 0 ? {} : { description: first.description },
@@ -199,12 +213,14 @@ var combineOperation = (accounts) => {
199
213
  }
200
214
  });
201
215
  if (variants.every(declaresOutput)) {
202
- const outputSchema = once(() => ({
203
- anyOf: variants.flatMap((operation) => {
204
- const output = outputDocument(operation);
205
- return output === void 0 ? [] : [output];
206
- }).map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
207
- }));
216
+ const outputSchema = once(
217
+ () => outputBranches(
218
+ variants.flatMap((operation) => {
219
+ const output = outputDocument(operation);
220
+ return output === void 0 ? [] : [output];
221
+ })
222
+ )
223
+ );
208
224
  const native2 = nativeOperation(declaration2);
209
225
  if (native2 !== void 0)
210
226
  Object.defineProperty(native2, "outputSchema", { enumerable: true, get: outputSchema });
@@ -230,23 +246,15 @@ var mergeSummary = (name, variants) => {
230
246
  };
231
247
  var merge = (name, variants) => Schema_exports.decodeUnknownSync(HostedTool)({
232
248
  ...mergeSummary(name, variants),
233
- inputSchema: {
234
- type: "object",
235
- anyOf: variants.map(([accountId, tool], index) => ({
236
- type: "object",
237
- properties: {
238
- accountId: { type: "string", const: accountId },
239
- input: nestJsonSchema(tool.inputSchema, `#/anyOf/${index}/properties/input`)
240
- },
241
- required: ["accountId", "input"]
242
- }))
243
- },
249
+ inputSchema: accountBranches(
250
+ variants.map(([accountId, tool]) => [accountId, tool.inputSchema])
251
+ ),
244
252
  ...variants.every(([, tool]) => tool.outputSchema !== void 0) ? {
245
- outputSchema: {
246
- anyOf: variants.flatMap(
247
- ([, tool], index) => tool.outputSchema === void 0 ? [] : [nestJsonSchema(tool.outputSchema, `#/anyOf/${index}`)]
253
+ outputSchema: outputBranches(
254
+ variants.flatMap(
255
+ ([, tool]) => tool.outputSchema === void 0 ? [] : [tool.outputSchema]
248
256
  )
249
- }
257
+ )
250
258
  } : {},
251
259
  ...sameAcross("_meta", variants)
252
260
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps",
3
- "version": "0.0.1-beta.93",
3
+ "version": "0.0.1-beta.94",
4
4
  "description": "TypeScript apps with typed tools, accounts, storage, and UI.",
5
5
  "type": "module",
6
6
  "sideEffects": false,