@objectstack/objectql 9.0.0 → 9.0.1

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/dist/index.mjs CHANGED
@@ -611,6 +611,172 @@ var init_seed_loader = __esm({
611
611
  }
612
612
  });
613
613
 
614
+ // src/build-probes.ts
615
+ var build_probes_exports = {};
616
+ __export(build_probes_exports, {
617
+ runBuildProbes: () => runBuildProbes
618
+ });
619
+ function asRec(v) {
620
+ return v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
621
+ }
622
+ function asArr(v) {
623
+ return Array.isArray(v) ? v : [];
624
+ }
625
+ function resultRows(result) {
626
+ if (Array.isArray(result)) return result;
627
+ const r = asRec(result);
628
+ if (!r) return [];
629
+ if (Array.isArray(r.rows)) return r.rows;
630
+ if (Array.isArray(r.data)) return r.data;
631
+ return [];
632
+ }
633
+ async function hasRows(engine, objectName, organizationId) {
634
+ const rows = await engine.find(objectName, {
635
+ fields: ["id"],
636
+ limit: 1,
637
+ ...organizationId ? { where: { organization_id: organizationId } } : {},
638
+ context: { isSystem: true }
639
+ });
640
+ return Array.isArray(rows) && rows.length > 0;
641
+ }
642
+ async function runBuildProbes(opts) {
643
+ const issues = [];
644
+ const checked = { seeds: 0, views: 0, widgets: 0 };
645
+ const { engine, getItem, published, analytics, organizationId } = opts;
646
+ const itemCache = /* @__PURE__ */ new Map();
647
+ const readItem = async (type, name) => {
648
+ const key = `${type} ${name}`;
649
+ if (itemCache.has(key)) return itemCache.get(key);
650
+ let item;
651
+ try {
652
+ item = await getItem(type, name);
653
+ } catch {
654
+ item = void 0;
655
+ }
656
+ itemCache.set(key, item);
657
+ return item;
658
+ };
659
+ for (const p of published.filter((x) => x.type === "seed")) {
660
+ const body = asRec(await readItem("seed", p.name));
661
+ const objectName = typeof body?.object === "string" ? body.object : void 0;
662
+ if (!objectName) continue;
663
+ checked.seeds += 1;
664
+ try {
665
+ if (!await hasRows(engine, objectName, organizationId)) {
666
+ issues.push({
667
+ layer: "runtime",
668
+ severity: "error",
669
+ artifact: { type: "seed", name: p.name },
670
+ ref: { type: "object", name: objectName },
671
+ code: "seed_not_applied",
672
+ message: `Seed "${p.name}" was published but object "${objectName}" has no rows \u2014 the sample data never materialized.`,
673
+ fix: `Check the publish response's seedApplied for the load error, fix the seed rows (field names/types), and republish the seed.`
674
+ });
675
+ }
676
+ } catch (e) {
677
+ issues.push({
678
+ layer: "runtime",
679
+ severity: "error",
680
+ artifact: { type: "seed", name: p.name },
681
+ ref: { type: "object", name: objectName },
682
+ code: "seed_not_applied",
683
+ message: `Seed "${p.name}" probe could not read object "${objectName}": ${String(e?.message ?? e)}`
684
+ });
685
+ }
686
+ }
687
+ for (const p of published.filter((x) => x.type === "view")) {
688
+ const body = asRec(await readItem("view", p.name));
689
+ const config = asRec(body?.config);
690
+ const dataObj = asRec(config?.data)?.object;
691
+ const objectName = typeof body?.object === "string" ? body.object : typeof dataObj === "string" ? dataObj : void 0;
692
+ if (!objectName) continue;
693
+ checked.views += 1;
694
+ try {
695
+ await engine.find(objectName, {
696
+ fields: ["id"],
697
+ limit: 1,
698
+ ...organizationId ? { where: { organization_id: organizationId } } : {},
699
+ context: { isSystem: true }
700
+ });
701
+ } catch (e) {
702
+ issues.push({
703
+ layer: "runtime",
704
+ severity: "error",
705
+ artifact: { type: "view", name: p.name },
706
+ ref: { type: "object", name: objectName },
707
+ code: "view_read_failed",
708
+ message: `View "${p.name}" cannot read object "${objectName}": ${String(e?.message ?? e)} \u2014 it will render as an error for every user.`,
709
+ fix: `Verify object "${objectName}" published successfully (its table must exist) and that the view's binding is correct.`
710
+ });
711
+ }
712
+ }
713
+ const dashboards = published.filter((x) => x.type === "dashboard");
714
+ let widgetsToProbe = 0;
715
+ for (const p of dashboards) {
716
+ const body = asRec(await readItem("dashboard", p.name));
717
+ const widgets = asArr(body?.widgets).map(asRec).filter((w) => !!w);
718
+ const datasetBound = widgets.filter((w) => typeof w.dataset === "string" && w.dataset);
719
+ widgetsToProbe += datasetBound.length;
720
+ if (!analytics || typeof analytics.queryDataset !== "function") continue;
721
+ for (const w of datasetBound) {
722
+ const widgetId = String(w.id ?? w.title ?? "?");
723
+ const dsName = w.dataset;
724
+ const dataset = asRec(await readItem("dataset", dsName));
725
+ if (!dataset) continue;
726
+ checked.widgets += 1;
727
+ const measures = asArr(w.values).filter((v) => typeof v === "string" && v.length > 0);
728
+ const firstMeasure = asRec(asArr(dataset.measures)[0])?.name;
729
+ const selection = {
730
+ measures: measures.length ? measures : typeof firstMeasure === "string" ? [firstMeasure] : [],
731
+ dimensions: [],
732
+ limit: 1
733
+ };
734
+ if (selection.measures.length === 0) continue;
735
+ const objectName = typeof dataset.object === "string" ? dataset.object : void 0;
736
+ try {
737
+ const result = await analytics.queryDataset(dataset, selection, void 0);
738
+ const rows = resultRows(result);
739
+ if (rows.length === 0 && objectName && await hasRows(engine, objectName, organizationId)) {
740
+ issues.push({
741
+ layer: "runtime",
742
+ severity: "error",
743
+ artifact: { type: "dashboard", name: p.name },
744
+ ref: { type: "dataset", name: dsName, member: widgetId },
745
+ code: "empty_query",
746
+ message: `Dashboard "${p.name}" widget "${widgetId}" returns NO data from dataset "${dsName}" although object "${objectName}" has rows \u2014 the widget will render empty for every user.`,
747
+ fix: `Run the dataset query directly to see the compiled strategy/SQL; check the dataset's measure/dimension field bindings against object "${objectName}".`
748
+ });
749
+ }
750
+ } catch (e) {
751
+ issues.push({
752
+ layer: "runtime",
753
+ severity: "error",
754
+ artifact: { type: "dashboard", name: p.name },
755
+ ref: { type: "dataset", name: dsName, member: widgetId },
756
+ code: "widget_query_failed",
757
+ message: `Dashboard "${p.name}" widget "${widgetId}" query against dataset "${dsName}" failed: ${String(e?.message ?? e)}`,
758
+ fix: `Fix the dataset definition (or the widget's values/dimensions) so the query compiles, then republish.`
759
+ });
760
+ }
761
+ }
762
+ }
763
+ if (widgetsToProbe > 0 && (!analytics || typeof analytics.queryDataset !== "function")) {
764
+ issues.push({
765
+ layer: "runtime",
766
+ severity: "warning",
767
+ artifact: { type: "dashboard", name: dashboards.map((d) => d.name).join(", ") },
768
+ code: "probes_unavailable",
769
+ message: `${widgetsToProbe} dashboard widget(s) could not be probed: no analytics service is mounted on this kernel.`
770
+ });
771
+ }
772
+ return { issues, checked };
773
+ }
774
+ var init_build_probes = __esm({
775
+ "src/build-probes.ts"() {
776
+ "use strict";
777
+ }
778
+ });
779
+
614
780
  // src/registry.ts
615
781
  import { ObjectSchema } from "@objectstack/spec/data";
616
782
  import { readEnvWithDeprecation } from "@objectstack/types";
@@ -4967,13 +5133,38 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
4967
5133
  });
4968
5134
  }
4969
5135
  }
5136
+ const seedApplied = seedBodies.length > 0 ? await this.applySeedBodies(seedBodies, orgId) : void 0;
5137
+ let probes;
5138
+ if (published.length > 0) {
5139
+ try {
5140
+ const { runBuildProbes: runBuildProbes2 } = await Promise.resolve().then(() => (init_build_probes(), build_probes_exports));
5141
+ const analytics = this.getServicesRegistry?.().get("analytics");
5142
+ probes = await runBuildProbes2({
5143
+ engine: this.engine,
5144
+ getItem: async (type, name) => {
5145
+ const wrapper = await this.getMetaItem({
5146
+ type,
5147
+ name,
5148
+ ...orgId ? { organizationId: orgId } : {}
5149
+ });
5150
+ return wrapper?.item ?? wrapper ?? void 0;
5151
+ },
5152
+ published,
5153
+ ...analytics && typeof analytics.queryDataset === "function" ? { analytics } : {},
5154
+ organizationId: orgId
5155
+ });
5156
+ } catch {
5157
+ probes = void 0;
5158
+ }
5159
+ }
4970
5160
  return {
4971
5161
  success: failed.length === 0 && published.length > 0,
4972
5162
  publishedCount: published.length,
4973
5163
  failedCount: failed.length,
4974
5164
  published,
4975
5165
  failed,
4976
- ...seedBodies.length > 0 ? { seedApplied: await this.applySeedBodies(seedBodies, orgId) } : {}
5166
+ ...seedApplied ? { seedApplied } : {},
5167
+ ...probes ? { probes } : {}
4977
5168
  };
4978
5169
  }
4979
5170
  /**
@@ -9840,6 +10031,7 @@ function convertIntrospectedSchemaToObjects(introspectedSchema, options) {
9840
10031
 
9841
10032
  // src/index.ts
9842
10033
  init_seed_loader();
10034
+ init_build_probes();
9843
10035
  export {
9844
10036
  DEFAULT_EXTENDER_PRIORITY,
9845
10037
  DEFAULT_OWNER_PRIORITY,
@@ -9873,6 +10065,7 @@ export {
9873
10065
  noopHookMetricsRecorder,
9874
10066
  parseFQN,
9875
10067
  parseSecretRef,
10068
+ runBuildProbes,
9876
10069
  toTitleCase,
9877
10070
  validateRecord,
9878
10071
  wrapDeclarativeHook