@object-ui/data-objectstack 17.6.0 → 17.7.0
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/CHANGELOG.md +2092 -0
- package/README.md +557 -11
- package/dist/index.cjs +1419 -124
- package/dist/index.d.cts +1423 -98
- package/dist/index.d.ts +1423 -98
- package/dist/index.js +1408 -125
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -4,6 +4,71 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { ObjectStackClient } from "@objectstack/client";
|
|
7
|
+
import { VIEW_CONSOLE_ROUND_TRIP_KEYS } from "@objectstack/spec/ui";
|
|
8
|
+
import { DroppedFieldsEventSchema } from "@objectstack/spec/data";
|
|
9
|
+
import { isFilterAST, parseFilterAST } from "@objectstack/spec/data";
|
|
10
|
+
import { isRefusedTextComparand as isRefusedTextComparand2, textComparandRefusalReason as textComparandRefusalReason2 } from "@objectstack/spec/data";
|
|
11
|
+
import { stripReadDecorations as stripReadDecorations2 } from "@objectstack/spec/kernel";
|
|
12
|
+
|
|
13
|
+
// src/metadata-client.ts
|
|
14
|
+
import { GetMetaItemLayeredResponseSchema } from "@objectstack/spec/api";
|
|
15
|
+
|
|
16
|
+
// src/object-metadata-write-guard.ts
|
|
17
|
+
var RELATIONSHIP_TYPES_REQUIRING_REFERENCE = ["lookup", "master_detail"];
|
|
18
|
+
var CHOICE_TYPES_REQUIRING_OPTIONS = ["select", "radio"];
|
|
19
|
+
var OBJECT_METADATA_TYPE = "object";
|
|
20
|
+
function isUsableTarget(reference) {
|
|
21
|
+
return typeof reference === "string" && reference.trim() !== "";
|
|
22
|
+
}
|
|
23
|
+
function describeTarget(reference) {
|
|
24
|
+
if (reference === void 0) return "no `reference` key at all";
|
|
25
|
+
if (reference === null) return "a `null` `reference`";
|
|
26
|
+
if (typeof reference !== "string") return `a \`reference\` of type \`${typeof reference}\``;
|
|
27
|
+
if (reference === "") return "an empty `reference`";
|
|
28
|
+
return "a whitespace-only `reference`";
|
|
29
|
+
}
|
|
30
|
+
function hasOptionSource(def) {
|
|
31
|
+
return Array.isArray(def.options) && def.options.length > 0 || typeof def.picklist === "string";
|
|
32
|
+
}
|
|
33
|
+
function describeOptions(options) {
|
|
34
|
+
if (options === void 0) return "no `options` key and no `picklist`";
|
|
35
|
+
if (Array.isArray(options)) return "an empty `options` list and no `picklist`";
|
|
36
|
+
if (options === null) return "a `null` `options` and no `picklist`";
|
|
37
|
+
return `an \`options\` value of type \`${typeof options}\` and no \`picklist\``;
|
|
38
|
+
}
|
|
39
|
+
function fieldEntries(fields) {
|
|
40
|
+
if (Array.isArray(fields)) {
|
|
41
|
+
return fields.flatMap((raw, index) => {
|
|
42
|
+
if (!raw || typeof raw !== "object") return [];
|
|
43
|
+
const record = raw;
|
|
44
|
+
const name = typeof record.name === "string" && record.name ? record.name : `[${index}]`;
|
|
45
|
+
return [{ name, def: record }];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (fields && typeof fields === "object") {
|
|
49
|
+
return Object.entries(fields).flatMap(
|
|
50
|
+
([name, def]) => def && typeof def === "object" ? [{ name, def }] : []
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
function assertObjectMetadataWritable(type, item, writer) {
|
|
56
|
+
if (String(type) !== OBJECT_METADATA_TYPE) return;
|
|
57
|
+
if (!item || typeof item !== "object") return;
|
|
58
|
+
const fields = item.fields;
|
|
59
|
+
for (const { name, def } of fieldEntries(fields)) {
|
|
60
|
+
if (CHOICE_TYPES_REQUIRING_OPTIONS.includes(String(def.type)) && !hasOptionSource(def)) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`${writer} refused this object metadata write: the field \`${name}\` is a \`${String(def.type)}\` with no options: it carries ${describeOptions(def.options)}, so it offers nothing to choose and nothing to check a stored value against. A choice field needs at least one option or a shared \`picklist\` (objectstack#20827), so this draft stays here until it has one. Add an option, or change the field to a non-choice type.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (!RELATIONSHIP_TYPES_REQUIRING_REFERENCE.includes(String(def.type))) continue;
|
|
66
|
+
if (isUsableTarget(def.reference)) continue;
|
|
67
|
+
throw new Error(
|
|
68
|
+
`${writer} refused this object metadata write: the field \`${name}\` is a \`${String(def.type)}\` and carries ${describeTarget(def.reference)}, so it names no object to link to. \`@objectstack/spec\` refuses the same document at the server with a 422 on \`fields.${name}.reference\`, and that refusal blocks every later save of this object for as long as the half-filled field rides along in the draft (objectui#7714). Pick the target object, or change the field to a non-relationship type.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
7
72
|
|
|
8
73
|
// src/metadata-client.ts
|
|
9
74
|
function readSaveAdvisories(body) {
|
|
@@ -16,6 +81,25 @@ function readSaveAdvisories(body) {
|
|
|
16
81
|
return typeof c.rule === "string" && typeof c.path === "string" && typeof c.where === "string" && typeof c.message === "string" && typeof c.hint === "string" && typeof c.severity === "string";
|
|
17
82
|
});
|
|
18
83
|
}
|
|
84
|
+
var PROTECTION_ENVELOPE_KEYS = [
|
|
85
|
+
"overlayScope",
|
|
86
|
+
"lock",
|
|
87
|
+
"lockReason",
|
|
88
|
+
"lockSource",
|
|
89
|
+
"lockDocsUrl",
|
|
90
|
+
"provenance",
|
|
91
|
+
"packageId",
|
|
92
|
+
"packageVersion",
|
|
93
|
+
"editable",
|
|
94
|
+
"deletable",
|
|
95
|
+
"resettable"
|
|
96
|
+
];
|
|
97
|
+
function unrecognizedEnvelopeKeys(body) {
|
|
98
|
+
const shape = GetMetaItemLayeredResponseSchema.shape;
|
|
99
|
+
return PROTECTION_ENVELOPE_KEYS.filter(
|
|
100
|
+
(key) => body[key] !== void 0 && !shape[key].safeParse(body[key]).success
|
|
101
|
+
);
|
|
102
|
+
}
|
|
19
103
|
var META_PREFIX = "/meta";
|
|
20
104
|
var API_PREFIX = "/api/v1";
|
|
21
105
|
function buildBase(config) {
|
|
@@ -28,6 +112,16 @@ function buildBase(config) {
|
|
|
28
112
|
}
|
|
29
113
|
return `${trimmed}${scoped}`;
|
|
30
114
|
}
|
|
115
|
+
function packagesBaseOf(metaBase) {
|
|
116
|
+
const origin = metaBase.replace(/\/api\/v\d+(?:\/environments\/[^/]+)?\/meta$/, "").replace(/\/+$/, "");
|
|
117
|
+
return `${origin}${API_PREFIX}/packages`;
|
|
118
|
+
}
|
|
119
|
+
function unwrapDispatcherEnvelope(body) {
|
|
120
|
+
if (!body || typeof body !== "object") return {};
|
|
121
|
+
const root = body;
|
|
122
|
+
const data = root.data;
|
|
123
|
+
return data && typeof data === "object" && !Array.isArray(data) ? data : root;
|
|
124
|
+
}
|
|
31
125
|
async function parseError(res) {
|
|
32
126
|
let body;
|
|
33
127
|
try {
|
|
@@ -60,7 +154,7 @@ var MetadataClient = class _MetadataClient {
|
|
|
60
154
|
__publicField(this, "headers");
|
|
61
155
|
/** ADR-0037: when true, reads render the draft-overlaid world. */
|
|
62
156
|
__publicField(this, "previewDrafts");
|
|
63
|
-
/** #4133 — sink for
|
|
157
|
+
/** #4133 / #5026 — sink for every write door's advisory findings; see the config field. */
|
|
64
158
|
__publicField(this, "onSaveAdvisory");
|
|
65
159
|
this.base = buildBase(config);
|
|
66
160
|
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
@@ -214,8 +308,20 @@ var MetadataClient = class _MetadataClient {
|
|
|
214
308
|
* {@link get} is deliberate and long-standing (the draft envelope's identity
|
|
215
309
|
* and protection carriers are part of what a draft reader inspects), so it
|
|
216
310
|
* is preserved by reading the transport directly instead of going through
|
|
217
|
-
* `get()`'s unwrap.
|
|
218
|
-
*
|
|
311
|
+
* `get()`'s unwrap.
|
|
312
|
+
*
|
|
313
|
+
* ⛔ Do NOT hand `.item` to a gate or a write yourself: the body this serves
|
|
314
|
+
* is DECORATED (`_draft`, then `_diagnostics` from `decorateMetadataItem`),
|
|
315
|
+
* and the spec says a served body is not a valid input to the schema that
|
|
316
|
+
* produced it until those come off. {@link extractDraftBody} is the one
|
|
317
|
+
* reader for this method's answer — it takes the presence verdict and then
|
|
318
|
+
* the strip, in that order. That function used to be copy-pasted into four
|
|
319
|
+
* views and only one copy knew the rule (objectui#8181).
|
|
320
|
+
*
|
|
321
|
+
* Its tolerant siblings exist for the OTHER client method: `unwrapDraftBody`
|
|
322
|
+
* (app-shell) and `unwrapViewDraft` (this package) read a draft that arrived
|
|
323
|
+
* through {@link get}, which already unwrapped the envelope. They split on
|
|
324
|
+
* which method feeds them, not on what they mean — all three strip.
|
|
219
325
|
*/
|
|
220
326
|
async getDraft(type, name, options = {}) {
|
|
221
327
|
return this.readItemResponse(type, name, {
|
|
@@ -223,6 +329,31 @@ var MetadataClient = class _MetadataClient {
|
|
|
223
329
|
...options.packageId ? { packageId: options.packageId } : {}
|
|
224
330
|
});
|
|
225
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Report the runtime authoring gate's advisory findings for a write the
|
|
334
|
+
* server has ALREADY committed (#4133 for the save door, #5026 for the
|
|
335
|
+
* publish door).
|
|
336
|
+
*
|
|
337
|
+
* Everything here is best-effort by construction, and that is the whole
|
|
338
|
+
* contract: the row is committed server-side before this runs, so neither a
|
|
339
|
+
* malformed body, nor a missing key, nor a throwing sink may change what the
|
|
340
|
+
* calling method returns or whether it throws. The server emits `advisories`
|
|
341
|
+
* ONLY when non-empty, so a clean write costs one absent-key check.
|
|
342
|
+
*
|
|
343
|
+
* One helper rather than a copy per door: every door's response declares the
|
|
344
|
+
* key identically, so a second inline copy could only ever drift. The batch
|
|
345
|
+
* door (`ce986aafc`) calls it once per `published[]` element, handing it
|
|
346
|
+
* the element — the object that carries the key there — and the same
|
|
347
|
+
* best-effort contract covers that loop unchanged.
|
|
348
|
+
*/
|
|
349
|
+
emitAdvisories(body, event) {
|
|
350
|
+
if (!this.onSaveAdvisory) return;
|
|
351
|
+
try {
|
|
352
|
+
const advisories = readSaveAdvisories(body);
|
|
353
|
+
if (advisories.length > 0) this.onSaveAdvisory({ ...event, advisories });
|
|
354
|
+
} catch {
|
|
355
|
+
}
|
|
356
|
+
}
|
|
226
357
|
/**
|
|
227
358
|
* Save (PUT) a metadata item. The framework accepts both the bare
|
|
228
359
|
* item payload and the `{ item: ... }` / `{ metadata: ... }`
|
|
@@ -235,6 +366,7 @@ var MetadataClient = class _MetadataClient {
|
|
|
235
366
|
`MetadataClient.save: name must be non-empty (type="${type}"). The PUT /meta/:type/:name route requires a name segment.`
|
|
236
367
|
);
|
|
237
368
|
}
|
|
369
|
+
assertObjectMetadataWritable(type, item, "MetadataClient.save");
|
|
238
370
|
const params = [];
|
|
239
371
|
if (options.force) params.push("force=true");
|
|
240
372
|
if (options.mode === "draft") params.push("mode=draft");
|
|
@@ -253,20 +385,12 @@ var MetadataClient = class _MetadataClient {
|
|
|
253
385
|
});
|
|
254
386
|
if (!res.ok) throw await parseError(res);
|
|
255
387
|
const body = await res.json();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
name,
|
|
263
|
-
mode: options.mode === "draft" ? "draft" : "publish",
|
|
264
|
-
advisories
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
} catch {
|
|
268
|
-
}
|
|
269
|
-
}
|
|
388
|
+
this.emitAdvisories(body, {
|
|
389
|
+
type,
|
|
390
|
+
name,
|
|
391
|
+
door: "save",
|
|
392
|
+
mode: options.mode === "draft" ? "draft" : "publish"
|
|
393
|
+
});
|
|
270
394
|
return body;
|
|
271
395
|
}
|
|
272
396
|
/**
|
|
@@ -280,6 +404,61 @@ var MetadataClient = class _MetadataClient {
|
|
|
280
404
|
* the rows and reports under `seedApplied` — a data problem never fails the
|
|
281
405
|
* publish, so callers should check `seedApplied?.success` and warn the user
|
|
282
406
|
* rather than assume the data went live.
|
|
407
|
+
*
|
|
408
|
+
* Same door as {@link publish} (`POST /meta/:type/:name/publish`), so it
|
|
409
|
+
* reports the gate's advisories the same way (#5026).
|
|
410
|
+
*
|
|
411
|
+
* The BATCH door (`POST /packages/:id/publish-drafts`) is a different route
|
|
412
|
+
* with a method of its own — {@link publishPackageDrafts} — and it reports
|
|
413
|
+
* too. It did not when this paragraph was first written: it discarded
|
|
414
|
+
* per-draft advisories server-side, which was objectstack#9343, and that card
|
|
415
|
+
* has since landed with a ruling that each `published[]` element carries
|
|
416
|
+
* them (`ce986aafc` is the client half).
|
|
417
|
+
*
|
|
418
|
+
* What survives that change is the READING RULE, which is about this method
|
|
419
|
+
* rather than about the other route: it reads the top level of the
|
|
420
|
+
* single-item body and nothing else. A batch-shaped body arriving HERE still
|
|
421
|
+
* reports nothing, because `PublishMetaItemResponse` declares no
|
|
422
|
+
* `published[]` and a client that went looking for findings wherever they
|
|
423
|
+
* might be would be inventing a contract instead of reading one.
|
|
424
|
+
*
|
|
425
|
+
* ## Why there is no `{ success, data }` unwrapping here (`7b433197d`)
|
|
426
|
+
*
|
|
427
|
+
* This method used to unwrap a dispatcher-shaped envelope before returning,
|
|
428
|
+
* while {@link publish} — the same route, a couple of hundred lines down —
|
|
429
|
+
* did not. Two spellings of one wire contract, and nothing said which was
|
|
430
|
+
* right. The tolerance is gone because the route was MEASURED, at the
|
|
431
|
+
* producer rather than inferred from the response schema:
|
|
432
|
+
*
|
|
433
|
+
* - The only mount of `POST /api/v1/meta/:type/:name/publish` is the REST
|
|
434
|
+
* server's own route-manager registration, which answers
|
|
435
|
+
* `res.json(await protocol.publishMetaItem(...))` — the protocol's object
|
|
436
|
+
* verbatim, with no envelope branch. The project-scoped mirror
|
|
437
|
+
* (`/api/v1/environments/:environmentId/...`) re-mounts that same handler.
|
|
438
|
+
* - The `{ success, data }` envelope has exactly one producer, the runtime
|
|
439
|
+
* `HttpDispatcher`, and it does not serve this route: its `/meta` domain
|
|
440
|
+
* has no publish branch, the dispatcher's own route ledger has no row for
|
|
441
|
+
* it, and a three-segment `/meta` path that is not `/published` terminates
|
|
442
|
+
* in a located `routeNotFound`. So no composition — REST server, the
|
|
443
|
+
* dispatcher-only Hono adapter, or both — puts an envelope on this body.
|
|
444
|
+
* - `packages/spec` states the same split in the two docstrings side by
|
|
445
|
+
* side: `PublishMetaItemResponseSchema` describes "the FULL body" this
|
|
446
|
+
* route returns and records that the REST route hands the producer's
|
|
447
|
+
* object to `res.json()` verbatim, while its batch sibling
|
|
448
|
+
* `PublishPackageDraftsResponseSchema` describes a body answered
|
|
449
|
+
* explicitly "inside the dispatcher's `{ success, data }` envelope".
|
|
450
|
+
*
|
|
451
|
+
* ⛔ So an enveloped body on THIS route is not a shape the platform emits,
|
|
452
|
+
* and unwrapping one is not a kindness: it is Commandment #0.1's lenient
|
|
453
|
+
* fallback, a second de-facto contract for a route that declares one. It
|
|
454
|
+
* also fails in the direction that hides the problem — a body that arrived
|
|
455
|
+
* enveloped is one this door did not actually serve, and unwrapping it
|
|
456
|
+
* would present that as a successful promotion.
|
|
457
|
+
*
|
|
458
|
+
* ⚠️ Sibling tolerances in this file are NOT this defect and must stay:
|
|
459
|
+
* {@link listDrafts} reads `data?.data?.drafts` because `GET /meta/_drafts`
|
|
460
|
+
* IS a dispatcher route, and `publishHealthFromResponse` unwraps because the
|
|
461
|
+
* batch door really is enveloped. The rule is per-route, not per-file.
|
|
283
462
|
*/
|
|
284
463
|
async publishDraft(type, name) {
|
|
285
464
|
const url = `${this.base}/${encodeURIComponent(type)}/${encodeURIComponent(name)}/publish`;
|
|
@@ -290,8 +469,80 @@ var MetadataClient = class _MetadataClient {
|
|
|
290
469
|
});
|
|
291
470
|
if (!res.ok) throw await parseError(res);
|
|
292
471
|
const body = await res.json().catch(() => ({}));
|
|
293
|
-
|
|
294
|
-
return
|
|
472
|
+
this.emitAdvisories(body, { type, name, door: "publish", mode: "publish" });
|
|
473
|
+
return body;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Publish EVERY pending draft bound to one package — Studio's "publish whole
|
|
477
|
+
* app" door, `POST /api/v1/packages/:id/publish-drafts` (ADR-0033; the route
|
|
478
|
+
* that orders structure-before-seeds server-side and runs the ADR-0038 L3
|
|
479
|
+
* runtime probes).
|
|
480
|
+
*
|
|
481
|
+
* ## Why it is expressed here at all (`ce986aafc`)
|
|
482
|
+
*
|
|
483
|
+
* It was not, and that was the defect. Two app-shell call sites fired this
|
|
484
|
+
* route with a bare `fetch` / a page-private `apiJson`, outside the seam that
|
|
485
|
+
* covers every other metadata write — so when objectstack#9343 landed and the
|
|
486
|
+
* server began sending per-draft advisories, the author publishing a whole
|
|
487
|
+
* app was told nothing, while the SAME button's client-side capability lint
|
|
488
|
+
* still raised a toast. A door that cannot report is not a door the gate can
|
|
489
|
+
* reach, however loudly the server speaks.
|
|
490
|
+
*
|
|
491
|
+
* ## What it reports, and what it refuses to invent
|
|
492
|
+
*
|
|
493
|
+
* `PublishPackageDraftsResponseSchema` declares `advisories` on EACH
|
|
494
|
+
* `published[]` element — objectstack#9343's ruled shape, the same element
|
|
495
|
+
* type and the same omitted-when-empty discipline as the single-item door,
|
|
496
|
+
* and explicitly not a parallel top-level map. So this method emits one
|
|
497
|
+
* {@link MetadataSaveAdvisoryEvent} per advised element, each naming that
|
|
498
|
+
* element's own `type` / `name`, through the same sink, event and renderer
|
|
499
|
+
* the save and single-item publish doors use.
|
|
500
|
+
*
|
|
501
|
+
* ⛔ It renders only what the server sent where the schema says it sits:
|
|
502
|
+
*
|
|
503
|
+
* - `advisories` is read off the element, by the one shared reader, which
|
|
504
|
+
* drops anything that is not a complete finding.
|
|
505
|
+
* - An element that does not carry the `type` and `name` the schema states as
|
|
506
|
+
* REQUIRED is skipped rather than reported under invented identity — the
|
|
507
|
+
* event names the item the author has to go fix, and an event that cannot
|
|
508
|
+
* name it truthfully is worse than silence.
|
|
509
|
+
* - Nothing is derived, counted or summarised from the batch: no advisory
|
|
510
|
+
* exists here that the server did not put in the body.
|
|
511
|
+
*
|
|
512
|
+
* ## The failure shapes stay the callers'
|
|
513
|
+
*
|
|
514
|
+
* Non-2xx throws {@link MetadataError}, like every other method. A 2xx is
|
|
515
|
+
* RETURNED unexamined — `success: false` is not a failure on this route
|
|
516
|
+
* (`outcome: 'nothing_to_publish'` answers it too, and the spec's own text
|
|
517
|
+
* says to read `outcome`, not the boolean), and the two callers have their
|
|
518
|
+
* own, different rules for the refusal and rolled-back cases. Deciding that
|
|
519
|
+
* here would change behaviour this card is not about.
|
|
520
|
+
*/
|
|
521
|
+
async publishPackageDrafts(packageId) {
|
|
522
|
+
if (!packageId || !String(packageId).trim()) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
"MetadataClient.publishPackageDrafts: packageId must be non-empty. The POST /packages/:id/publish-drafts route requires an id segment."
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
const url = `${packagesBaseOf(this.base)}/${encodeURIComponent(packageId)}/publish-drafts`;
|
|
528
|
+
const res = await this.fetchImpl(url, {
|
|
529
|
+
method: "POST",
|
|
530
|
+
// Both call sites this replaces sent the session cookie, and the client's
|
|
531
|
+
// own fetch adds the console's Bearer token — so the routed call carries a
|
|
532
|
+
// superset of what the bare doors carried, never less.
|
|
533
|
+
credentials: "include",
|
|
534
|
+
headers: { ...this.headers, "Content-Type": "application/json", Accept: "application/json" },
|
|
535
|
+
body: "{}"
|
|
536
|
+
});
|
|
537
|
+
if (!res.ok) throw await parseError(res);
|
|
538
|
+
const body = unwrapDispatcherEnvelope(await res.json().catch(() => ({})));
|
|
539
|
+
for (const element of Array.isArray(body.published) ? body.published : []) {
|
|
540
|
+
if (!element || typeof element !== "object") continue;
|
|
541
|
+
const { type, name } = element;
|
|
542
|
+
if (typeof type !== "string" || typeof name !== "string") continue;
|
|
543
|
+
this.emitAdvisories(element, { type, name, door: "publish", mode: "publish" });
|
|
544
|
+
}
|
|
545
|
+
return body;
|
|
295
546
|
}
|
|
296
547
|
/**
|
|
297
548
|
* Get the 3-state layered view of a metadata item: `code` (the packaged
|
|
@@ -333,7 +584,7 @@ var MetadataClient = class _MetadataClient {
|
|
|
333
584
|
}
|
|
334
585
|
if (!res.ok) throw await parseError(res);
|
|
335
586
|
const body = await res.json();
|
|
336
|
-
const hasEnvelope = body && ("code" in body || "overlay" in body || "effective" in body);
|
|
587
|
+
const hasEnvelope = typeof body === "object" && body !== null && ("code" in body || "overlay" in body || "effective" in body);
|
|
337
588
|
if (!hasEnvelope) {
|
|
338
589
|
return {
|
|
339
590
|
code: null,
|
|
@@ -342,14 +593,34 @@ var MetadataClient = class _MetadataClient {
|
|
|
342
593
|
effective: body
|
|
343
594
|
};
|
|
344
595
|
}
|
|
596
|
+
const parsed = GetMetaItemLayeredResponseSchema.safeParse(body);
|
|
597
|
+
if (parsed.success) {
|
|
598
|
+
const envelope = parsed.data;
|
|
599
|
+
return {
|
|
600
|
+
code: envelope.code ?? null,
|
|
601
|
+
overlay: envelope.overlay ?? null,
|
|
602
|
+
overlayScope: envelope.overlayScope,
|
|
603
|
+
effective: envelope.effective ?? null,
|
|
604
|
+
...body._diagnostics ? { _diagnostics: body._diagnostics } : {},
|
|
605
|
+
lock: envelope.lock,
|
|
606
|
+
...envelope.lockReason !== void 0 ? { lockReason: envelope.lockReason } : {},
|
|
607
|
+
...envelope.lockSource !== void 0 ? { lockSource: envelope.lockSource } : {},
|
|
608
|
+
...envelope.lockDocsUrl !== void 0 ? { lockDocsUrl: envelope.lockDocsUrl } : {},
|
|
609
|
+
...envelope.provenance !== void 0 ? { provenance: envelope.provenance } : {},
|
|
610
|
+
...envelope.packageId !== void 0 ? { packageId: envelope.packageId } : {},
|
|
611
|
+
...envelope.packageVersion !== void 0 ? { packageVersion: envelope.packageVersion } : {},
|
|
612
|
+
editable: envelope.editable,
|
|
613
|
+
deletable: envelope.deletable,
|
|
614
|
+
resettable: envelope.resettable
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
const unrecognized = unrecognizedEnvelopeKeys(body);
|
|
345
618
|
return {
|
|
346
619
|
code: body.code ?? null,
|
|
347
620
|
overlay: body.overlay ?? null,
|
|
348
621
|
overlayScope: body.overlayScope ?? null,
|
|
349
622
|
effective: body.effective ?? null,
|
|
350
623
|
...body._diagnostics ? { _diagnostics: body._diagnostics } : {},
|
|
351
|
-
// ADR-0010 Phase 4 — pass through the metadata-protection envelope so
|
|
352
|
-
// the editor can render lock affordances without a second round trip.
|
|
353
624
|
...body.lock !== void 0 ? { lock: body.lock } : {},
|
|
354
625
|
...body.lockReason !== void 0 ? { lockReason: body.lockReason } : {},
|
|
355
626
|
...body.lockSource !== void 0 ? { lockSource: body.lockSource } : {},
|
|
@@ -359,7 +630,8 @@ var MetadataClient = class _MetadataClient {
|
|
|
359
630
|
...body.packageVersion !== void 0 ? { packageVersion: body.packageVersion } : {},
|
|
360
631
|
...body.editable !== void 0 ? { editable: body.editable } : {},
|
|
361
632
|
...body.deletable !== void 0 ? { deletable: body.deletable } : {},
|
|
362
|
-
...body.resettable !== void 0 ? { resettable: body.resettable } : {}
|
|
633
|
+
...body.resettable !== void 0 ? { resettable: body.resettable } : {},
|
|
634
|
+
...unrecognized.length > 0 ? { _unrecognized: unrecognized } : {}
|
|
363
635
|
};
|
|
364
636
|
}
|
|
365
637
|
/**
|
|
@@ -426,9 +698,16 @@ var MetadataClient = class _MetadataClient {
|
|
|
426
698
|
* `{ success, version, seq, message }`. Throws a `404 no_draft` if
|
|
427
699
|
* nothing is pending and `409 metadata_conflict` if the published
|
|
428
700
|
* overlay moved while the draft was sitting.
|
|
701
|
+
*
|
|
702
|
+
* Reports the runtime authoring gate's advisory findings through
|
|
703
|
+
* {@link MetadataClientConfig.onSaveAdvisory} when the response carries them
|
|
704
|
+
* (#5026 / objectstack#9176), with `door: 'publish'`. This is the door the
|
|
705
|
+
* Studio designer takes on every edit, so it is the one whose findings an
|
|
706
|
+
* author actually sees.
|
|
429
707
|
*/
|
|
430
708
|
async publish(type, name, options = {}) {
|
|
431
|
-
const
|
|
709
|
+
const qs = options.packageId ? `?package=${encodeURIComponent(options.packageId)}` : "";
|
|
710
|
+
const url = `${this.base}/${encodeURIComponent(type)}/${encodeURIComponent(name)}/publish${qs}`;
|
|
432
711
|
const headers = {
|
|
433
712
|
...this.headers,
|
|
434
713
|
"Content-Type": "application/json"
|
|
@@ -439,7 +718,9 @@ var MetadataClient = class _MetadataClient {
|
|
|
439
718
|
body: JSON.stringify(options.message ? { message: options.message } : {})
|
|
440
719
|
});
|
|
441
720
|
if (!res.ok) throw await parseError(res);
|
|
442
|
-
|
|
721
|
+
const body = await res.json();
|
|
722
|
+
this.emitAdvisories(body, { type, name, door: "publish", mode: "publish" });
|
|
723
|
+
return body;
|
|
443
724
|
}
|
|
444
725
|
/**
|
|
445
726
|
* Restore an item to a previous version (POST `/meta/:type/:name/rollback`).
|
|
@@ -534,15 +815,38 @@ function errorCodeIsAnyOf(err, codes) {
|
|
|
534
815
|
}
|
|
535
816
|
|
|
536
817
|
// ../core/src/utils/filter-converter.ts
|
|
537
|
-
import {
|
|
818
|
+
import {
|
|
819
|
+
normalizeFilterOperator,
|
|
820
|
+
VIEW_FILTER_OPERATORS,
|
|
821
|
+
VIEW_FILTER_LIST_VALUE_OPERATORS,
|
|
822
|
+
VIEW_FILTER_PAIR_VALUE_OPERATORS
|
|
823
|
+
} from "@objectstack/spec/ui";
|
|
824
|
+
import { isAcceptedFilterComparand, ACCEPTED_FILTER_COMPARAND_TYPES_SENTENCE } from "@objectstack/spec/data";
|
|
825
|
+
|
|
826
|
+
// ../core/src/utils/text-comparand.ts
|
|
827
|
+
import { isRefusedTextComparand, textComparandRefusalReason } from "@objectstack/spec/data";
|
|
828
|
+
|
|
829
|
+
// ../core/src/utils/filter-converter.ts
|
|
538
830
|
var FilterOperatorError = class extends Error {
|
|
539
|
-
constructor(message) {
|
|
831
|
+
constructor(message, subject) {
|
|
540
832
|
super(message);
|
|
541
833
|
__publicField(this, "code", "INVALID_FILTER");
|
|
542
834
|
__publicField(this, "httpStatus", 400);
|
|
835
|
+
/** @see FilterRefusalSubject */
|
|
836
|
+
__publicField(this, "operator");
|
|
837
|
+
/** @see FilterRefusalSubject */
|
|
838
|
+
__publicField(this, "field");
|
|
543
839
|
this.name = "FilterOperatorError";
|
|
840
|
+
this.operator = subject?.operator;
|
|
841
|
+
this.field = subject?.field;
|
|
544
842
|
}
|
|
545
843
|
};
|
|
844
|
+
var RETIRED_OPERATOR_ALIASES = {
|
|
845
|
+
"$notin": "$nin",
|
|
846
|
+
"$notcontains": "$notContains",
|
|
847
|
+
"$startswith": "$startsWith",
|
|
848
|
+
"$endswith": "$endsWith"
|
|
849
|
+
};
|
|
546
850
|
function convertOperatorToAST(operator) {
|
|
547
851
|
const operatorMap = {
|
|
548
852
|
"$eq": "=",
|
|
@@ -553,27 +857,148 @@ function convertOperatorToAST(operator) {
|
|
|
553
857
|
"$lte": "<=",
|
|
554
858
|
"$in": "in",
|
|
555
859
|
"$nin": "nin",
|
|
556
|
-
"$notin": "nin",
|
|
557
860
|
"$between": "between",
|
|
558
861
|
"$contains": "contains",
|
|
559
862
|
"$notContains": "notcontains",
|
|
560
|
-
"$notcontains": "notcontains",
|
|
561
863
|
"$startsWith": "startswith",
|
|
562
|
-
"$startswith": "startswith",
|
|
563
864
|
"$endsWith": "endswith",
|
|
564
|
-
|
|
865
|
+
// Case-insensitive contains. A canonical `FILTER_OPERATORS` member that
|
|
866
|
+
// `ValueDataSource` executes and `FilterConditionField` emits (for its
|
|
867
|
+
// `icontains` builder row — spelled `containsCaseInsensitive` until
|
|
868
|
+
// objectui#9306), while this map refused it with the
|
|
869
|
+
// generic unknown-operator paragraph — so ONE authored filter selected rows
|
|
870
|
+
// through the in-memory matcher and 400'd on the ObjectStack lowering path
|
|
871
|
+
// (objectui#8976). The other direction of the same split objectui#8568 fixed:
|
|
872
|
+
// there the map was MORE tolerant than the matcher, here it was LESS tolerant
|
|
873
|
+
// than the contract. Restored by aligning the map with the spec, per AGENTS.md
|
|
874
|
+
// #0 — not by removing the operator from the builder, which the spec declares.
|
|
875
|
+
//
|
|
876
|
+
// The VALUE is an IDENTITY, and that is not a typo: `icontains` is itself a
|
|
877
|
+
// member of the spec's `VALID_AST_OPERATORS`, so unlike its camelCase siblings
|
|
878
|
+
// above there is no case to squash. Same identity row, for the same stated
|
|
879
|
+
// reason, that `FILTER_OPERATOR_ALIASES` carries in
|
|
880
|
+
// `packages/data-objectstack/src/index.ts`.
|
|
881
|
+
"$icontains": "icontains"
|
|
565
882
|
};
|
|
566
883
|
return operatorMap[operator] || null;
|
|
567
884
|
}
|
|
885
|
+
var AST_LOGIC_KEYWORD = {
|
|
886
|
+
$and: "and",
|
|
887
|
+
$or: "or"
|
|
888
|
+
};
|
|
889
|
+
function lowerLogicalGroup(field, keyword, value) {
|
|
890
|
+
if (!Array.isArray(value)) {
|
|
891
|
+
throw new FilterOperatorError(
|
|
892
|
+
`[ObjectUI] The '${field}' filter combinator takes an ARRAY of conditions. Received ${typeof value === "object" ? "an object" : typeof value}: ${JSON.stringify(value)}. Spec: FilterCondition declares '${field}?: FilterCondition[]' (data/filter.zod.ts).`,
|
|
893
|
+
{ operator: field }
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
if (value.length === 0) {
|
|
897
|
+
return keyword === "and" ? void 0 : falseIdentityLeaf(field, value);
|
|
898
|
+
}
|
|
899
|
+
const children = [];
|
|
900
|
+
let absorbed = false;
|
|
901
|
+
for (const child of value) {
|
|
902
|
+
if (child === null || typeof child !== "object" || Array.isArray(child)) {
|
|
903
|
+
throw new FilterOperatorError(
|
|
904
|
+
`[ObjectUI] Every member of '${field}' must be a filter condition OBJECT. Received ${JSON.stringify(child)}. Spec: FilterCondition declares '${field}?: FilterCondition[]' (data/filter.zod.ts).`,
|
|
905
|
+
{ operator: field }
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
const lowered = convertFiltersToAST(child);
|
|
909
|
+
if (!Array.isArray(lowered)) {
|
|
910
|
+
if (keyword === "or") absorbed = true;
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
children.push(lowered);
|
|
914
|
+
}
|
|
915
|
+
if (absorbed) return void 0;
|
|
916
|
+
if (children.length === 0) return void 0;
|
|
917
|
+
return [keyword, ...children];
|
|
918
|
+
}
|
|
919
|
+
function falseIdentityLeaf(field, value) {
|
|
920
|
+
return [field, "=", value];
|
|
921
|
+
}
|
|
922
|
+
function isOperatorMap(value) {
|
|
923
|
+
const proto = Object.getPrototypeOf(value);
|
|
924
|
+
return proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null;
|
|
925
|
+
}
|
|
926
|
+
function describeExoticComparand(value) {
|
|
927
|
+
let name;
|
|
928
|
+
let text2;
|
|
929
|
+
try {
|
|
930
|
+
const proto = Object.getPrototypeOf(value);
|
|
931
|
+
name = proto?.constructor?.name;
|
|
932
|
+
} catch {
|
|
933
|
+
name = void 0;
|
|
934
|
+
}
|
|
935
|
+
if (typeof name !== "string" || name === "") return "an object of an unrecognised type";
|
|
936
|
+
try {
|
|
937
|
+
text2 = String(value);
|
|
938
|
+
} catch {
|
|
939
|
+
text2 = void 0;
|
|
940
|
+
}
|
|
941
|
+
return text2 && text2 !== `[object ${name}]` ? `a ${name} instance (${text2})` : `a ${name} instance`;
|
|
942
|
+
}
|
|
943
|
+
function refuseTextComparand(field, operator, target) {
|
|
944
|
+
const ported = `It is refused here rather than lowered onto the wire (objectui#9001; ported from ValueDataSource's refuseTextComparand, objectui#8748).`;
|
|
945
|
+
throw new FilterOperatorError(
|
|
946
|
+
`[ObjectUI] The ${textComparandRefusalReason(field, operator, target)}. ${ported}`,
|
|
947
|
+
{ operator, field }
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
function refuseEmptyOperatorMap(field) {
|
|
951
|
+
throw new FilterOperatorError(
|
|
952
|
+
`[ObjectUI] The filter on field '${field}' is an EMPTY operator map \u2014 { ${field}: {} } names the field and no operator. It cannot be lowered: the ObjectQL filter AST has no node for a field with zero operators, and '@objectstack/spec' ruled the shape REJECTED wherever it appears (objectstack#5240, recorded on FilterConditionSchema). It is refused here rather than dropped: beside a key that lowers, the '${field}' condition used to vanish from the filter and silently WIDEN the result set (objectui#10788), and alone it was handed back as the caller's object, which reached the wire as ?${field}=[object Object] on one route and as a filter the server refuses on the other (objectui#9164). Choose an operator \u2014 { ${field}: { $eq: ... } }, { ${field}: { $in: [...] } }, { ${field}: { $null: true } } \u2014 or remove the key.`,
|
|
953
|
+
{ field }
|
|
954
|
+
);
|
|
955
|
+
}
|
|
568
956
|
function convertFiltersToAST(filter) {
|
|
569
957
|
const conditions = [];
|
|
958
|
+
let trueIdentityGroups = 0;
|
|
959
|
+
let skippedNullKeys = 0;
|
|
570
960
|
for (const [field, value] of Object.entries(filter)) {
|
|
571
|
-
if (value === null || value === void 0)
|
|
961
|
+
if (value === null || value === void 0) {
|
|
962
|
+
skippedNullKeys += 1;
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
const logicKeyword = AST_LOGIC_KEYWORD[field];
|
|
966
|
+
if (logicKeyword) {
|
|
967
|
+
const group = lowerLogicalGroup(field, logicKeyword, value);
|
|
968
|
+
if (group !== void 0) conditions.push(group);
|
|
969
|
+
else trueIdentityGroups += 1;
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
if (field === "$not") {
|
|
973
|
+
throw new FilterOperatorError(
|
|
974
|
+
`[ObjectUI] The '$not' filter combinator cannot be lowered to the ObjectQL filter AST. '@objectstack/spec' declares it on FilterCondition, but the AST this layer emits has no negation keyword (FILTER_ARRAY_LOGIC_KEYWORDS is ['and', 'or']), and rewriting the negation inward is not available either \u2014 'startswith', 'endswith', 'between' and 'icontains' have no negated counterpart in VALID_AST_OPERATORS, so the rewrite would be silently partial. Express the negation with a negated operator instead ($ne, $nin, $notContains); note those follow each operator's own answer for a missing value rather than $not's NULL-safe rule (objectstack#5146). Value: ${JSON.stringify(value)}.`,
|
|
975
|
+
{ operator: "$not" }
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
if (Array.isArray(value)) {
|
|
979
|
+
throw new FilterOperatorError(
|
|
980
|
+
`[ObjectUI] The filter on field '${field}' carries a bare ARRAY as its equality comparand: ${JSON.stringify(value)}. It cannot be lowered: the ObjectQL filter AST has no array-equality node, so the lowered node [${field}, '=', [...]] is refused by @objectstack/driver-sql (400 INVALID_FILTER) and matches no row in the in-memory matchers \u2014 it can never select anything. It is deliberately NOT read as membership here: { ${field}: [...] } and { ${field}: { $in: [...] } } are different statements, and guessing the second from the first would silently change which rows a stored view returns (objectui#8530; the same ruling objectui#8514 applied one layer down). Spell membership as { ${field}: { $in: [...] } }, its negation as { ${field}: { $nin: [...] } }, or a range as { ${field}: { $between: [min, max] } }.`,
|
|
981
|
+
{ field }
|
|
982
|
+
);
|
|
983
|
+
}
|
|
572
984
|
if (typeof value === "object" && !Array.isArray(value)) {
|
|
573
|
-
|
|
985
|
+
if (isAcceptedFilterComparand(value)) {
|
|
986
|
+
conditions.push([field, "=", value]);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
if (!isOperatorMap(value)) {
|
|
990
|
+
throw new FilterOperatorError(
|
|
991
|
+
`[ObjectUI] The filter on field '${field}' carries ${describeExoticComparand(value)} in comparand position. '@objectstack/spec' does not accept it: a comparison value must be ${ACCEPTED_FILTER_COMPARAND_TYPES_SENTENCE} (ACCEPTED_FILTER_COMPARAND_TYPES), so isAcceptedFilterComparand is false for it and normalizeFilterComparandTypes answers 400 INVALID_FILTER \u2014 "which no driver can compare". It is not an operator map either: only a plain object can be one, so until objectui#8567 this value was read as ZERO operators and the '${field}' condition was dropped from the filter entirely, silently WIDENING the result set. Spell a text match as { ${field}: { $contains: '...' } } ($startsWith / $endsWith; a pattern itself has no operator here, see the $regex refusal), a membership test as { ${field}: { $in: [...] } }, and a date bound as { ${field}: { $gte: new Date(...) } }.`,
|
|
992
|
+
{ field }
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
const operatorEntries = Object.entries(value);
|
|
996
|
+
if (operatorEntries.length === 0) refuseEmptyOperatorMap(field);
|
|
997
|
+
for (const [operator, operatorValue] of operatorEntries) {
|
|
574
998
|
if (operator === "$regex") {
|
|
575
999
|
throw new FilterOperatorError(
|
|
576
|
-
`[ObjectUI] The '$regex' filter operator is not supported. It used to be converted to 'contains', which matches a literal substring rather than a pattern \u2014 a different result, not a degraded one. Field: '${field}', Value: ${JSON.stringify(operatorValue)}. Use $contains, $
|
|
1000
|
+
`[ObjectUI] The '$regex' filter operator is not supported. It used to be converted to 'contains', which matches a literal substring rather than a pattern \u2014 a different result, not a degraded one. Field: '${field}', Value: ${JSON.stringify(operatorValue)}. Use $contains for a case-sensitive substring, $icontains for a case-insensitive one, or $startsWith / $endsWith.`,
|
|
1001
|
+
{ operator: "$regex", field }
|
|
577
1002
|
);
|
|
578
1003
|
}
|
|
579
1004
|
if (operator === "$null") {
|
|
@@ -584,12 +1009,33 @@ function convertFiltersToAST(filter) {
|
|
|
584
1009
|
conditions.push([field, operatorValue ? "is_not_null" : "is_null", true]);
|
|
585
1010
|
continue;
|
|
586
1011
|
}
|
|
1012
|
+
if (operator === "$empty") {
|
|
1013
|
+
if (operatorValue !== true && operatorValue !== false) {
|
|
1014
|
+
throw new FilterOperatorError(
|
|
1015
|
+
`[ObjectUI] The '$empty' filter operator on field '${field}' takes a boolean flag (true or false); received ${JSON.stringify(operatorValue) ?? String(operatorValue)}. Write { ${field}: { $empty: true } } for an empty value, or { ${field}: { $empty: false } } for a non-empty one.`,
|
|
1016
|
+
{ operator: "$empty", field }
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
conditions.push([field, operatorValue ? "is_empty" : "is_not_empty", true]);
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
587
1022
|
const astOperator = convertOperatorToAST(operator);
|
|
588
1023
|
if (astOperator) {
|
|
1024
|
+
if (astOperator === "icontains" && isRefusedTextComparand(operatorValue)) {
|
|
1025
|
+
refuseTextComparand(field, operator, operatorValue);
|
|
1026
|
+
}
|
|
589
1027
|
conditions.push([field, astOperator, operatorValue]);
|
|
590
1028
|
} else {
|
|
1029
|
+
const canonical = RETIRED_OPERATOR_ALIASES[operator];
|
|
1030
|
+
if (canonical) {
|
|
1031
|
+
throw new FilterOperatorError(
|
|
1032
|
+
`[ObjectUI] The '${operator}' filter operator is retired. Write '${canonical}' instead \u2014 the canonical spelling '@objectstack/spec' declares in FILTER_OPERATORS (data/filter.zod.ts). The operator itself is unchanged; only the key is renamed. Field: '${field}', Value: ${JSON.stringify(operatorValue)}. It used to be accepted here as a lowercase alias while the in-memory matcher refused it, so the same filter selected rows through one data source and none through the other (objectui#8568).`,
|
|
1033
|
+
{ operator, field }
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
591
1036
|
throw new FilterOperatorError(
|
|
592
|
-
`[ObjectUI] Unknown filter operator '${operator}' for field '${field}'. Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $between, $contains, $notContains, $startsWith, $endsWith, $null, $exists. If you need exact object matching, use the value directly without an operator
|
|
1037
|
+
`[ObjectUI] Unknown filter operator '${operator}' for field '${field}'. Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $between, $contains, $notContains, $startsWith, $endsWith, $icontains, $null, $exists, $empty. If you need exact object matching, use the value directly without an operator.`,
|
|
1038
|
+
{ operator, field }
|
|
593
1039
|
);
|
|
594
1040
|
}
|
|
595
1041
|
}
|
|
@@ -598,6 +1044,13 @@ function convertFiltersToAST(filter) {
|
|
|
598
1044
|
}
|
|
599
1045
|
}
|
|
600
1046
|
if (conditions.length === 0) {
|
|
1047
|
+
const keysTheLoopProcessed = Object.keys(filter).length - skippedNullKeys;
|
|
1048
|
+
if (trueIdentityGroups > 0 && trueIdentityGroups === keysTheLoopProcessed) {
|
|
1049
|
+
return void 0;
|
|
1050
|
+
}
|
|
1051
|
+
if (skippedNullKeys > 0 && skippedNullKeys === Object.keys(filter).length) {
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
601
1054
|
return filter;
|
|
602
1055
|
}
|
|
603
1056
|
if (conditions.length === 1) {
|
|
@@ -605,6 +1058,52 @@ function convertFiltersToAST(filter) {
|
|
|
605
1058
|
}
|
|
606
1059
|
return ["and", ...conditions];
|
|
607
1060
|
}
|
|
1061
|
+
var ARRAY_VALUED_VIEW_OPERATORS = /* @__PURE__ */ new Set([
|
|
1062
|
+
...VIEW_FILTER_LIST_VALUE_OPERATORS,
|
|
1063
|
+
...VIEW_FILTER_PAIR_VALUE_OPERATORS
|
|
1064
|
+
]);
|
|
1065
|
+
var KNOWN_VIEW_OPERATORS = new Set(VIEW_FILTER_OPERATORS);
|
|
1066
|
+
|
|
1067
|
+
// ../core/src/utils/column-sortability.ts
|
|
1068
|
+
import {
|
|
1069
|
+
FIELD_UNSORTABLE_VIRTUAL_TYPE,
|
|
1070
|
+
FIELD_SORTABLE_UNPROVISIONED_ANCHOR
|
|
1071
|
+
} from "@objectstack/spec/api";
|
|
1072
|
+
var OBJECT_SORTABILITY_KEY = /* @__PURE__ */ Symbol.for("objectui.objectSortability");
|
|
1073
|
+
function asFieldSortability(value) {
|
|
1074
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1075
|
+
const sortable = value.sortable;
|
|
1076
|
+
if (typeof sortable !== "boolean") return void 0;
|
|
1077
|
+
const reason = value.reason;
|
|
1078
|
+
const caveat = value.caveat;
|
|
1079
|
+
return {
|
|
1080
|
+
sortable,
|
|
1081
|
+
...typeof reason === "string" ? { reason } : {},
|
|
1082
|
+
...typeof caveat === "string" ? { caveat } : {}
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
function normalizeObjectSortability(served) {
|
|
1086
|
+
if (!served || typeof served !== "object" || Array.isArray(served)) return void 0;
|
|
1087
|
+
const rawFields = served.fields;
|
|
1088
|
+
if (!rawFields || typeof rawFields !== "object" || Array.isArray(rawFields)) return void 0;
|
|
1089
|
+
const fields = {};
|
|
1090
|
+
for (const [name, entry] of Object.entries(rawFields)) {
|
|
1091
|
+
const verdict = asFieldSortability(entry);
|
|
1092
|
+
if (verdict) fields[name] = verdict;
|
|
1093
|
+
}
|
|
1094
|
+
return { fields };
|
|
1095
|
+
}
|
|
1096
|
+
function attachObjectSortability(schema, served) {
|
|
1097
|
+
const projection = normalizeObjectSortability(served);
|
|
1098
|
+
if (!projection || !schema || typeof schema !== "object") return schema;
|
|
1099
|
+
Object.defineProperty(schema, OBJECT_SORTABILITY_KEY, {
|
|
1100
|
+
value: projection,
|
|
1101
|
+
enumerable: false,
|
|
1102
|
+
configurable: true,
|
|
1103
|
+
writable: true
|
|
1104
|
+
});
|
|
1105
|
+
return schema;
|
|
1106
|
+
}
|
|
608
1107
|
|
|
609
1108
|
// ../core/src/adapters/batchTransaction.ts
|
|
610
1109
|
function idOf(rec) {
|
|
@@ -673,20 +1172,143 @@ async function emulateBatchTransaction(dataSource, operations) {
|
|
|
673
1172
|
}
|
|
674
1173
|
|
|
675
1174
|
// ../core/src/utils/reference-keys.ts
|
|
676
|
-
|
|
1175
|
+
import { FIELD_KEY_GUIDANCE, FieldSchema } from "@objectstack/spec/data";
|
|
1176
|
+
var aliasProbe = (key) => key.toLowerCase().replace(/[_\-\s]/g, "");
|
|
1177
|
+
var declaredFieldKeys = null;
|
|
1178
|
+
var probeFolds = null;
|
|
1179
|
+
var collidingProbes = null;
|
|
1180
|
+
function fieldKeyFolds() {
|
|
1181
|
+
if (probeFolds) return probeFolds;
|
|
1182
|
+
const declared = Object.keys(FieldSchema.shape);
|
|
1183
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1184
|
+
for (const key of declared) {
|
|
1185
|
+
const probe = aliasProbe(key);
|
|
1186
|
+
seen.set(probe, [...seen.get(probe) ?? [], key]);
|
|
1187
|
+
}
|
|
1188
|
+
const folds = /* @__PURE__ */ new Map();
|
|
1189
|
+
const collisions = /* @__PURE__ */ new Map();
|
|
1190
|
+
for (const [probe, keys] of seen) {
|
|
1191
|
+
if (keys.length === 1) folds.set(probe, keys[0]);
|
|
1192
|
+
else collisions.set(probe, keys);
|
|
1193
|
+
}
|
|
1194
|
+
declaredFieldKeys = new Set(declared);
|
|
1195
|
+
collidingProbes = collisions;
|
|
1196
|
+
probeFolds = folds;
|
|
1197
|
+
return folds;
|
|
1198
|
+
}
|
|
1199
|
+
var warnedRetiredSpelling = /* @__PURE__ */ new Set();
|
|
1200
|
+
var warnedUnfoldableSpelling = /* @__PURE__ */ new Set();
|
|
1201
|
+
function warnUnfoldableRetiredKey(reason, key, detail, fieldName, objectName, f) {
|
|
1202
|
+
if (!isDev()) return;
|
|
1203
|
+
const named = fieldName ?? (typeof f.name === "string" ? f.name : "(unnamed field)");
|
|
1204
|
+
const owner = objectName ?? "(unknown object)";
|
|
1205
|
+
const memo = `${owner}:${named}:${key}:${reason}`;
|
|
1206
|
+
if (warnedUnfoldableSpelling.has(memo)) return;
|
|
1207
|
+
const published = reason === "no-declared-twin" && key === "id_field" ? ` \`@objectstack/spec\`'s \`FIELD_KEY_GUIDANCE\` gives the reason: ${FIELD_KEY_GUIDANCE.id_field.why}` : "";
|
|
1208
|
+
warnedUnfoldableSpelling.add(memo);
|
|
1209
|
+
console.warn(
|
|
1210
|
+
`[ObjectUI] Object \`${owner}\`, field \`${named}\`: the ingestion choke point CANNOT canonicalize the retired spelling \`${key}\`. ${detail}${published} The key and its value are LEFT on the def exactly as served \u2014 nothing is dropped here \u2014 but a consumer that reads only the spellings \`@objectstack/spec\`'s \`FieldSchema\` declares will not see this value. Fix the PRODUCER, or migrate the stored document. (maintainer ruling item 3 on objectui#7650; objectui#8938)`
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
function canonicalizeRetiredFieldKeys(f, fieldName, objectName) {
|
|
1214
|
+
const folds = fieldKeyFolds();
|
|
1215
|
+
for (const key of Object.keys(f)) {
|
|
1216
|
+
if (declaredFieldKeys.has(key)) continue;
|
|
1217
|
+
const value = f[key];
|
|
1218
|
+
if (value === void 0) continue;
|
|
1219
|
+
if (REFERENCE_ARM_KEYS.has(key)) continue;
|
|
1220
|
+
const probe = aliasProbe(key);
|
|
1221
|
+
const canonical = folds.get(probe);
|
|
1222
|
+
if (canonical === void 0) {
|
|
1223
|
+
const colliding = collidingProbes.get(probe);
|
|
1224
|
+
if (colliding) {
|
|
1225
|
+
warnUnfoldableRetiredKey(
|
|
1226
|
+
"ambiguous-probe",
|
|
1227
|
+
key,
|
|
1228
|
+
`Its alias spelling is shared by MORE THAN ONE key \`FieldSchema\` declares (${colliding.map((c) => `\`${c}\``).join(", ")}), so the fold refuses to choose between them rather than picking one.`,
|
|
1229
|
+
fieldName,
|
|
1230
|
+
objectName,
|
|
1231
|
+
f
|
|
1232
|
+
);
|
|
1233
|
+
} else {
|
|
1234
|
+
warnUnfoldableRetiredKey(
|
|
1235
|
+
"no-declared-twin",
|
|
1236
|
+
key,
|
|
1237
|
+
`\`FieldSchema\` declares neither \`${key}\` nor any key sharing its alias spelling (lowercased, with \`_\`, \`-\` and spaces removed), so there is no canonical key to fold it onto \u2014 and this path deliberately does not guess a near match.`,
|
|
1238
|
+
fieldName,
|
|
1239
|
+
objectName,
|
|
1240
|
+
f
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (f[canonical] !== void 0) {
|
|
1246
|
+
if (f[canonical] !== value) {
|
|
1247
|
+
warnUnfoldableRetiredKey(
|
|
1248
|
+
"canonical-occupied",
|
|
1249
|
+
key,
|
|
1250
|
+
`\`FieldSchema\` declares \`${canonical}\`, and this def already carries a DIFFERENT value under it; the producer's value stands, because this choke point never overwrites one.`,
|
|
1251
|
+
fieldName,
|
|
1252
|
+
objectName,
|
|
1253
|
+
f
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1258
|
+
f[canonical] = value;
|
|
1259
|
+
if (!isDev()) continue;
|
|
1260
|
+
const named = fieldName ?? (typeof f.name === "string" ? f.name : "(unnamed field)");
|
|
1261
|
+
const owner = objectName ?? "(unknown object)";
|
|
1262
|
+
const memo = `${owner}:${named}:${key}:${canonical}`;
|
|
1263
|
+
if (warnedRetiredSpelling.has(memo)) continue;
|
|
1264
|
+
warnedRetiredSpelling.add(memo);
|
|
1265
|
+
console.warn(
|
|
1266
|
+
`[ObjectUI] Object \`${owner}\`, field \`${named}\` carries the retired spelling \`${key}\`. \`@objectstack/spec\`'s \`FieldSchema\` declares \`${canonical}\` and does not declare \`${key}\`, so a producer emitting it would be refused at the metadata write door. ObjectUI stamps \`${canonical}\` here so this stored def still renders, but the consumers no longer carry a \`${key}\` fallback of their own \u2014 fix the PRODUCER, or migrate the stored document. (objectui#7650)`
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
var warnedLegacyOnly = /* @__PURE__ */ new Set();
|
|
1271
|
+
var isDev = () => globalThis.process?.env?.NODE_ENV !== "production";
|
|
1272
|
+
var LEGACY_REFERENCE_KEYS = ["reference_to", "referenceTo"];
|
|
1273
|
+
var REFERENCE_ARM_KEYS = new Set(LEGACY_REFERENCE_KEYS);
|
|
1274
|
+
function warnOnLegacyOnlyReference(f, fieldName, objectName) {
|
|
1275
|
+
if (!isDev()) return;
|
|
1276
|
+
if (f.reference !== void 0) return;
|
|
1277
|
+
const spelled = LEGACY_REFERENCE_KEYS.filter((k) => f[k] !== void 0 && f[k] !== "");
|
|
1278
|
+
if (spelled.length === 0) return;
|
|
1279
|
+
const named = fieldName ?? (typeof f.name === "string" ? f.name : "(unnamed field)");
|
|
1280
|
+
const owner = objectName ?? "(unknown object)";
|
|
1281
|
+
for (const key of spelled) {
|
|
1282
|
+
const memo = `${owner}:${named}:${key}:${String(f[key])}`;
|
|
1283
|
+
if (warnedLegacyOnly.has(memo)) continue;
|
|
1284
|
+
warnedLegacyOnly.add(memo);
|
|
1285
|
+
console.warn(
|
|
1286
|
+
`[ObjectUI] Object \`${owner}\`, field \`${named}\` declares its relationship target as \`${key}: '${String(f[key])}'\` and does NOT carry \`reference\`. \`reference\` is the only spelling the protocol declares: \`@objectstack/spec\`'s \`FieldSchema\` refuses \`${key}\` by name with \`unrecognized_keys\` ("Did you mean \`${key}\` -> \`reference\`?"). ObjectUI stamps \`reference\` here so this def still renders, but the readers no longer carry a \`${key}\` fallback of their own \u2014 fix the PRODUCER to emit \`reference\`, or serve the def through a backend that normalizes it (objectstack#13847 does this on the serve path and in \`os migrate meta\`). Maintainer ruling 2026-08-31: protocol normalization belongs on the server, the front end just executes the protocol. (objectui#6837)`
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function normalizeFieldReferenceKeys(fieldDef, fieldName, objectName) {
|
|
677
1291
|
if (!fieldDef || typeof fieldDef !== "object") return fieldDef;
|
|
678
1292
|
const f = fieldDef;
|
|
679
|
-
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
if (
|
|
1293
|
+
canonicalizeRetiredFieldKeys(f, fieldName, objectName);
|
|
1294
|
+
if (f.reference !== void 0) return fieldDef;
|
|
1295
|
+
const legacy = f.reference_to ?? f.referenceTo;
|
|
1296
|
+
if (legacy == null || legacy === "") return fieldDef;
|
|
1297
|
+
warnOnLegacyOnlyReference(f, fieldName, objectName);
|
|
1298
|
+
f.reference = legacy;
|
|
683
1299
|
return fieldDef;
|
|
684
1300
|
}
|
|
685
1301
|
function normalizeSchemaReferenceKeys(schema) {
|
|
686
1302
|
const fields = schema && typeof schema === "object" ? schema.fields : null;
|
|
687
1303
|
if (!fields || typeof fields !== "object") return schema;
|
|
688
|
-
const
|
|
689
|
-
|
|
1304
|
+
const objectName = typeof schema.name === "string" ? schema.name : void 0;
|
|
1305
|
+
if (Array.isArray(fields)) {
|
|
1306
|
+
for (const def of fields) normalizeFieldReferenceKeys(def, void 0, objectName);
|
|
1307
|
+
} else {
|
|
1308
|
+
for (const [name, def] of Object.entries(fields)) {
|
|
1309
|
+
normalizeFieldReferenceKeys(def, name, objectName);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
690
1312
|
return schema;
|
|
691
1313
|
}
|
|
692
1314
|
|
|
@@ -1059,6 +1681,25 @@ function isErrorType(error, errorClass) {
|
|
|
1059
1681
|
return error instanceof errorClass;
|
|
1060
1682
|
}
|
|
1061
1683
|
|
|
1684
|
+
// src/error-envelope.ts
|
|
1685
|
+
function readErrorEnvelope(body) {
|
|
1686
|
+
if (!body || typeof body !== "object") return {};
|
|
1687
|
+
const env = body;
|
|
1688
|
+
const nested = env.error && typeof env.error === "object" ? env.error : void 0;
|
|
1689
|
+
const reading = {};
|
|
1690
|
+
const message = text(nested?.message) ?? text(env.message) ?? text(env.error);
|
|
1691
|
+
if (message !== void 0) reading.message = message;
|
|
1692
|
+
const code = present(env.code) ?? present(nested?.code);
|
|
1693
|
+
if (code !== void 0) reading.code = code;
|
|
1694
|
+
return reading;
|
|
1695
|
+
}
|
|
1696
|
+
function text(value) {
|
|
1697
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
1698
|
+
}
|
|
1699
|
+
function present(value) {
|
|
1700
|
+
return typeof value === "string" ? value : void 0;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1062
1703
|
// src/userState.ts
|
|
1063
1704
|
var DEFAULT_RESOURCE = "sys_user_preference";
|
|
1064
1705
|
function createObjectStackUserStateAdapter(options) {
|
|
@@ -1161,6 +1802,33 @@ function createObjectStackUserStateAdapter(options) {
|
|
|
1161
1802
|
};
|
|
1162
1803
|
}
|
|
1163
1804
|
|
|
1805
|
+
// src/draft-envelope.ts
|
|
1806
|
+
import { stripReadDecorations } from "@objectstack/spec/kernel";
|
|
1807
|
+
function extractDraftBody(resp) {
|
|
1808
|
+
if (!resp || typeof resp !== "object") return null;
|
|
1809
|
+
const env = resp;
|
|
1810
|
+
if (!("item" in env)) return null;
|
|
1811
|
+
const body = env.item;
|
|
1812
|
+
if (!body || typeof body !== "object") return null;
|
|
1813
|
+
if (Object.keys(body).length === 0) return null;
|
|
1814
|
+
return stripReadDecorations(body);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
// src/metadata-error.ts
|
|
1818
|
+
function extractIssues(e) {
|
|
1819
|
+
const issues = e?.issues;
|
|
1820
|
+
return Array.isArray(issues) ? issues : [];
|
|
1821
|
+
}
|
|
1822
|
+
function formatMetadataIssue(i) {
|
|
1823
|
+
return `\u2022 ${i.path && i.path.length > 0 ? i.path : "(root)"} \u2014 ${i.message}`;
|
|
1824
|
+
}
|
|
1825
|
+
function formatMetadataError(e) {
|
|
1826
|
+
const issues = extractIssues(e);
|
|
1827
|
+
if (issues.length > 0) return issues.map(formatMetadataIssue).join("\n");
|
|
1828
|
+
const err = e;
|
|
1829
|
+
return err?.message ?? String(e);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1164
1832
|
// src/index.ts
|
|
1165
1833
|
var FILTER_OPERATOR_ALIASES = {
|
|
1166
1834
|
equals: "=",
|
|
@@ -1218,14 +1886,21 @@ var FILTER_OPERATOR_ALIASES = {
|
|
|
1218
1886
|
before: "<",
|
|
1219
1887
|
after: ">"
|
|
1220
1888
|
};
|
|
1221
|
-
function
|
|
1889
|
+
function toAstFilterOperator(op) {
|
|
1222
1890
|
if (typeof op !== "string") return null;
|
|
1223
1891
|
const lower = op.toLowerCase();
|
|
1224
1892
|
return FILTER_OPERATOR_ALIASES[lower] ?? FILTER_OPERATOR_ALIASES[op] ?? op;
|
|
1225
1893
|
}
|
|
1894
|
+
function describeFilterEntry(entry) {
|
|
1895
|
+
try {
|
|
1896
|
+
return JSON.stringify(entry, (_key, value) => typeof value === "bigint" ? `${value}n` : value) ?? String(entry);
|
|
1897
|
+
} catch {
|
|
1898
|
+
return String(entry);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1226
1901
|
var MalformedFilterError = class extends Error {
|
|
1227
1902
|
constructor(entry, index) {
|
|
1228
|
-
const shown =
|
|
1903
|
+
const shown = describeFilterEntry(entry);
|
|
1229
1904
|
super(
|
|
1230
1905
|
`Filter entry ${index} is not a usable filter rule (${shown}). Expected { field, operator, value } with a non-empty field.`
|
|
1231
1906
|
);
|
|
@@ -1243,12 +1918,104 @@ function isMalformedFilterError(error) {
|
|
|
1243
1918
|
const e = error;
|
|
1244
1919
|
return e.code === "INVALID_FILTER" || e.name === "MalformedFilterError";
|
|
1245
1920
|
}
|
|
1246
|
-
|
|
1921
|
+
var UnloweredAggregateWhereError = class extends Error {
|
|
1922
|
+
constructor(where, resource) {
|
|
1923
|
+
const shown = JSON.stringify(where) ?? String(where);
|
|
1924
|
+
super(
|
|
1925
|
+
`aggregate('${resource}'): the spec-shape branch received a \`where\` array that is not a filter \u2014 ${shown}. This branch posts \`where\` to POST /data/:object/query verbatim, so it must ALREADY be lowered: either a FilterCondition object (\`QuerySchema.where\`, @objectstack/spec data/query.zod.ts), or a FilterArray the ingress can lower \u2014 a comparison tuple (['stage','=','won']), a logical node (['and',[..],[..]]), or an array of nodes (data/filter.zod.ts, gate \`isFilterAST\`). A ViewFilterRule[] ([{ field, operator, value }, ...]) is authoring sugar, not a filter: lower it in the producer that built these aggregate params, not here. Nothing was sent to the server, so no unfiltered numbers came back.`
|
|
1926
|
+
);
|
|
1927
|
+
__publicField(this, "code", "INVALID_FILTER");
|
|
1928
|
+
__publicField(this, "httpStatus", 400);
|
|
1929
|
+
/** The value as received, so a caller can log what its producer actually built. */
|
|
1930
|
+
__publicField(this, "where");
|
|
1931
|
+
/** The object `aggregate()` was called for. */
|
|
1932
|
+
__publicField(this, "resource");
|
|
1933
|
+
this.name = "UnloweredAggregateWhereError";
|
|
1934
|
+
this.where = where;
|
|
1935
|
+
this.resource = resource;
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
function assertSpecShapeWhereIsFilterAst(where, resource) {
|
|
1939
|
+
if (!Array.isArray(where)) return;
|
|
1940
|
+
if (where.length === 0) return;
|
|
1941
|
+
if (isFilterAST(where)) return;
|
|
1942
|
+
throw new UnloweredAggregateWhereError(where, resource);
|
|
1943
|
+
}
|
|
1944
|
+
var ANALYTICS_ONLY_AGGREGATE_KEYS = ["filter", "field", "function"];
|
|
1945
|
+
var ANALYTICS_ONLY_KEY_ADVICE = {
|
|
1946
|
+
filter: "`filter` is the ANALYTICS branch's filter and is lowered there through `parseFilterAST`; this branch's filter is `where` (`QuerySchema.where`, @objectstack/spec data/query.zod.ts) and is posted VERBATIM \u2014 rename it to `where` and lower it in the producer.",
|
|
1947
|
+
field: "`field` is half of the analytics branch's `${field}_${function}` measure; this branch's measure is `aggregations`, an AggregationNode[] such as [{ function: 'sum', field: 'amount', alias: 'amount_sum' }].",
|
|
1948
|
+
function: "`function` is the other half of that measure pair and belongs inside an `aggregations` node, not beside `groupBy`."
|
|
1949
|
+
};
|
|
1950
|
+
function specShapeSelectorReasons(params) {
|
|
1951
|
+
const reasons = [];
|
|
1952
|
+
if (Array.isArray(params?.groupBy)) reasons.push("`groupBy` is an array");
|
|
1953
|
+
if (Array.isArray(params?.aggregations)) reasons.push("`aggregations` is an array");
|
|
1954
|
+
if (params?.where !== void 0) reasons.push("a `where` key is present");
|
|
1955
|
+
return reasons;
|
|
1956
|
+
}
|
|
1957
|
+
var AnalyticsKeysOnSpecShapeError = class extends Error {
|
|
1958
|
+
constructor(keys, params, resource) {
|
|
1959
|
+
const received = {};
|
|
1960
|
+
for (const key of keys) received[key] = params?.[key];
|
|
1961
|
+
const named = keys.map((k) => `\`${k}\``).join(", ");
|
|
1962
|
+
const shown = keys.map((k) => `${k}=${JSON.stringify(params?.[k]) ?? String(params?.[k])}`).join(", ");
|
|
1963
|
+
const why = specShapeSelectorReasons(params).join(" and ");
|
|
1964
|
+
const noMeasure = !Array.isArray(params?.aggregations) ? " Because no `aggregations` was supplied either, the query this would have built is a grouping with NO MEASURE \u2014 the chart renders and its numbers mean nothing." : "";
|
|
1965
|
+
super(
|
|
1966
|
+
`aggregate('${resource}'): the spec-shape branch received the analytics branch's ${named} \u2014 ${shown} \u2014 and reads none of them. This call took the spec-shape branch because ${why}; the branch posts only \`groupBy\`, \`aggregations\`, \`where\` and \`limit\` to POST /data/:object/query, so those keys would have been dropped in silence.${noMeasure} ` + keys.map((k) => ANALYTICS_ONLY_KEY_ADVICE[k]).join(" ") + " The two shapes are alternatives, not a mixture: the analytics branch (`{ field, function, groupBy, filter }`, which lowers its filter for you) is reached only when NONE of an array `groupBy`, an array `aggregations` or a `where` key is present. Nothing was sent to the server, so no unfiltered numbers came back."
|
|
1967
|
+
);
|
|
1968
|
+
__publicField(this, "code", "INVALID_FILTER");
|
|
1969
|
+
__publicField(this, "httpStatus", 400);
|
|
1970
|
+
/** The offending keys, in the order {@link ANALYTICS_ONLY_AGGREGATE_KEYS} lists them. */
|
|
1971
|
+
__publicField(this, "keys");
|
|
1972
|
+
/** What each offending key carried, so a producer is identifiable from a log. */
|
|
1973
|
+
__publicField(this, "received");
|
|
1974
|
+
/** The object `aggregate()` was called for. */
|
|
1975
|
+
__publicField(this, "resource");
|
|
1976
|
+
this.name = "AnalyticsKeysOnSpecShapeError";
|
|
1977
|
+
this.keys = keys;
|
|
1978
|
+
this.received = received;
|
|
1979
|
+
this.resource = resource;
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
function assertNoAnalyticsKeysOnSpecShape(params, resource) {
|
|
1983
|
+
const present2 = ANALYTICS_ONLY_AGGREGATE_KEYS.filter((key) => params?.[key] != null);
|
|
1984
|
+
if (present2.length === 0) return;
|
|
1985
|
+
throw new AnalyticsKeysOnSpecShapeError(present2, params, resource);
|
|
1986
|
+
}
|
|
1987
|
+
var UnlowerableAnalyticsFilterError = class extends Error {
|
|
1988
|
+
constructor(filter, resource, detail) {
|
|
1989
|
+
const shown = JSON.stringify(filter) ?? String(filter);
|
|
1990
|
+
super(
|
|
1991
|
+
`aggregate('${resource}'): the analytics branch received a \`filter\` array that \`parseFilterAST\` cannot lower into a FilterCondition \u2014 ${shown}.` + (detail ? ` (${detail})` : "") + " `where` on the analytics wire is a FilterCondition (`AnalyticsQuerySchema`, @objectstack/spec data/analytics.zod.ts), and a FilterArray is input-only sugar lowered into one at the single sink `parseFilterAST` (data/filter.zod.ts, objectstack#5158 ruling C). Lowerable shapes are a comparison tuple (['stage','=','won']), a logical node (['and',[..],[..]]), an array of such nodes, and a ViewFilterRule[] this adapter translates first. An infix join ([condA, 'or', condB]) is none of them. Nothing was sent to the server, so no unfiltered numbers came back."
|
|
1992
|
+
);
|
|
1993
|
+
__publicField(this, "code", "INVALID_FILTER");
|
|
1994
|
+
__publicField(this, "httpStatus", 400);
|
|
1995
|
+
/** The filter as received, so a caller can log what its producer actually built. */
|
|
1996
|
+
__publicField(this, "filter");
|
|
1997
|
+
/** The object `aggregate()` was called for. */
|
|
1998
|
+
__publicField(this, "resource");
|
|
1999
|
+
this.name = "UnlowerableAnalyticsFilterError";
|
|
2000
|
+
this.filter = filter;
|
|
2001
|
+
this.resource = resource;
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
function refuseTextComparandEntry(entry, index, field, arrived) {
|
|
2005
|
+
const tail = `This is a { field, operator, value } rule entry, so it is refused as the filter is translated rather than sent: the spelling @objectstack/spec's FILTER_TEXT_CASES uses for this operator is the $-dialect '$icontains', which this form spells '${arrived}'. Remove the entry, or give it a non-empty string value (objectui#9048; the same refusal convertFiltersToAST and ValueDataSource already share).`;
|
|
2006
|
+
const error = new MalformedFilterError(entry, index);
|
|
2007
|
+
error.message = `Filter entry ${index} is refused. The ${textComparandRefusalReason2(field, arrived, entry.value)}. ${tail}`;
|
|
2008
|
+
throw error;
|
|
2009
|
+
}
|
|
2010
|
+
function objectFilterEntryToAST(entry, index) {
|
|
1247
2011
|
if (!entry || typeof entry !== "object") return null;
|
|
1248
2012
|
const field = entry.field;
|
|
1249
2013
|
const rawOp = entry.operator ?? entry.op ?? "=";
|
|
1250
|
-
const op =
|
|
2014
|
+
const op = toAstFilterOperator(rawOp);
|
|
1251
2015
|
if (!field || !op) return null;
|
|
2016
|
+
if (op === "icontains" && isRefusedTextComparand2(entry.value)) {
|
|
2017
|
+
refuseTextComparandEntry(entry, index, String(field), rawOp);
|
|
2018
|
+
}
|
|
1252
2019
|
return [String(field), op, entry.value];
|
|
1253
2020
|
}
|
|
1254
2021
|
function isObjectFilterEntryForm(filter) {
|
|
@@ -1257,8 +2024,8 @@ function isObjectFilterEntryForm(filter) {
|
|
|
1257
2024
|
}
|
|
1258
2025
|
function objectFilterEntriesToAST(entries) {
|
|
1259
2026
|
const nodes = entries.map((entry, i) => {
|
|
1260
|
-
if (Array.isArray(entry)) return translateFilterChild(entry);
|
|
1261
|
-
const tuple = objectFilterEntryToAST(entry);
|
|
2027
|
+
if (Array.isArray(entry)) return translateFilterChild(entry, i);
|
|
2028
|
+
const tuple = objectFilterEntryToAST(entry, i);
|
|
1262
2029
|
if (!tuple) throw new MalformedFilterError(entry, i);
|
|
1263
2030
|
return tuple;
|
|
1264
2031
|
});
|
|
@@ -1269,15 +2036,17 @@ function translateFilterArray(filter) {
|
|
|
1269
2036
|
if (isObjectFilterEntryForm(filter)) return objectFilterEntriesToAST(filter);
|
|
1270
2037
|
const head = filter[0];
|
|
1271
2038
|
if (typeof head === "string" && LOGICAL_AST_HEADS.has(head.toLowerCase())) {
|
|
1272
|
-
return [head, ...filter.slice(1).map(translateFilterChild)];
|
|
2039
|
+
return [head, ...filter.slice(1).map((child, i) => translateFilterChild(child, i + 1))];
|
|
2040
|
+
}
|
|
2041
|
+
if (filter.every((child) => Array.isArray(child))) {
|
|
2042
|
+
return filter.map((child, i) => translateFilterChild(child, i));
|
|
1273
2043
|
}
|
|
1274
|
-
if (filter.every((child) => Array.isArray(child))) return filter.map(translateFilterChild);
|
|
1275
2044
|
return filter;
|
|
1276
2045
|
}
|
|
1277
|
-
function translateFilterChild(child) {
|
|
2046
|
+
function translateFilterChild(child, index) {
|
|
1278
2047
|
if (Array.isArray(child)) return child.length > 0 ? translateFilterArray(child) : child;
|
|
1279
2048
|
if (child && typeof child === "object" && child.field !== void 0) {
|
|
1280
|
-
const tuple = objectFilterEntryToAST(child);
|
|
2049
|
+
const tuple = objectFilterEntryToAST(child, index);
|
|
1281
2050
|
if (tuple) return tuple;
|
|
1282
2051
|
}
|
|
1283
2052
|
return child;
|
|
@@ -1294,6 +2063,30 @@ function translateFilterToAST(filter) {
|
|
|
1294
2063
|
}
|
|
1295
2064
|
return void 0;
|
|
1296
2065
|
}
|
|
2066
|
+
function lowerAnalyticsFilterForWire(filter, resource) {
|
|
2067
|
+
if (!Array.isArray(filter)) return filter;
|
|
2068
|
+
if (filter.length === 0) return void 0;
|
|
2069
|
+
const ast = translateFilterArray(filter);
|
|
2070
|
+
if (!isFilterAST(ast)) throw new UnlowerableAnalyticsFilterError(filter, resource);
|
|
2071
|
+
let lowered;
|
|
2072
|
+
try {
|
|
2073
|
+
lowered = parseFilterAST(ast);
|
|
2074
|
+
} catch (e) {
|
|
2075
|
+
throw new UnlowerableAnalyticsFilterError(
|
|
2076
|
+
filter,
|
|
2077
|
+
resource,
|
|
2078
|
+
e instanceof Error ? e.message : String(e)
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
if (lowered === void 0) {
|
|
2082
|
+
throw new UnlowerableAnalyticsFilterError(
|
|
2083
|
+
filter,
|
|
2084
|
+
resource,
|
|
2085
|
+
"`parseFilterAST` answered `undefined` for a non-empty filter"
|
|
2086
|
+
);
|
|
2087
|
+
}
|
|
2088
|
+
return lowered;
|
|
2089
|
+
}
|
|
1297
2090
|
function serializeOrderBy(orderby) {
|
|
1298
2091
|
if (orderby === void 0 || orderby === null) return void 0;
|
|
1299
2092
|
if (typeof orderby === "string") {
|
|
@@ -1356,6 +2149,37 @@ var APP_PERMISSION_DENIED_CODE = "PERMISSION_DENIED";
|
|
|
1356
2149
|
function isAppPermissionDeniedError(error) {
|
|
1357
2150
|
return errorCodeIs(error, APP_PERMISSION_DENIED_CODE);
|
|
1358
2151
|
}
|
|
2152
|
+
var META_ITEM_ABSENT_CODE = "RESOURCE_NOT_FOUND";
|
|
2153
|
+
function isMetaItemAbsentError(error) {
|
|
2154
|
+
return errorCodeIs(error, META_ITEM_ABSENT_CODE);
|
|
2155
|
+
}
|
|
2156
|
+
function metaEnvelopeCarriesItem(envelope) {
|
|
2157
|
+
if (envelope == null || typeof envelope !== "object") return false;
|
|
2158
|
+
return envelope.item != null;
|
|
2159
|
+
}
|
|
2160
|
+
var VIEW_CONFIG_CAPABILITY = "manage_metadata";
|
|
2161
|
+
var ViewConfigPermissionDeniedError = class extends Error {
|
|
2162
|
+
constructor(objectName, viewId) {
|
|
2163
|
+
super(
|
|
2164
|
+
`View configuration is shared: changing "${viewId}" changes it for everyone who uses this view. That requires the "${VIEW_CONFIG_CAPABILITY}" capability, which this session does not hold.`
|
|
2165
|
+
);
|
|
2166
|
+
__publicField(this, "code", "VIEW_CONFIG_PERMISSION_DENIED");
|
|
2167
|
+
/** The capability that was required and not held. */
|
|
2168
|
+
__publicField(this, "capability", VIEW_CONFIG_CAPABILITY);
|
|
2169
|
+
/** The object whose view configuration the refused write targeted. */
|
|
2170
|
+
__publicField(this, "objectName");
|
|
2171
|
+
/** The view id the refused write targeted. */
|
|
2172
|
+
__publicField(this, "viewId");
|
|
2173
|
+
this.name = "ViewConfigPermissionDeniedError";
|
|
2174
|
+
this.objectName = objectName;
|
|
2175
|
+
this.viewId = viewId;
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
function isViewConfigPermissionDeniedError(error) {
|
|
2179
|
+
if (!error || typeof error !== "object") return false;
|
|
2180
|
+
const e = error;
|
|
2181
|
+
return e.code === "VIEW_CONFIG_PERMISSION_DENIED" || e.name === "ViewConfigPermissionDeniedError";
|
|
2182
|
+
}
|
|
1359
2183
|
var AnalyticsNotInstalledError = class extends Error {
|
|
1360
2184
|
constructor(surface, detail, serverCode) {
|
|
1361
2185
|
super(
|
|
@@ -1424,6 +2248,25 @@ var AnalyticsUnauthenticatedError = class extends Error {
|
|
|
1424
2248
|
this.serverMessage = opts.serverMessage;
|
|
1425
2249
|
}
|
|
1426
2250
|
};
|
|
2251
|
+
var AnalyticsForbiddenError = class extends Error {
|
|
2252
|
+
constructor(opts = {}) {
|
|
2253
|
+
super(
|
|
2254
|
+
`Analytics query refused: this user may not read the data behind ${opts.datasetName ? `dataset "${opts.datasetName}"` : "this dataset"}.` + (opts.serverMessage ? ` (server said: ${opts.serverMessage})` : "")
|
|
2255
|
+
);
|
|
2256
|
+
__publicField(this, "code", "PERMISSION_DENIED");
|
|
2257
|
+
__publicField(this, "httpStatus", 403);
|
|
2258
|
+
/** The server's own ADR-0112 code — the field this branch was chosen BY. */
|
|
2259
|
+
__publicField(this, "serverCode");
|
|
2260
|
+
/** The server's own message, verbatim (diagnostics only). */
|
|
2261
|
+
__publicField(this, "serverMessage");
|
|
2262
|
+
/** The dataset the refused query asked for, when it named one. */
|
|
2263
|
+
__publicField(this, "datasetName");
|
|
2264
|
+
this.name = "AnalyticsForbiddenError";
|
|
2265
|
+
this.serverCode = opts.serverCode;
|
|
2266
|
+
this.serverMessage = opts.serverMessage;
|
|
2267
|
+
this.datasetName = opts.datasetName;
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
1427
2270
|
function readAnalyticsErrorEnvelope(body) {
|
|
1428
2271
|
if (!body || typeof body !== "object") return {};
|
|
1429
2272
|
const flat = body;
|
|
@@ -1446,6 +2289,30 @@ var AnalyticsQueryRejectedError = class extends Error {
|
|
|
1446
2289
|
this.serverCode = serverCode;
|
|
1447
2290
|
}
|
|
1448
2291
|
};
|
|
2292
|
+
var AnalyticsResultShapeError = class extends Error {
|
|
2293
|
+
constructor(resource, result) {
|
|
2294
|
+
const value = result;
|
|
2295
|
+
const envelope = Array.isArray(value?.data?.rows);
|
|
2296
|
+
const received = result === null ? "null" : Array.isArray(result) ? "an array" : typeof result !== "object" ? typeof result : `an object with keys [${Object.keys(result).join(", ")}]`;
|
|
2297
|
+
super(
|
|
2298
|
+
envelope ? `aggregate('${resource}'): client.analytics.query resolved to the \`{ data: { rows } }\` envelope, not to an AnalyticsResult. @objectstack/client resolves this method to the payload itself since 17.3.0 (objectstack#13079), and this adapter reads \`rows\` only: an older client is installed beside it, or something between the client and POST /analytics/query wraps the payload a second time. Install @objectstack/client 17.3.0 or later.` : `aggregate('${resource}'): client.analytics.query resolved to ${received}, which has no \`rows\` array, so it is not an AnalyticsResult. This adapter reads \`rows\` only (objectui#7028).`
|
|
2299
|
+
);
|
|
2300
|
+
__publicField(this, "code", "ANALYTICS_RESULT_SHAPE_INVALID");
|
|
2301
|
+
/** The object `aggregate()` was called for. */
|
|
2302
|
+
__publicField(this, "resource");
|
|
2303
|
+
/**
|
|
2304
|
+
* True when the value is the envelope the client stopped handing back at
|
|
2305
|
+
* 17.3.0 — `{ success, data: { rows } }`, or its `{ data: { rows } }` core.
|
|
2306
|
+
*/
|
|
2307
|
+
__publicField(this, "envelope");
|
|
2308
|
+
/** What the value was, so the producer is identifiable from a log. */
|
|
2309
|
+
__publicField(this, "received");
|
|
2310
|
+
this.name = "AnalyticsResultShapeError";
|
|
2311
|
+
this.resource = resource;
|
|
2312
|
+
this.envelope = envelope;
|
|
2313
|
+
this.received = received;
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
1449
2316
|
function classifyAnalyticsFailure(error) {
|
|
1450
2317
|
const err = error ?? {};
|
|
1451
2318
|
const code = typeof err.code === "string" && err.code.length > 0 ? err.code : void 0;
|
|
@@ -1457,11 +2324,11 @@ function classifyAnalyticsFailure(error) {
|
|
|
1457
2324
|
if (errorCodeIs({ code }, "VALIDATION_FAILED")) return { kind: "rejected", code, message };
|
|
1458
2325
|
if (errorCodeIs({ code }, "UNAUTHENTICATED")) return { kind: "unauthenticated", code, message };
|
|
1459
2326
|
if (errorCodeIs({ code }, "CUBE_NOT_FOUND")) return { kind: "cube-not-found", code, message };
|
|
2327
|
+
if (status === 400) return { kind: "rejected", code, message };
|
|
1460
2328
|
if (code === void 0) {
|
|
1461
2329
|
if (status !== void 0 && ANALYTICS_ABSENT_STATUSES.includes(status)) {
|
|
1462
2330
|
return { kind: "not-installed", code, message };
|
|
1463
2331
|
}
|
|
1464
|
-
if (status === 400) return { kind: "rejected", code, message };
|
|
1465
2332
|
if (status === 401) return { kind: "unauthenticated", code, message };
|
|
1466
2333
|
}
|
|
1467
2334
|
return { kind: "unknown", code, message };
|
|
@@ -1473,9 +2340,22 @@ var ConcurrentUpdateError = class extends Error {
|
|
|
1473
2340
|
__publicField(this, "httpStatus", 409);
|
|
1474
2341
|
__publicField(this, "currentVersion");
|
|
1475
2342
|
__publicField(this, "currentRecord");
|
|
2343
|
+
/**
|
|
2344
|
+
* The refusal text the PRODUCER marked as addressed to the end user
|
|
2345
|
+
* (`ApiErrorSchema.userMessage`, objectstack `79c46da90`), or `null` when the
|
|
2346
|
+
* refusal carried no marking.
|
|
2347
|
+
*
|
|
2348
|
+
* Declared on the class because this error has no `details` bag: the shared
|
|
2349
|
+
* reader (`declaredUserMessage` in `@object-ui/react`) looks at the
|
|
2350
|
+
* top-level field first, so parking it here is what makes the marking
|
|
2351
|
+
* readable at the surface. The contract is status-agnostic — a 409 carries
|
|
2352
|
+
* it exactly like a 400 or a 403 does.
|
|
2353
|
+
*/
|
|
2354
|
+
__publicField(this, "userMessage");
|
|
1476
2355
|
this.name = "ConcurrentUpdateError";
|
|
1477
2356
|
this.currentVersion = opts.currentVersion;
|
|
1478
2357
|
this.currentRecord = opts.currentRecord;
|
|
2358
|
+
this.userMessage = opts.userMessage ?? null;
|
|
1479
2359
|
}
|
|
1480
2360
|
};
|
|
1481
2361
|
function isConcurrentUpdateError(error) {
|
|
@@ -1483,10 +2363,18 @@ function isConcurrentUpdateError(error) {
|
|
|
1483
2363
|
const e = error;
|
|
1484
2364
|
return e.code === "CONCURRENT_UPDATE" || e.name === "ConcurrentUpdateError";
|
|
1485
2365
|
}
|
|
2366
|
+
function liftUserMessage(e, details) {
|
|
2367
|
+
if (typeof e.userMessage === "string" && e.userMessage.trim()) return e.userMessage;
|
|
2368
|
+
if (typeof details.userMessage === "string" && details.userMessage.trim()) {
|
|
2369
|
+
return details.userMessage;
|
|
2370
|
+
}
|
|
2371
|
+
return null;
|
|
2372
|
+
}
|
|
1486
2373
|
function normaliseClientError(error) {
|
|
1487
2374
|
if (!error || typeof error !== "object") return error;
|
|
1488
2375
|
const e = error;
|
|
1489
2376
|
const details = e.details ?? {};
|
|
2377
|
+
const userMessage = liftUserMessage(e, details);
|
|
1490
2378
|
if (e.code === "VALIDATION_FAILED" || e.name === "ValidationError") {
|
|
1491
2379
|
const rawFields = Array.isArray(details.fields) ? details.fields : Array.isArray(e.fields) ? e.fields : [];
|
|
1492
2380
|
const validationErrors = rawFields.map((f) => {
|
|
@@ -1500,15 +2388,21 @@ function normaliseClientError(error) {
|
|
|
1500
2388
|
typeof e.message === "string" ? e.message : "Validation failed",
|
|
1501
2389
|
validationErrors[0]?.field,
|
|
1502
2390
|
validationErrors,
|
|
1503
|
-
|
|
2391
|
+
// The marking rides the details bag exactly the way `fields` already
|
|
2392
|
+
// does, landing on `err.details.userMessage` — the second of the two
|
|
2393
|
+
// places the shared reader looks. Purely additive: `field`,
|
|
2394
|
+
// `validationErrors` and `fields` are untouched, so the per-field
|
|
2395
|
+
// marking a form already draws keeps working. Omitted entirely when
|
|
2396
|
+
// unmarked, so an unmarked refusal carries no empty key.
|
|
2397
|
+
userMessage === null ? { fields: rawFields } : { fields: rawFields, userMessage }
|
|
1504
2398
|
);
|
|
1505
2399
|
}
|
|
1506
|
-
if (e.code !== "CONCURRENT_UPDATE" && e.httpStatus !== 409) return error;
|
|
1507
2400
|
if (e.code !== "CONCURRENT_UPDATE") return error;
|
|
1508
2401
|
return new ConcurrentUpdateError({
|
|
1509
2402
|
currentVersion: typeof details.currentVersion === "string" ? details.currentVersion : null,
|
|
1510
2403
|
currentRecord: details.currentRecord ?? null,
|
|
1511
|
-
message: typeof e.message === "string" ? e.message : void 0
|
|
2404
|
+
message: typeof e.message === "string" ? e.message : void 0,
|
|
2405
|
+
userMessage
|
|
1512
2406
|
});
|
|
1513
2407
|
}
|
|
1514
2408
|
function formatHttpFailureMessage(message, meta) {
|
|
@@ -1563,6 +2457,80 @@ function createQuietHttpLogger() {
|
|
|
1563
2457
|
};
|
|
1564
2458
|
return logger;
|
|
1565
2459
|
}
|
|
2460
|
+
var RECOGNIZED_DROP_REASONS = new Set(
|
|
2461
|
+
DroppedFieldsEventSchema.shape.reason.options
|
|
2462
|
+
);
|
|
2463
|
+
var UNRECOGNIZED_DROP_REASON = "objectui:unrecognized-drop-reason";
|
|
2464
|
+
function isRecognizedDropReason(reason) {
|
|
2465
|
+
return RECOGNIZED_DROP_REASONS.has(reason);
|
|
2466
|
+
}
|
|
2467
|
+
function isWireDroppedFieldsEntry(e) {
|
|
2468
|
+
return !!e && typeof e === "object" && Array.isArray(e.fields) && e.fields.some((f) => typeof f === "string");
|
|
2469
|
+
}
|
|
2470
|
+
function asDroppedFieldsNotice(entry, fallbackObject) {
|
|
2471
|
+
const fields = entry.fields.filter((f) => typeof f === "string");
|
|
2472
|
+
const object = typeof entry.object === "string" ? entry.object : fallbackObject;
|
|
2473
|
+
if (isRecognizedDropReason(entry.reason)) {
|
|
2474
|
+
return { ...entry, object, fields, reason: entry.reason };
|
|
2475
|
+
}
|
|
2476
|
+
return {
|
|
2477
|
+
...entry,
|
|
2478
|
+
object,
|
|
2479
|
+
fields,
|
|
2480
|
+
reason: UNRECOGNIZED_DROP_REASON,
|
|
2481
|
+
unrecognizedReason: entry.reason
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
var UNATTRIBUTED_STRIP_OBJECT = "";
|
|
2485
|
+
var META_ROUTE_ABSENT_CODES = ["ROUTE_NOT_FOUND", "NOT_IMPLEMENTED"];
|
|
2486
|
+
var IMPORT_MAPPINGS_UNKNOWN_KIND_CODE = "INVALID_REQUEST";
|
|
2487
|
+
var IMPORT_MAPPINGS_UNKNOWN_KIND_STATUS = 400;
|
|
2488
|
+
var META_ABSENT_STATUSES = [404, 501];
|
|
2489
|
+
var META_REFUSAL_CODES = ["UNAUTHENTICATED", "PERMISSION_DENIED"];
|
|
2490
|
+
var META_REFUSAL_STATUSES = [401, 403, 405];
|
|
2491
|
+
function classifyImportMappingsFailure(error) {
|
|
2492
|
+
const err = error ?? {};
|
|
2493
|
+
const code = typeof err.code === "string" && err.code.length > 0 ? err.code : void 0;
|
|
2494
|
+
const message = typeof err.message === "string" ? err.message : void 0;
|
|
2495
|
+
const status = typeof err.httpStatus === "number" ? err.httpStatus : typeof err.status === "number" ? err.status : typeof err.statusCode === "number" ? err.statusCode : void 0;
|
|
2496
|
+
const found = { code, status, message };
|
|
2497
|
+
if (errorCodeIsAnyOf({ code }, META_ROUTE_ABSENT_CODES)) {
|
|
2498
|
+
return { kind: "not-served", ...found };
|
|
2499
|
+
}
|
|
2500
|
+
if (errorCodeIs({ code }, IMPORT_MAPPINGS_UNKNOWN_KIND_CODE) && status === IMPORT_MAPPINGS_UNKNOWN_KIND_STATUS) {
|
|
2501
|
+
return { kind: "not-served", ...found };
|
|
2502
|
+
}
|
|
2503
|
+
if (errorCodeIsAnyOf({ code }, META_REFUSAL_CODES)) {
|
|
2504
|
+
return { kind: "refused", ...found };
|
|
2505
|
+
}
|
|
2506
|
+
if (status !== void 0 && META_REFUSAL_STATUSES.includes(status)) {
|
|
2507
|
+
return { kind: "refused", ...found };
|
|
2508
|
+
}
|
|
2509
|
+
if (code === void 0 && status !== void 0 && META_ABSENT_STATUSES.includes(status)) {
|
|
2510
|
+
return { kind: "not-served", ...found };
|
|
2511
|
+
}
|
|
2512
|
+
return { kind: "unreadable", ...found };
|
|
2513
|
+
}
|
|
2514
|
+
function classifyViewsFailure(error) {
|
|
2515
|
+
const err = error ?? {};
|
|
2516
|
+
const code = typeof err.code === "string" && err.code.length > 0 ? err.code : void 0;
|
|
2517
|
+
const message = typeof err.message === "string" ? err.message : void 0;
|
|
2518
|
+
const status = typeof err.httpStatus === "number" ? err.httpStatus : typeof err.status === "number" ? err.status : typeof err.statusCode === "number" ? err.statusCode : void 0;
|
|
2519
|
+
const found = { code, status, message };
|
|
2520
|
+
if (errorCodeIsAnyOf({ code }, META_ROUTE_ABSENT_CODES)) {
|
|
2521
|
+
return { kind: "not-served", ...found };
|
|
2522
|
+
}
|
|
2523
|
+
if (errorCodeIsAnyOf({ code }, META_REFUSAL_CODES)) {
|
|
2524
|
+
return { kind: "refused", ...found };
|
|
2525
|
+
}
|
|
2526
|
+
if (status !== void 0 && META_REFUSAL_STATUSES.includes(status)) {
|
|
2527
|
+
return { kind: "refused", ...found };
|
|
2528
|
+
}
|
|
2529
|
+
if (code === void 0 && status !== void 0 && META_ABSENT_STATUSES.includes(status)) {
|
|
2530
|
+
return { kind: "not-served", ...found };
|
|
2531
|
+
}
|
|
2532
|
+
return { kind: "unreadable", ...found };
|
|
2533
|
+
}
|
|
1566
2534
|
function stableStringify(value) {
|
|
1567
2535
|
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1568
2536
|
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
@@ -1595,20 +2563,14 @@ function withoutNoOpDrops(droppedFields, sent, stored) {
|
|
|
1595
2563
|
}
|
|
1596
2564
|
return out;
|
|
1597
2565
|
}
|
|
2566
|
+
var VIEW_ITEM_ROUND_TRIP_KEYS = Object.keys(VIEW_CONSOLE_ROUND_TRIP_KEYS).filter((key) => VIEW_CONSOLE_ROUND_TRIP_KEYS[key].includes("viewItem"));
|
|
1598
2567
|
function viewItemObjectName(item) {
|
|
1599
2568
|
const spec = item?.list ?? item;
|
|
1600
|
-
return spec?.data?.object ?? spec?.object
|
|
2569
|
+
return spec?.data?.object ?? spec?.object;
|
|
1601
2570
|
}
|
|
1602
2571
|
var VIEW_OVERLAY_MARKER = "_isOverride";
|
|
1603
|
-
function isLegacyOverlayRow(item, spec) {
|
|
1604
|
-
if (spec && spec.config && typeof spec.config === "object") return false;
|
|
1605
|
-
const viewKind = item?.viewKind ?? spec?.viewKind;
|
|
1606
|
-
return viewKind === "list";
|
|
1607
|
-
}
|
|
1608
2572
|
function isPersonalizationOverlayRow(item, spec) {
|
|
1609
|
-
|
|
1610
|
-
if (spec?.[VIEW_OVERLAY_MARKER] === true) return true;
|
|
1611
|
-
return isLegacyOverlayRow(item, spec);
|
|
2573
|
+
return item?.[VIEW_OVERLAY_MARKER] === true || spec?.[VIEW_OVERLAY_MARKER] === true;
|
|
1612
2574
|
}
|
|
1613
2575
|
var VIEW_OVERLAY_OWNED_KEYS = Object.freeze([
|
|
1614
2576
|
"rowHeight",
|
|
@@ -1640,8 +2602,9 @@ function narrowPersonalizationOverlay(row) {
|
|
|
1640
2602
|
function unwrapViewDraft(resp) {
|
|
1641
2603
|
if (!resp || typeof resp !== "object") return null;
|
|
1642
2604
|
const env = resp;
|
|
1643
|
-
const
|
|
1644
|
-
if (!
|
|
2605
|
+
const raw = "item" in env ? env.item : env;
|
|
2606
|
+
if (!raw || typeof raw !== "object") return null;
|
|
2607
|
+
const body = stripReadDecorations2(raw);
|
|
1645
2608
|
const spec = body.list ?? body;
|
|
1646
2609
|
if (!spec || typeof spec !== "object") return null;
|
|
1647
2610
|
return Object.keys(spec).length > 0 ? spec : null;
|
|
@@ -1697,10 +2660,10 @@ var ObjectStackAdapter = class {
|
|
|
1697
2660
|
// one adapter that has to cope with a backend lacking server atomicity (#2679).
|
|
1698
2661
|
__publicField(this, "batchUnsupported", false);
|
|
1699
2662
|
// The server's declared cross-object atomic-batch capability, read from
|
|
1700
|
-
// discovery at connect() (
|
|
2663
|
+
// discovery at connect() (objectstack-ai/objectstack#3298 / objectui #2693). `true` → the
|
|
1701
2664
|
// backend GUARANTEES an atomic `/batch`, so batchTransaction trusts it and
|
|
1702
2665
|
// never degrades to the non-atomic emulation (any failure surfaces as a real
|
|
1703
|
-
// error). `false` or `undefined` (capability absent → backend predates #3298)
|
|
2666
|
+
// error). `false` or `undefined` (capability absent → backend predates objectstack-ai/objectstack#3298)
|
|
1704
2667
|
// → keep the legacy runtime-probe + emulation fallback so a save is still
|
|
1705
2668
|
// possible; dropping it there would turn "saves, less safe" into "no save
|
|
1706
2669
|
// path" on older backends (#2679 compatibility constraint).
|
|
@@ -1711,7 +2674,7 @@ var ObjectStackAdapter = class {
|
|
|
1711
2674
|
// inline-edit "Save All" writes without a manual reload.
|
|
1712
2675
|
__publicField(this, "mutationListeners", /* @__PURE__ */ new Set());
|
|
1713
2676
|
// Subscribers registered via onWriteWarning(). Emitted after a create/update
|
|
1714
|
-
// whose response carried `droppedFields` (
|
|
2677
|
+
// whose response carried `droppedFields` (objectstack-ai/objectstack#3431 / objectstack-ai/objectstack#3455) so the app
|
|
1715
2678
|
// shell can surface a toast instead of the strip passing silently.
|
|
1716
2679
|
__publicField(this, "writeWarningListeners", /* @__PURE__ */ new Set());
|
|
1717
2680
|
// Subscribers registered via onSaveAdvisory(). Emitted after a metadata save
|
|
@@ -1720,6 +2683,18 @@ var ObjectStackAdapter = class {
|
|
|
1720
2683
|
// above in every respect except which door produced the event: that one is
|
|
1721
2684
|
// record CRUD, this one is the metadata save door.
|
|
1722
2685
|
__publicField(this, "saveAdvisoryListeners", /* @__PURE__ */ new Set());
|
|
2686
|
+
// Subscribers registered via onMetadataReadWarning(). Emitted when a metadata
|
|
2687
|
+
// READ failed in a way that is NOT the supported "this deployment does not
|
|
2688
|
+
// serve that kind" shape, and was degraded to an empty result anyway
|
|
2689
|
+
// (objectui#7741). Third sibling of the two sets above: same seam shape, and
|
|
2690
|
+
// the opposite direction — those two describe a write that succeeded, this
|
|
2691
|
+
// one a read that did not happen.
|
|
2692
|
+
__publicField(this, "metadataReadWarningListeners", /* @__PURE__ */ new Set());
|
|
2693
|
+
// [ADR-0066] The session's REPORTED system capabilities, pushed in by the
|
|
2694
|
+
// host (see `setSystemCapabilities`). `undefined` means NO answer was ever
|
|
2695
|
+
// reported — which is NOT the same as a reported-empty grant, and the two
|
|
2696
|
+
// are treated differently by `maySetViewConfig` below.
|
|
2697
|
+
__publicField(this, "systemCapabilities");
|
|
1723
2698
|
this.client = new ObjectStackClient({ ...config, logger: createQuietHttpLogger() });
|
|
1724
2699
|
this.installSaveAdvisoryInterceptor();
|
|
1725
2700
|
this.metadataCache = new MetadataCache(config.cache);
|
|
@@ -1728,6 +2703,7 @@ var ObjectStackAdapter = class {
|
|
|
1728
2703
|
this.reconnectDelay = config.reconnectDelay ?? 1e3;
|
|
1729
2704
|
this.baseUrl = config.baseUrl;
|
|
1730
2705
|
this.token = config.token;
|
|
2706
|
+
this.systemCapabilities = config.systemCapabilities;
|
|
1731
2707
|
this.fetchImpl = config.fetch || globalThis.fetch.bind(globalThis);
|
|
1732
2708
|
}
|
|
1733
2709
|
/**
|
|
@@ -1901,7 +2877,7 @@ var ObjectStackAdapter = class {
|
|
|
1901
2877
|
* — a per-object metadata-driven search (ADR-0061) — this consults the search
|
|
1902
2878
|
* index and ranks hits across objects, so it surfaces records the per-object
|
|
1903
2879
|
* fanout misses. Global affordances (⌘K command palette, search page) prefer
|
|
1904
|
-
* this path (
|
|
2880
|
+
* this path (objectstack-ai/objectstack#3371).
|
|
1905
2881
|
*
|
|
1906
2882
|
* Returns `{ query, hits }`. A backend without the search plugin installed
|
|
1907
2883
|
* answers `404`; we treat that as "no global search here" and return an empty
|
|
@@ -1934,10 +2910,10 @@ var ObjectStackAdapter = class {
|
|
|
1934
2910
|
if (!res.ok) {
|
|
1935
2911
|
if (res.status === 404) return { query: trimmed, hits: [] };
|
|
1936
2912
|
const errorBody = await res.json().catch(() => ({ message: res.statusText }));
|
|
1937
|
-
const
|
|
1938
|
-
|
|
1939
|
-
);
|
|
2913
|
+
const envelope = readErrorEnvelope(errorBody);
|
|
2914
|
+
const err = new Error(envelope.message ?? res.statusText);
|
|
1940
2915
|
err.status = res.status;
|
|
2916
|
+
err.code = envelope.code;
|
|
1941
2917
|
throw err;
|
|
1942
2918
|
}
|
|
1943
2919
|
const body = await res.json();
|
|
@@ -2040,24 +3016,28 @@ var ObjectStackAdapter = class {
|
|
|
2040
3016
|
}
|
|
2041
3017
|
}
|
|
2042
3018
|
/**
|
|
2043
|
-
* Read `droppedFields` off a create/update response (
|
|
3019
|
+
* Read `droppedFields` off a create/update response (objectstack-ai/objectstack#3431 / objectstack-ai/objectstack#3455)
|
|
2044
3020
|
* and, when present, notify write-warning subscribers. Tolerant of a client
|
|
2045
3021
|
* whose response type predates `droppedFields`: the field is read structurally
|
|
2046
3022
|
* and validated, so an older client (or a backend that never drops) is a no-op.
|
|
3023
|
+
*
|
|
3024
|
+
* SHAPE decides whether an entry is an event at all (it must name at least one
|
|
3025
|
+
* field); `object`, `fields` and `reason` are then PARSED — an unrecognized
|
|
3026
|
+
* reason routed to the skew arm, a non-string field element refused, a missing
|
|
3027
|
+
* `object` healed from `resource` — never asserted into the union, and the
|
|
3028
|
+
* entry itself never dropped for them (objectui#4934, `f75810e7c`).
|
|
2047
3029
|
*/
|
|
2048
3030
|
notifyDroppedFields(operation, resource, result, id, sent) {
|
|
2049
3031
|
const dropped = result?.droppedFields;
|
|
2050
3032
|
if (!Array.isArray(dropped) || dropped.length === 0) return;
|
|
2051
|
-
const valid = dropped.filter(
|
|
2052
|
-
(e) => !!e && typeof e === "object" && Array.isArray(e.fields) && e.fields.length > 0
|
|
2053
|
-
);
|
|
3033
|
+
const valid = dropped.filter(isWireDroppedFieldsEntry).map((e) => asDroppedFieldsNotice(e, resource));
|
|
2054
3034
|
const stored = result?.record;
|
|
2055
3035
|
const droppedFields = withoutNoOpDrops(valid, sent, stored);
|
|
2056
3036
|
if (droppedFields.length === 0) return;
|
|
2057
3037
|
this.emitWriteWarning({ operation, resource, ...id !== void 0 ? { id } : {}, droppedFields });
|
|
2058
3038
|
}
|
|
2059
3039
|
/**
|
|
2060
|
-
* Same, for the cross-object transactional batch (
|
|
3040
|
+
* Same, for the cross-object transactional batch (objectstack-ai/objectstack#3794). Its
|
|
2061
3041
|
* response hangs the events off a top-level `droppedFields` list, each tagged
|
|
2062
3042
|
* with the `index` of the operation it came from — `results` entries are bare
|
|
2063
3043
|
* record echoes with nowhere to hang a per-row list.
|
|
@@ -2073,13 +3053,13 @@ var ObjectStackAdapter = class {
|
|
|
2073
3053
|
if (!Array.isArray(dropped) || dropped.length === 0) return;
|
|
2074
3054
|
const results = payload?.results;
|
|
2075
3055
|
for (const entry of dropped) {
|
|
2076
|
-
if (!entry
|
|
3056
|
+
if (!isWireDroppedFieldsEntry(entry)) continue;
|
|
2077
3057
|
const e = entry;
|
|
2078
|
-
if (!Array.isArray(e.fields) || e.fields.length === 0) continue;
|
|
2079
3058
|
const op = typeof e.index === "number" ? operations[e.index] : void 0;
|
|
3059
|
+
const object = typeof e.object === "string" ? e.object : typeof op?.object === "string" ? op.object : UNATTRIBUTED_STRIP_OBJECT;
|
|
2080
3060
|
const stored = typeof e.index === "number" && Array.isArray(results) ? results[e.index] : void 0;
|
|
2081
3061
|
const [live] = withoutNoOpDrops(
|
|
2082
|
-
[{
|
|
3062
|
+
[asDroppedFieldsNotice({ fields: e.fields, reason: e.reason }, object)],
|
|
2083
3063
|
op?.data,
|
|
2084
3064
|
stored
|
|
2085
3065
|
);
|
|
@@ -2087,7 +3067,7 @@ var ObjectStackAdapter = class {
|
|
|
2087
3067
|
const operation = (op?.action ?? "create") === "create" ? "create" : "update";
|
|
2088
3068
|
this.emitWriteWarning({
|
|
2089
3069
|
operation,
|
|
2090
|
-
resource:
|
|
3070
|
+
resource: object,
|
|
2091
3071
|
...op?.id !== void 0 && op?.id !== null ? { id: op.id } : {},
|
|
2092
3072
|
droppedFields: [live]
|
|
2093
3073
|
});
|
|
@@ -2095,7 +3075,7 @@ var ObjectStackAdapter = class {
|
|
|
2095
3075
|
}
|
|
2096
3076
|
/**
|
|
2097
3077
|
* Subscribe to write-warning events (a create/update dropped caller-supplied
|
|
2098
|
-
* fields — #3431
|
|
3078
|
+
* fields — objectstack-ai/objectstack#3431 / objectstack-ai/objectstack#3455). Returns an unsubscribe function. The app shell uses
|
|
2099
3079
|
* this to toast the user; the write itself already succeeded.
|
|
2100
3080
|
*/
|
|
2101
3081
|
onWriteWarning(callback) {
|
|
@@ -2109,7 +3089,7 @@ var ObjectStackAdapter = class {
|
|
|
2109
3089
|
* advisory findings on a save that SUCCEEDED (#4237; backend
|
|
2110
3090
|
* objectstack#7435). Returns an unsubscribe function.
|
|
2111
3091
|
*
|
|
2112
|
-
* Deliberately the same seam as {@link onWriteWarning} (#3431
|
|
3092
|
+
* Deliberately the same seam as {@link onWriteWarning} (objectstack-ai/objectstack#3431 / objectstack-ai/objectstack#3455), which
|
|
2113
3093
|
* is what {@link MetadataSaveAdvisoryEvent}'s own declaration already said it
|
|
2114
3094
|
* was modelled on. It is a SIBLING of that channel rather than a second
|
|
2115
3095
|
* payload pushed down it: `WriteWarningEvent` is a closed shape whose
|
|
@@ -2146,6 +3126,45 @@ var ObjectStackAdapter = class {
|
|
|
2146
3126
|
}
|
|
2147
3127
|
}
|
|
2148
3128
|
}
|
|
3129
|
+
/**
|
|
3130
|
+
* Subscribe to metadata read-warning events — a metadata READ that could not
|
|
3131
|
+
* be answered and was degraded to an empty result anyway (objectui#7741).
|
|
3132
|
+
* Returns an unsubscribe function. The app shell uses this to toast the user;
|
|
3133
|
+
* the caller has already been handed the empty result.
|
|
3134
|
+
*
|
|
3135
|
+
* Deliberately the same seam as {@link onWriteWarning} and
|
|
3136
|
+
* {@link onSaveAdvisory}, and a SIBLING of them rather than a payload pushed
|
|
3137
|
+
* down either: both of those announce a write that SUCCEEDED, and an event
|
|
3138
|
+
* saying "this read did not happen" carried on one of them would make it lie
|
|
3139
|
+
* about what occurred. What is reused is the seam's SHAPE — one long-lived
|
|
3140
|
+
* instance with a `subscribe -> unsubscribe` registration that
|
|
3141
|
+
* `AdapterProvider` wires once — not its event type.
|
|
3142
|
+
*
|
|
3143
|
+
* ⛔ Nothing here changes what a caller RECEIVES. `listImportMappings` still
|
|
3144
|
+
* answers `[]` on every failure, including the loud ones; this channel is
|
|
3145
|
+
* added ALONGSIDE that return, which is why it is not a change to a surface
|
|
3146
|
+
* published since `@object-ui/data-objectstack@17.1.0`.
|
|
3147
|
+
*/
|
|
3148
|
+
onMetadataReadWarning(callback) {
|
|
3149
|
+
this.metadataReadWarningListeners.add(callback);
|
|
3150
|
+
return () => {
|
|
3151
|
+
this.metadataReadWarningListeners.delete(callback);
|
|
3152
|
+
};
|
|
3153
|
+
}
|
|
3154
|
+
/**
|
|
3155
|
+
* Notify all metadata read-warning subscribers. Isolated exactly like
|
|
3156
|
+
* {@link emitWriteWarning}: a throwing listener must neither break the caller
|
|
3157
|
+
* nor starve the others.
|
|
3158
|
+
*/
|
|
3159
|
+
emitMetadataReadWarning(event) {
|
|
3160
|
+
for (const listener of this.metadataReadWarningListeners) {
|
|
3161
|
+
try {
|
|
3162
|
+
listener(event);
|
|
3163
|
+
} catch (err) {
|
|
3164
|
+
console.warn("ObjectStackAdapter: metadata read-warning listener error", err);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
2149
3168
|
/**
|
|
2150
3169
|
* Install the ONE emitter for the metadata save door (#4237).
|
|
2151
3170
|
*
|
|
@@ -2203,6 +3222,12 @@ var ObjectStackAdapter = class {
|
|
|
2203
3222
|
this.emitSaveAdvisory({
|
|
2204
3223
|
type,
|
|
2205
3224
|
name,
|
|
3225
|
+
// #5026 — this interceptor wraps `meta.saveItem`, the SAVE door
|
|
3226
|
+
// (`PUT /meta/:type/:name`) and only that one. The SDK's publish
|
|
3227
|
+
// door (`meta.publishItem`) has no caller in this repo, so wiring
|
|
3228
|
+
// it here would be a surface with no consumer; `MetadataClient` is
|
|
3229
|
+
// where the publish door is actually taken.
|
|
3230
|
+
door: "save",
|
|
2206
3231
|
mode: result?.state === "draft" ? "draft" : "publish",
|
|
2207
3232
|
advisories
|
|
2208
3233
|
});
|
|
@@ -2250,7 +3275,7 @@ var ObjectStackAdapter = class {
|
|
|
2250
3275
|
data,
|
|
2251
3276
|
opts?.ifMatch ? { ifMatch: opts.ifMatch } : void 0
|
|
2252
3277
|
);
|
|
2253
|
-
this.emitMutation({ type: "update", resource, id, record: { ...result.record } });
|
|
3278
|
+
this.emitMutation({ type: "update", resource, id: String(id), record: { ...result.record } });
|
|
2254
3279
|
this.notifyDroppedFields("update", resource, result, id, data);
|
|
2255
3280
|
return result.record;
|
|
2256
3281
|
} catch (err) {
|
|
@@ -2273,7 +3298,7 @@ var ObjectStackAdapter = class {
|
|
|
2273
3298
|
opts?.ifMatch ? { ifMatch: opts.ifMatch } : void 0
|
|
2274
3299
|
);
|
|
2275
3300
|
if (result.success) {
|
|
2276
|
-
this.emitMutation({ type: "delete", resource, id });
|
|
3301
|
+
this.emitMutation({ type: "delete", resource, id: String(id) });
|
|
2277
3302
|
}
|
|
2278
3303
|
return result.success;
|
|
2279
3304
|
} catch (err) {
|
|
@@ -2374,25 +3399,25 @@ var ObjectStackAdapter = class {
|
|
|
2374
3399
|
* @returns Promise resolving to array of results
|
|
2375
3400
|
*/
|
|
2376
3401
|
/**
|
|
2377
|
-
* Cross-object transactional batch (
|
|
3402
|
+
* Cross-object transactional batch (objectstack-ai/objectstack#1604 / ADR-0034 item 4).
|
|
2378
3403
|
* Runs the operations in ONE server transaction — commit all or roll back
|
|
2379
3404
|
* all. A field value of `{ $ref: <earlier op index> }` resolves to that op's
|
|
2380
3405
|
* created id, so a child can reference its parent created earlier in the same
|
|
2381
3406
|
* batch (master-detail).
|
|
2382
3407
|
*
|
|
2383
3408
|
* Transport: the published `@objectstack/client` SDK method
|
|
2384
|
-
* `data.batchTransaction` (
|
|
3409
|
+
* `data.batchTransaction` (objectstack-ai/objectstack#3271; shipped since client v16, our
|
|
2385
3410
|
* dependency floor). Per AGENTS.md §7 data always flows through the client —
|
|
2386
3411
|
* never a hand-rolled `fetch('/api/v1/batch')`.
|
|
2387
3412
|
*
|
|
2388
|
-
* Fallback decision — declarative capability negotiation (
|
|
3413
|
+
* Fallback decision — declarative capability negotiation (objectstack-ai/objectstack#3298 /
|
|
2389
3414
|
* objectui #2693). At connect() we read `capabilities.transactionalBatch`
|
|
2390
3415
|
* from discovery:
|
|
2391
3416
|
* - Declared `true` → the backend GUARANTEES atomicity (declared ===
|
|
2392
3417
|
* enforced). We TRUST it: any batch failure — including 404/405/501 —
|
|
2393
3418
|
* surfaces as a real error. No non-atomic client-side compensation. This
|
|
2394
3419
|
* is the path modern backends take.
|
|
2395
|
-
* - Declared `false`, or ABSENT (backend predates #3298) → we can't rely on
|
|
3420
|
+
* - Declared `false`, or ABSENT (backend predates objectstack-ai/objectstack#3298) → we can't rely on
|
|
2396
3421
|
* server atomicity, so we keep the legacy behaviour: on 404/405 (no
|
|
2397
3422
|
* endpoint) or 501 (runtime without transactions) degrade to the
|
|
2398
3423
|
* client-side, NON-atomic {@link emulateBatchTransaction} so a save is
|
|
@@ -2816,9 +3841,10 @@ var ObjectStackAdapter = class {
|
|
|
2816
3841
|
const res = await this.fetchImpl(url, { method: "GET", headers });
|
|
2817
3842
|
if (!res.ok) {
|
|
2818
3843
|
const errorBody = await res.json().catch(() => ({ message: res.statusText }));
|
|
2819
|
-
const
|
|
3844
|
+
const envelope = readErrorEnvelope(errorBody);
|
|
3845
|
+
const err = new Error(envelope.message ?? res.statusText);
|
|
2820
3846
|
err.status = res.status;
|
|
2821
|
-
err.code =
|
|
3847
|
+
err.code = envelope.code;
|
|
2822
3848
|
err.httpStatus = res.status;
|
|
2823
3849
|
throw err;
|
|
2824
3850
|
}
|
|
@@ -2868,16 +3894,51 @@ var ObjectStackAdapter = class {
|
|
|
2868
3894
|
queryParams.set("searchFields", request.searchFields.join(","));
|
|
2869
3895
|
}
|
|
2870
3896
|
}
|
|
3897
|
+
return this.fetchExportBlob(resource, queryParams);
|
|
3898
|
+
}
|
|
3899
|
+
/**
|
|
3900
|
+
* Download the server's import template:
|
|
3901
|
+
* `GET /api/v1/data/:object/export?template=true` (objectui#9600).
|
|
3902
|
+
*
|
|
3903
|
+
* Same route as {@link exportDownload}, with the server's template switch. It
|
|
3904
|
+
* sends only `template=true`: the server refuses the export's row parameters
|
|
3905
|
+
* on a template request, and its answer is always an xlsx workbook.
|
|
3906
|
+
*
|
|
3907
|
+
* The server writes the template's labels in the request's locale, and the
|
|
3908
|
+
* import accepts a translated label only in its own request's locale. The
|
|
3909
|
+
* import request goes through `@objectstack/client`, which stamps
|
|
3910
|
+
* `Accept-Language` with the client's locale when one is set (and the host's
|
|
3911
|
+
* `fetch` stamps its own otherwise). This request bypasses the client, so it
|
|
3912
|
+
* stamps the client's locale the same way. Both requests then carry the same
|
|
3913
|
+
* locale.
|
|
3914
|
+
*/
|
|
3915
|
+
async downloadImportTemplate(resource) {
|
|
3916
|
+
const locale = this.client.getLocale();
|
|
3917
|
+
return this.fetchExportBlob(
|
|
3918
|
+
resource,
|
|
3919
|
+
new URLSearchParams({ template: "true" }),
|
|
3920
|
+
locale ? { "Accept-Language": locale } : void 0
|
|
3921
|
+
);
|
|
3922
|
+
}
|
|
3923
|
+
/**
|
|
3924
|
+
* GET `/api/v1/data/:object/export` with the given query and answer the body
|
|
3925
|
+
* as a Blob. A failure throws an `Error` that carries the server's `status`
|
|
3926
|
+
* and its ADR-0112 `code`. The one request path {@link exportDownload} and
|
|
3927
|
+
* {@link downloadImportTemplate} share.
|
|
3928
|
+
*/
|
|
3929
|
+
async fetchExportBlob(resource, queryParams, extraHeaders) {
|
|
2871
3930
|
const baseUrl = this.baseUrl.replace(/\/$/, "");
|
|
2872
3931
|
const hasApiVersionSuffix = /\/api\/v\d+$/i.test(baseUrl);
|
|
2873
3932
|
const dataPath = hasApiVersionSuffix ? "/data" : "/api/v1/data";
|
|
2874
3933
|
const url = `${baseUrl}${dataPath}/${encodeURIComponent(resource)}/export?${queryParams.toString()}`;
|
|
2875
|
-
const headers = { ...this.getAuthHeaders() };
|
|
3934
|
+
const headers = { ...this.getAuthHeaders(), ...extraHeaders };
|
|
2876
3935
|
const res = await this.fetchImpl(url, { method: "GET", headers, credentials: "include" });
|
|
2877
3936
|
if (!res.ok) {
|
|
2878
3937
|
const errorBody = await res.json().catch(() => ({ message: res.statusText }));
|
|
2879
|
-
const
|
|
3938
|
+
const envelope = readErrorEnvelope(errorBody);
|
|
3939
|
+
const err = new Error(envelope.message ?? res.statusText);
|
|
2880
3940
|
err.status = res.status;
|
|
3941
|
+
err.code = envelope.code;
|
|
2881
3942
|
throw err;
|
|
2882
3943
|
}
|
|
2883
3944
|
return await res.blob();
|
|
@@ -2898,7 +3959,8 @@ var ObjectStackAdapter = class {
|
|
|
2898
3959
|
if (Array.isArray(params.$filter)) {
|
|
2899
3960
|
options.filters = translateFilterArray(params.$filter);
|
|
2900
3961
|
} else {
|
|
2901
|
-
|
|
3962
|
+
const lowered = convertFiltersToAST(params.$filter);
|
|
3963
|
+
if (lowered !== void 0) options.filters = lowered;
|
|
2902
3964
|
}
|
|
2903
3965
|
}
|
|
2904
3966
|
}
|
|
@@ -3018,13 +4080,16 @@ var ObjectStackAdapter = class {
|
|
|
3018
4080
|
});
|
|
3019
4081
|
if (!res.ok) {
|
|
3020
4082
|
const errBody = await res.json().catch(() => ({ message: res.statusText }));
|
|
3021
|
-
const
|
|
4083
|
+
const envelope = readErrorEnvelope(errBody);
|
|
4084
|
+
const err = new Error(envelope.message ?? res.statusText);
|
|
3022
4085
|
err.status = res.status;
|
|
4086
|
+
err.code = envelope.code;
|
|
3023
4087
|
throw err;
|
|
3024
4088
|
}
|
|
3025
4089
|
const body = await res.json();
|
|
3026
4090
|
const data = body && typeof body === "object" && "success" in body && "data" in body ? body.data : body;
|
|
3027
|
-
|
|
4091
|
+
const item = data && typeof data === "object" && "item" in data ? data.item : data;
|
|
4092
|
+
return attachObjectSortability(item, data && typeof data === "object" ? data.sortability : void 0);
|
|
3028
4093
|
}
|
|
3029
4094
|
/**
|
|
3030
4095
|
* List every registered object (code- and DB-defined) from the metadata
|
|
@@ -3251,7 +4316,42 @@ var ObjectStackAdapter = class {
|
|
|
3251
4316
|
* (vs. a system view being personalized for the first time). Omit /
|
|
3252
4317
|
* `false` for the default overlay-marking behavior.
|
|
3253
4318
|
*/
|
|
4319
|
+
/**
|
|
4320
|
+
* [ADR-0066] Tell this adapter which system capabilities the session holds.
|
|
4321
|
+
*
|
|
4322
|
+
* Pass `undefined` for "no answer was reported" (a backend predating
|
|
4323
|
+
* ADR-0066, or no permission provider mounted). Pass `[]` for a real,
|
|
4324
|
+
* reported, empty grant — {@link maySetViewConfig} treats those two
|
|
4325
|
+
* differently and callers must not collapse them, which is the same
|
|
4326
|
+
* distinction `MePermissionsProvider` preserves natively (objectui#4656).
|
|
4327
|
+
*/
|
|
4328
|
+
setSystemCapabilities(capabilities) {
|
|
4329
|
+
this.systemCapabilities = capabilities ? [...capabilities] : void 0;
|
|
4330
|
+
}
|
|
4331
|
+
/**
|
|
4332
|
+
* May this session write ORG-WIDE view configuration?
|
|
4333
|
+
*
|
|
4334
|
+
* **Unknown fails OPEN**, deliberately, and this is the one judgement in the
|
|
4335
|
+
* gate worth reading twice. It is the doctrine `PermissionContextValue`
|
|
4336
|
+
* .`hasCapabilities` states for every ADR-0066 gate in this repo
|
|
4337
|
+
* (objectui#4656, framework#3923): the server enforces `manage_metadata` on
|
|
4338
|
+
* the metadata door regardless of what the client believes, so a client-side
|
|
4339
|
+
* denial on MISSING DATA cannot protect anything the server was not already
|
|
4340
|
+
* protecting — it can only break a permitted user. Failing closed here would
|
|
4341
|
+
* have refused the write on every deployment predating ADR-0066 and every
|
|
4342
|
+
* host with no permission provider, which is "break the write for everyone"
|
|
4343
|
+
* wearing the costume of a security fix.
|
|
4344
|
+
*
|
|
4345
|
+
* A REPORTED empty array gates strictly: "holds nothing" is a real answer.
|
|
4346
|
+
*/
|
|
4347
|
+
maySetViewConfig() {
|
|
4348
|
+
if (this.systemCapabilities === void 0) return true;
|
|
4349
|
+
return this.systemCapabilities.includes(VIEW_CONFIG_CAPABILITY);
|
|
4350
|
+
}
|
|
3254
4351
|
async updateViewConfig(objectName, viewId, config, opts) {
|
|
4352
|
+
if (!this.maySetViewConfig()) {
|
|
4353
|
+
throw new ViewConfigPermissionDeniedError(objectName, viewId);
|
|
4354
|
+
}
|
|
3255
4355
|
await this.connect();
|
|
3256
4356
|
const merged = {
|
|
3257
4357
|
...config || {},
|
|
@@ -3279,6 +4379,42 @@ var ObjectStackAdapter = class {
|
|
|
3279
4379
|
* the metadata index is name-only, not field-typed, so the route has no
|
|
3280
4380
|
* `?object=` to push the filter down into. {@link listViewOverrides}
|
|
3281
4381
|
* reads the same rows through the same accessor.
|
|
4382
|
+
*
|
|
4383
|
+
* ## Every failure still degrades to an empty list — and now says which kind
|
|
4384
|
+
* ## of failure it was (objectui#8151)
|
|
4385
|
+
*
|
|
4386
|
+
* The degrade is unchanged and deliberate, exactly as it is one method over
|
|
4387
|
+
* in {@link listImportMappings}: a host with no metadata door keeps answering
|
|
4388
|
+
* `[]` rather than breaking the page. What changed is that the OTHER failures
|
|
4389
|
+
* no longer render as that one.
|
|
4390
|
+
*
|
|
4391
|
+
* This method's empty list is read as *this object has no saved views*, and
|
|
4392
|
+
* that reading reaches the user in two places measured on this tree: the list
|
|
4393
|
+
* view switcher simply shows fewer tabs, and `@object-ui/core`'s
|
|
4394
|
+
* `elementDataSourceViewNotFoundMessage` states it outright. So a session
|
|
4395
|
+
* whose token lapsed mid-read was shown an object that appears to have no
|
|
4396
|
+
* saved views AT ALL — including ones the user created — with a
|
|
4397
|
+
* `console.warn` as the only discriminator, in a console nothing in the UI
|
|
4398
|
+
* points at. That is the silence objectui#7741 removed from the sibling after
|
|
4399
|
+
* it produced a confident wrong diagnosis in objectstack#14026.
|
|
4400
|
+
*
|
|
4401
|
+
* The `catch` now asks {@link classifyViewsFailure} what the failure WAS,
|
|
4402
|
+
* reading the error's own ADR-0112 `code` and status — never "is the result
|
|
4403
|
+
* empty", which is what both conditions produce and so can never tell them
|
|
4404
|
+
* apart — and anything that is not the doorless shape is announced on
|
|
4405
|
+
* {@link onMetadataReadWarning}.
|
|
4406
|
+
*
|
|
4407
|
+
* ⛔ That classifier is a SEPARATE reading, not a second caller of the
|
|
4408
|
+
* sibling's: `view`'s quiet set is strictly smaller, because the arm
|
|
4409
|
+
* `listImportMappings` is built around (*an older server without this kind*)
|
|
4410
|
+
* has no members here. See {@link classifyViewsFailure} for the measurement.
|
|
4411
|
+
*
|
|
4412
|
+
* ⛔ The RETURN is untouched. This method has answered `Promise<any[]>`, never
|
|
4413
|
+
* throwing, since `@object-ui/data-objectstack@17.1.0`; a consumer that reads
|
|
4414
|
+
* nothing new sees exactly what it saw before, including on the loud arms.
|
|
4415
|
+
* Applying framework objectstack#13906 decision 1 option A — *a thing that could not be
|
|
4416
|
+
* READ is not a thing that is ABSENT* — is done by ADDING a channel, not by
|
|
4417
|
+
* moving that contract.
|
|
3282
4418
|
*/
|
|
3283
4419
|
async listViews(objectName, options) {
|
|
3284
4420
|
await this.connect();
|
|
@@ -3304,18 +4440,35 @@ var ObjectStackAdapter = class {
|
|
|
3304
4440
|
const spec = v.list ?? v;
|
|
3305
4441
|
const isDraft = v._draft === true || spec?._draft === true;
|
|
3306
4442
|
if (spec && spec.config && typeof spec.config === "object") {
|
|
3307
|
-
|
|
4443
|
+
const row = {
|
|
3308
4444
|
...spec.config,
|
|
3309
4445
|
name: spec.name ?? spec.config.name,
|
|
3310
|
-
label: spec.label ?? spec.config.label
|
|
3311
|
-
isDefault: !!spec.isDefault,
|
|
3312
|
-
...isDraft ? { _draft: true } : {}
|
|
4446
|
+
label: spec.label ?? spec.config.label
|
|
3313
4447
|
};
|
|
4448
|
+
if (spec.object !== void 0) row.object = spec.object;
|
|
4449
|
+
for (const key of VIEW_ITEM_ROUND_TRIP_KEYS) {
|
|
4450
|
+
if (spec[key] !== void 0) row[key] = spec[key];
|
|
4451
|
+
}
|
|
4452
|
+
row.isDefault = !!spec.isDefault;
|
|
4453
|
+
if (isDraft) row._draft = true;
|
|
4454
|
+
return row;
|
|
3314
4455
|
}
|
|
3315
4456
|
return isDraft ? { ...spec, _draft: true } : spec;
|
|
3316
4457
|
});
|
|
3317
4458
|
} catch (err) {
|
|
3318
4459
|
console.warn("[OBJECTSTACKDataSource] listViews failed:", err);
|
|
4460
|
+
const failure = classifyViewsFailure(err);
|
|
4461
|
+
if (failure.kind !== "not-served") {
|
|
4462
|
+
this.emitMetadataReadWarning({
|
|
4463
|
+
operation: "listViews",
|
|
4464
|
+
kind: "view",
|
|
4465
|
+
objectName,
|
|
4466
|
+
reason: failure.kind,
|
|
4467
|
+
...failure.code !== void 0 ? { code: failure.code } : {},
|
|
4468
|
+
...failure.status !== void 0 ? { status: failure.status } : {},
|
|
4469
|
+
...failure.message !== void 0 ? { message: failure.message } : {}
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
3319
4472
|
return [];
|
|
3320
4473
|
}
|
|
3321
4474
|
}
|
|
@@ -3334,11 +4487,36 @@ var ObjectStackAdapter = class {
|
|
|
3334
4487
|
}
|
|
3335
4488
|
/**
|
|
3336
4489
|
* List registered import `mapping` artifacts targeting a given object
|
|
3337
|
-
* (
|
|
4490
|
+
* (objectstack-ai/objectstack#2611). Reads the `mapping` metadata kind via the overlay API
|
|
3338
4491
|
* and filters by `targetObject` client-side (the metadata index is
|
|
3339
|
-
* name-only). Feeds the import wizard's "saved mapping" selector
|
|
3340
|
-
*
|
|
3341
|
-
*
|
|
4492
|
+
* name-only). Feeds the import wizard's "saved mapping" selector.
|
|
4493
|
+
*
|
|
4494
|
+
* ## Every failure still degrades to an empty list — and now says which kind
|
|
4495
|
+
* ## of failure it was (objectui#7741)
|
|
4496
|
+
*
|
|
4497
|
+
* The degrade is unchanged and deliberate: an older server without the
|
|
4498
|
+
* `mapping` kind must not break the wizard, so it keeps answering `[]` and
|
|
4499
|
+
* the selector simply doesn't appear. That is a real, supported deployment
|
|
4500
|
+
* shape and it stays quiet.
|
|
4501
|
+
*
|
|
4502
|
+
* What changed is that the OTHER failures no longer render as that one. A
|
|
4503
|
+
* refused door and a broken one used to be indistinguishable, in the UI, from
|
|
4504
|
+
* "no mapping is registered" — both were an empty list behind a
|
|
4505
|
+
* `console.warn` nothing pointed at — and that silence produced a confident
|
|
4506
|
+
* wrong diagnosis in a careful reporter (objectstack#14026 was filed, routed
|
|
4507
|
+
* and worked by two seats against a wizard that had been correct since
|
|
4508
|
+
* 17.1.0). So the `catch` now asks {@link classifyImportMappingsFailure} what
|
|
4509
|
+
* the failure WAS, reading the error's own ADR-0112 `code` and status —
|
|
4510
|
+
* never "is the result empty", which is what both conditions produce and so
|
|
4511
|
+
* can never tell them apart — and anything that is not the supported
|
|
4512
|
+
* kind-absent shape is announced on {@link onMetadataReadWarning}.
|
|
4513
|
+
*
|
|
4514
|
+
* ⛔ The RETURN is untouched. This method has answered `Promise<any[]>`, never
|
|
4515
|
+
* throwing, since `@object-ui/data-objectstack@17.1.0`; a consumer that reads
|
|
4516
|
+
* nothing new sees exactly what it saw before, including on the loud arms.
|
|
4517
|
+
* Applying framework objectstack#13906 decision 1 option A — *a thing that could not be
|
|
4518
|
+
* READ is not a thing that is ABSENT* — is done by ADDING a channel, not by
|
|
4519
|
+
* moving that contract.
|
|
3342
4520
|
*/
|
|
3343
4521
|
async listImportMappings(objectName) {
|
|
3344
4522
|
await this.connect();
|
|
@@ -3348,6 +4526,18 @@ var ObjectStackAdapter = class {
|
|
|
3348
4526
|
return items.filter((m) => m && m.targetObject === objectName);
|
|
3349
4527
|
} catch (err) {
|
|
3350
4528
|
console.warn("[OBJECTSTACKDataSource] listImportMappings failed:", err);
|
|
4529
|
+
const failure = classifyImportMappingsFailure(err);
|
|
4530
|
+
if (failure.kind !== "not-served") {
|
|
4531
|
+
this.emitMetadataReadWarning({
|
|
4532
|
+
operation: "listImportMappings",
|
|
4533
|
+
kind: "mapping",
|
|
4534
|
+
objectName,
|
|
4535
|
+
reason: failure.kind,
|
|
4536
|
+
...failure.code !== void 0 ? { code: failure.code } : {},
|
|
4537
|
+
...failure.status !== void 0 ? { status: failure.status } : {},
|
|
4538
|
+
...failure.message !== void 0 ? { message: failure.message } : {}
|
|
4539
|
+
});
|
|
4540
|
+
}
|
|
3351
4541
|
return [];
|
|
3352
4542
|
}
|
|
3353
4543
|
}
|
|
@@ -3602,11 +4792,17 @@ var ObjectStackAdapter = class {
|
|
|
3602
4792
|
*
|
|
3603
4793
|
* The maintainer ruling (2026-08-12) put the answer on the BY-NAME route
|
|
3604
4794
|
* rather than in the list, so the enumeration surface is not widened past what
|
|
3605
|
-
* a by-name probe already implies (objectstack#8013 / PR #8135): an app that
|
|
4795
|
+
* a by-name probe already implies (objectstack#8013 / PR objectstack-ai/objectstack#8135): an app that
|
|
3606
4796
|
* exists and whose `requiredPermissions` the session lacks answers `403` with
|
|
3607
4797
|
* `PERMISSION_DENIED` in the declared envelope, and absence — a nonexistent
|
|
3608
|
-
* name, an unpublished app, an app gated by an absent optional service —
|
|
3609
|
-
*
|
|
4798
|
+
* name, an unpublished app, an app gated by an absent optional service — is
|
|
4799
|
+
* one undifferentiated answer.
|
|
4800
|
+
*
|
|
4801
|
+
* ⚠️ That absence is NOT uniformly a `404`, which this docstring asserted
|
|
4802
|
+
* until objectui#9262 measured it: the 404 covers an app that EXISTS and is
|
|
4803
|
+
* withheld for a non-permission reason, while a name that resolves to nothing
|
|
4804
|
+
* answers `200` with an envelope carrying no `item`. Both are absence and both
|
|
4805
|
+
* read as `not_found`; see {@link metaEnvelopeCarriesItem} for the measurement.
|
|
3610
4806
|
*
|
|
3611
4807
|
* ## Why this is a separate method and not a flavour of {@link getApp}
|
|
3612
4808
|
*
|
|
@@ -3617,19 +4813,41 @@ var ObjectStackAdapter = class {
|
|
|
3617
4813
|
* be cached beside a document about the APP — one grant, and a cached
|
|
3618
4814
|
* denial outlives the session it described.
|
|
3619
4815
|
*
|
|
3620
|
-
* Nothing here throws:
|
|
3621
|
-
*
|
|
3622
|
-
*
|
|
4816
|
+
* Nothing here throws: every outcome is a verdict the caller renders a screen
|
|
4817
|
+
* from, never a catch block. Only the measured `code` produces `denied` —
|
|
4818
|
+
* never a status, never a message (objectui#4408).
|
|
4819
|
+
*
|
|
4820
|
+
* ## objectui#9262 — what this method stopped folding away
|
|
4821
|
+
*
|
|
4822
|
+
* It used to answer `granted` whenever the call did not throw, and `unknown`
|
|
4823
|
+
* for everything that did. Both halves were wrong in the same direction, and
|
|
4824
|
+
* the first was measured on a real server before this change landed:
|
|
4825
|
+
*
|
|
4826
|
+
* - **an app that does not exist answers `200` with the envelope minus its
|
|
4827
|
+
* `item`**, so "did not throw" reported `granted` for a name with nothing
|
|
4828
|
+
* behind it — the shape issue objectui#9262 listed as cause 8 and expected
|
|
4829
|
+
* to be structural. It is the ordinary case: every typo, every never-created
|
|
4830
|
+
* app and every unpublished draft took it. See
|
|
4831
|
+
* {@link metaEnvelopeCarriesItem} for the measurement and the server-side
|
|
4832
|
+
* mechanism.
|
|
4833
|
+
* - a 404 absence and an unreachable server were one `unknown`, though the
|
|
4834
|
+
* transport had already told them apart.
|
|
4835
|
+
*
|
|
4836
|
+
* The verdicts now say only what was obtained: a served document, a refusal
|
|
4837
|
+
* naming permission, an answer that there is no such app here, or no answer
|
|
4838
|
+
* at all. `unknown` is left for the one case where nothing was asked.
|
|
3623
4839
|
*
|
|
3624
4840
|
* @param appName - the app name as it appears in the URL segment
|
|
3625
4841
|
*/
|
|
3626
4842
|
async probeAppAccess(appName) {
|
|
3627
4843
|
if (!appName) return "unknown";
|
|
3628
4844
|
try {
|
|
3629
|
-
await this.client.meta.getItem("app", appName);
|
|
3630
|
-
return "granted";
|
|
4845
|
+
const envelope = await this.client.meta.getItem("app", appName);
|
|
4846
|
+
return metaEnvelopeCarriesItem(envelope) ? "granted" : "not_found";
|
|
3631
4847
|
} catch (err) {
|
|
3632
|
-
|
|
4848
|
+
if (isAppPermissionDeniedError(err)) return "denied";
|
|
4849
|
+
if (isMetaItemAbsentError(err)) return "not_found";
|
|
4850
|
+
return "unreachable";
|
|
3633
4851
|
}
|
|
3634
4852
|
}
|
|
3635
4853
|
/**
|
|
@@ -3679,7 +4897,8 @@ var ObjectStackAdapter = class {
|
|
|
3679
4897
|
* Uses `this.client.analytics.query()` from @objectstack/client to leverage
|
|
3680
4898
|
* the SDK's built-in auth, headers, and fetch configuration.
|
|
3681
4899
|
* Falls back to client-side aggregation via find() if the analytics endpoint
|
|
3682
|
-
* is not available.
|
|
4900
|
+
* is not available. Throws {@link AnalyticsResultShapeError} when it answers
|
|
4901
|
+
* with anything but an `AnalyticsResult` carrying `rows`.
|
|
3683
4902
|
*/
|
|
3684
4903
|
async aggregate(resource, params) {
|
|
3685
4904
|
await this.connect();
|
|
@@ -3688,7 +4907,11 @@ var ObjectStackAdapter = class {
|
|
|
3688
4907
|
const queryAst = {};
|
|
3689
4908
|
if (Array.isArray(params.groupBy)) queryAst.groupBy = params.groupBy;
|
|
3690
4909
|
if (Array.isArray(params.aggregations)) queryAst.aggregations = params.aggregations;
|
|
3691
|
-
if (params.where !== void 0)
|
|
4910
|
+
if (params.where !== void 0) {
|
|
4911
|
+
assertSpecShapeWhereIsFilterAst(params.where, resource);
|
|
4912
|
+
queryAst.where = params.where;
|
|
4913
|
+
}
|
|
4914
|
+
assertNoAnalyticsKeysOnSpecShape(params, resource);
|
|
3692
4915
|
if (typeof params.limit === "number") queryAst.limit = params.limit;
|
|
3693
4916
|
const result = await this.client.data.query(resource, queryAst);
|
|
3694
4917
|
if (Array.isArray(result)) return result;
|
|
@@ -3696,6 +4919,7 @@ var ObjectStackAdapter = class {
|
|
|
3696
4919
|
if (Array.isArray(result?.data)) return result.data;
|
|
3697
4920
|
return [];
|
|
3698
4921
|
}
|
|
4922
|
+
const analyticsWhere = params.filter ? lowerAnalyticsFilterForWire(params.filter, resource) : void 0;
|
|
3699
4923
|
try {
|
|
3700
4924
|
const measureName = params.function === "count" ? "count" : `${params.field}_${params.function}`;
|
|
3701
4925
|
const valueKey = this.aggregateValueKey(params);
|
|
@@ -3705,11 +4929,12 @@ var ObjectStackAdapter = class {
|
|
|
3705
4929
|
// When groupBy is '_all' no dimensions are needed (single-bucket).
|
|
3706
4930
|
dimensions: params.groupBy && params.groupBy !== "_all" ? [params.groupBy] : []
|
|
3707
4931
|
};
|
|
3708
|
-
if (
|
|
3709
|
-
|
|
4932
|
+
if (analyticsWhere !== void 0) payload.where = analyticsWhere;
|
|
4933
|
+
const contractResult = await this.client.analytics.query(payload);
|
|
4934
|
+
if (!Array.isArray(contractResult?.rows)) {
|
|
4935
|
+
throw new AnalyticsResultShapeError(resource, contractResult);
|
|
3710
4936
|
}
|
|
3711
|
-
const
|
|
3712
|
-
const rawRows = Array.isArray(data) ? data : data?.rows && Array.isArray(data.rows) ? data.rows : data?.data && Array.isArray(data.data) ? data.data : data?.data?.rows && Array.isArray(data.data.rows) ? data.data.rows : data?.results && Array.isArray(data.results) ? data.results : [];
|
|
4937
|
+
const rawRows = contractResult.rows;
|
|
3713
4938
|
const measureMissing = rawRows.length > 0 && rawRows.every((row) => {
|
|
3714
4939
|
if (row == null) return true;
|
|
3715
4940
|
if (measureName in row && row[measureName] != null) return false;
|
|
@@ -3728,6 +4953,7 @@ var ObjectStackAdapter = class {
|
|
|
3728
4953
|
return mapped;
|
|
3729
4954
|
});
|
|
3730
4955
|
} catch (e) {
|
|
4956
|
+
if (e instanceof AnalyticsResultShapeError) throw e;
|
|
3731
4957
|
const failure = classifyAnalyticsFailure(e);
|
|
3732
4958
|
if (failure.kind === "rejected") {
|
|
3733
4959
|
throw new AnalyticsQueryRejectedError(failure.message, failure.code);
|
|
@@ -3747,6 +4973,34 @@ var ObjectStackAdapter = class {
|
|
|
3747
4973
|
return await this.aggregateViaFind(resource, params);
|
|
3748
4974
|
}
|
|
3749
4975
|
}
|
|
4976
|
+
/**
|
|
4977
|
+
* Answer a grouped list view's GROUP HEADER query (objectui#7189) — see
|
|
4978
|
+
* `DataSource.queryGroupHeaders` in `@object-ui/types` for the contract.
|
|
4979
|
+
*
|
|
4980
|
+
* The compiled query rides the platform's EXISTING data door verbatim:
|
|
4981
|
+
* `client.data.query()` posts it to `POST /data/:object/query`, whose
|
|
4982
|
+
* `findData` routes a body carrying `groupBy` / `aggregations` to
|
|
4983
|
+
* `engine.aggregate` and answers the header rows as `records` (the door the
|
|
4984
|
+
* spec half of objectstack#14556 names, pinned platform-side by
|
|
4985
|
+
* objectstack#15330). No new route, no new wire shape.
|
|
4986
|
+
*
|
|
4987
|
+
* ⛔ No fallback, deliberately — unlike {@link aggregate}. A header query that
|
|
4988
|
+
* degraded to bucketing a fetched page would answer page slices under a name
|
|
4989
|
+
* that promises the query's own numbers, which is the defect this member
|
|
4990
|
+
* exists to end. A failure is thrown to the caller, and a body without a
|
|
4991
|
+
* `records` array is refused rather than read as "no groups".
|
|
4992
|
+
*/
|
|
4993
|
+
async queryGroupHeaders(resource, query) {
|
|
4994
|
+
await this.connect();
|
|
4995
|
+
const result = await this.client.data.query(resource, query);
|
|
4996
|
+
const records = result?.records;
|
|
4997
|
+
if (!Array.isArray(records)) {
|
|
4998
|
+
throw new Error(
|
|
4999
|
+
`queryGroupHeaders('${resource}'): POST /data/${resource}/query answered without a \`records\` array, so no group header can be read from it. The header query was sent verbatim; nothing was approximated from a page of rows.`
|
|
5000
|
+
);
|
|
5001
|
+
}
|
|
5002
|
+
return records;
|
|
5003
|
+
}
|
|
3750
5004
|
/**
|
|
3751
5005
|
* Client-side aggregation over a server-scoped `find()` — the fallback used
|
|
3752
5006
|
* whenever the analytics endpoint cannot answer (capability absent, network
|
|
@@ -3842,6 +5096,13 @@ var ObjectStackAdapter = class {
|
|
|
3842
5096
|
if (errorCodeIs({ code: serverCode }, "UNAUTHENTICATED")) {
|
|
3843
5097
|
throw new AnalyticsUnauthenticatedError({ serverCode, serverMessage });
|
|
3844
5098
|
}
|
|
5099
|
+
if (errorCodeIs({ code: serverCode }, "PERMISSION_DENIED")) {
|
|
5100
|
+
throw new AnalyticsForbiddenError({
|
|
5101
|
+
serverCode,
|
|
5102
|
+
serverMessage,
|
|
5103
|
+
datasetName: requestedDatasetName
|
|
5104
|
+
});
|
|
5105
|
+
}
|
|
3845
5106
|
if (serverCode === void 0) {
|
|
3846
5107
|
if (ANALYTICS_ABSENT_STATUSES.includes(res.status)) {
|
|
3847
5108
|
throw new AnalyticsNotInstalledError(surface, detail || void 0);
|
|
@@ -3982,9 +5243,10 @@ var ObjectStackAdapter = class {
|
|
|
3982
5243
|
}
|
|
3983
5244
|
});
|
|
3984
5245
|
if (!response.ok) {
|
|
3985
|
-
const
|
|
5246
|
+
const errorBody = await response.json().catch(() => ({ message: response.statusText }));
|
|
5247
|
+
const envelope = readErrorEnvelope(errorBody);
|
|
3986
5248
|
throw new ObjectStackError(
|
|
3987
|
-
|
|
5249
|
+
envelope.message ?? `Upload failed with status ${response.status}`,
|
|
3988
5250
|
"UPLOAD_ERROR",
|
|
3989
5251
|
response.status
|
|
3990
5252
|
);
|
|
@@ -4024,9 +5286,10 @@ var ObjectStackAdapter = class {
|
|
|
4024
5286
|
}
|
|
4025
5287
|
});
|
|
4026
5288
|
if (!response.ok) {
|
|
4027
|
-
const
|
|
5289
|
+
const errorBody = await response.json().catch(() => ({ message: response.statusText }));
|
|
5290
|
+
const envelope = readErrorEnvelope(errorBody);
|
|
4028
5291
|
throw new ObjectStackError(
|
|
4029
|
-
|
|
5292
|
+
envelope.message ?? `Upload failed with status ${response.status}`,
|
|
4030
5293
|
"UPLOAD_ERROR",
|
|
4031
5294
|
response.status
|
|
4032
5295
|
);
|
|
@@ -4108,28 +5371,46 @@ export {
|
|
|
4108
5371
|
API_ACCESS_DENIED_CODES,
|
|
4109
5372
|
APP_PERMISSION_DENIED_CODE,
|
|
4110
5373
|
AnalyticsDatasetNotFoundError,
|
|
5374
|
+
AnalyticsForbiddenError,
|
|
5375
|
+
AnalyticsKeysOnSpecShapeError,
|
|
4111
5376
|
AnalyticsNotInstalledError,
|
|
4112
5377
|
AnalyticsQueryRejectedError,
|
|
5378
|
+
AnalyticsResultShapeError,
|
|
4113
5379
|
AnalyticsUnauthenticatedError,
|
|
4114
5380
|
AuthenticationError,
|
|
4115
5381
|
BulkOperationError,
|
|
5382
|
+
CHOICE_TYPES_REQUIRING_OPTIONS,
|
|
4116
5383
|
ConcurrentUpdateError,
|
|
4117
5384
|
ConnectionError,
|
|
4118
5385
|
DataApiValidationError,
|
|
4119
5386
|
FILTER_OPERATOR_ALIASES,
|
|
5387
|
+
META_ITEM_ABSENT_CODE,
|
|
4120
5388
|
MalformedFilterError,
|
|
4121
5389
|
MetadataClient,
|
|
4122
5390
|
MetadataNotFoundError,
|
|
5391
|
+
OBJECT_METADATA_TYPE,
|
|
4123
5392
|
ObjectStackAdapter,
|
|
4124
5393
|
ObjectStackError,
|
|
5394
|
+
RELATIONSHIP_TYPES_REQUIRING_REFERENCE,
|
|
5395
|
+
UNRECOGNIZED_DROP_REASON,
|
|
5396
|
+
UnlowerableAnalyticsFilterError,
|
|
5397
|
+
UnloweredAggregateWhereError,
|
|
5398
|
+
VIEW_CONFIG_CAPABILITY,
|
|
4125
5399
|
VIEW_OVERLAY_OWNED_KEYS,
|
|
5400
|
+
ViewConfigPermissionDeniedError,
|
|
5401
|
+
assertObjectMetadataWritable,
|
|
4126
5402
|
classifyAnalyticsFailure,
|
|
5403
|
+
classifyImportMappingsFailure,
|
|
5404
|
+
classifyViewsFailure,
|
|
4127
5405
|
clearSharedDiscoveryCache,
|
|
4128
5406
|
createErrorFromResponse,
|
|
4129
5407
|
createObjectStackAdapter,
|
|
4130
5408
|
createObjectStackUserStateAdapter,
|
|
4131
5409
|
createQuietHttpLogger,
|
|
5410
|
+
extractDraftBody,
|
|
4132
5411
|
formatHttpFailureMessage,
|
|
5412
|
+
formatMetadataError,
|
|
5413
|
+
formatMetadataIssue,
|
|
4133
5414
|
getSharedDiscovery,
|
|
4134
5415
|
is404Error,
|
|
4135
5416
|
isAnalyticsNotInstalledError,
|
|
@@ -4138,7 +5419,9 @@ export {
|
|
|
4138
5419
|
isConcurrentUpdateError,
|
|
4139
5420
|
isErrorType,
|
|
4140
5421
|
isMalformedFilterError,
|
|
5422
|
+
isMetaItemAbsentError,
|
|
4141
5423
|
isObjectStackError,
|
|
5424
|
+
isViewConfigPermissionDeniedError,
|
|
4142
5425
|
narrowPersonalizationOverlay,
|
|
4143
5426
|
normaliseClientError,
|
|
4144
5427
|
readSaveAdvisories,
|