Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/25921-data-objectstack-shared-discovery-cache-helper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/data-objectstack': patch
---

refactor(data-objectstack)!: retire the test-only `clearSharedDiscoveryCache` from the package entry

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (runtime-export-retired @object-ui/data-objectstack#clearSharedDiscoveryCache) the retired operand is a test-only function that empties the adapter's in-memory per-origin discovery cache; nothing in the workspace or in hotcrm calls it outside tests, and no packages/spec schema, registered node type, conversion surface or stored shape names it, so there is nothing for `objectstack migrate meta` to rewrite -->

**BREAKING** for a host that imports `clearSharedDiscoveryCache` from `@object-ui/data-objectstack`. It reset module state between tests, and no code outside a test called it, in the workspace or in hotcrm, so the Console and every `@object-ui/*` package are unaffected. Nothing fetches or renders differently.

The per-origin discovery cache moves verbatim into the package's own module `sharedDiscovery.ts`. `ObjectStackAdapter.connect()` still reads through it, and `getSharedDiscovery` stays exported from the entry unchanged. Only the reset helper stops being published, the same way the package roots already keep `resetRuntimeConfigForTesting`, `resetInflightGetsForTesting` and `__clearRecordEditableCache` off their barrels. The workspace's own tests import it from the module.

What leaves, and what to write instead:

- FROM `clearSharedDiscoveryCache` TO no replacement. The helper was test-only; a host test that needs a fresh discovery read gives each case its own `baseUrl`, or stubs the fetch its adapter makes.
2 changes: 1 addition & 1 deletion ui/apps/console/src/LocalizationFetchProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { notifyDataChanged } from '@object-ui/react';
// Test-only and off the `@object-ui/types` barrel; the vitest alias makes this
// the same module instance the provider's `sharedGetJson` uses.
import { resetInflightGetsForTesting } from '../../../packages/types/src/http-inflight';
import { clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../packages/data-objectstack/src/sharedDiscovery';
import { LocalizationFetchProvider } from './LocalizationFetchProvider';
import { __resetAppDefaultLocaleForTests, loadAppDefaultLocale } from './languageSeed';
// Not on the `@object-ui/auth` barrel; the vitest alias maps that barrel to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { useLocalization, readCachedLanguageSeed } from '@object-ui/i18n';
import { clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../packages/data-objectstack/src/sharedDiscovery';
import { resetInflightGetsForTesting } from '../../../../packages/types/src/http-inflight';
import { __resetAppDefaultLocaleForTests, seedTenantLanguage } from '../languageSeed';
import { LocalizationFetchProvider } from '../LocalizationFetchProvider';
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/console/src/languageSeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
preloadBootstrapLocale,
useObjectTranslation,
} from '@object-ui/i18n';
import { clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../packages/data-objectstack/src/sharedDiscovery';
import { __resetAppDefaultLocaleForTests, seedTenantLanguage } from './languageSeed';

const BASE = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../../packages/data-objectstack/src/sharedDiscovery';
import { probeRecordReadability, readabilityKey } from './recordReadability';

/** The server's refusal body, as measured on the probe's list read. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { render, screen, act } from '@testing-library/react';
import { useEffect, useState } from 'react';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
type ConnectionState,
} from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../data-objectstack/src/sharedDiscovery';
import { ConnectionStatus } from '../ConnectionStatus';

vi.mock('@object-ui/i18n', async (importOriginal) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
IDENTITY_IMPORT_BATCH_SIZE,
IDENTITY_IMPORT_OBJECT,
} from '../identityImport';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../data-objectstack/src/sharedDiscovery';
import type { ImportRecordsResult } from '@object-ui/types';

const okResponse = (rows: Array<Record<string, unknown>>, overrides: Record<string, unknown> = {}) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import '@testing-library/jest-dom';
import React from 'react';

import { ImportWizard } from '@object-ui/plugin-grid';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../data-objectstack/src/sharedDiscovery';
import { createIdentityImportDataSource, IDENTITY_IMPORT_OBJECT } from '../identityImport';

const BASE_URL = 'http://identity-import-selector-pin.local';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import { cleanup, render, screen, waitFor } from '@testing-library/react';
// (ui/AGENTS.md, flaky-test discipline). Specifiers identical to the previews'.
import '@object-ui/plugin-report';
import '@object-ui/plugin-dashboard';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from '@object-ui/data-objectstack';
// The object picker under the dataset form loads the linter and the formula
// engine lazily: pay both loads while the file is collected, never inside a
// case's timeout (`check:test-source-alias`).
import '@objectstack/lint';
import '@objectstack/formula';
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
import { clearSharedDiscoveryCache } from '../../../../../data-objectstack/src/sharedDiscovery';
import { StudioDatasetAuthoringContext } from '../../studio-design/datasetCreate';

const current = vi.hoisted(() => ({ adapter: null as unknown }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const RECORDS = [
{ id: '1', stage: 'won', amount: 100 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ import { isFilterAST, parseFilterAST } from '@objectstack/spec/data';
import { AnalyticsQueryRequestSchema } from '@objectstack/spec/api';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
isMalformedFilterError,
UnlowerableAnalyticsFilterError,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/** Rows that carry the requested measure, so nothing degrades to the fallback. */
const ANALYTICS_ROWS = { rows: [{ amount_sum: 150 }] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const RECORDS = [
{ id: '1', stage: 'won', amount: 100 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
import {
AnalyticsResultShapeError,
ObjectStackAdapter,
clearSharedDiscoveryCache,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const RECORDS = [
{ id: '1', stage: 'won', amount: 100 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
import { parseFilterAST } from '@objectstack/spec/data';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
isMalformedFilterError,
AnalyticsKeysOnSpecShapeError,
UnloweredAggregateWhereError,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/** Rows the spec-shape door answers with, so nothing degrades to a fallback. */
const QUERY_ROWS = { success: true, data: { object: 'opportunity', records: [{ stage: 'won', n: 2 }], total: 1 } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
import { isFilterAST, parseFilterAST } from '@objectstack/spec/data';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
isMalformedFilterError,
UnloweredAggregateWhereError,
AnalyticsKeysOnSpecShapeError,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/** Rows the spec-shape door answers with, so nothing degrades to a fallback. */
const QUERY_ROWS = { success: true, data: { object: 'opportunity', records: [{ stage: 'won', n: 2 }], total: 1 } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const json = (body: unknown) =>
new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
ObjectStackAdapter,
ConnectionError,
clearSharedDiscoveryCache,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const DISCOVERY = { name: 'fake', routes: {} };

Expand Down
2 changes: 1 addition & 1 deletion ui/packages/data-objectstack/src/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

describe('Connection State Monitoring', () => {
let adapter: ObjectStackAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
ObjectStackAdapter,
ConnectionError,
clearSharedDiscoveryCache,
type ConnectionStateEvent,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

type Mode = 'answer' | 'refuse' | 'abort' | { status: number };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ValueDataSource } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/**
* Four rows that tell the two candidate answers apart: `2` is the only row with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { FilterOperatorError } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

function makeAdapter() {
const calls: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import {
ObjectStackAdapter,
FILTER_OPERATOR_ALIASES,
MalformedFilterError,
clearSharedDiscoveryCache,
isMalformedFilterError,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

type Route = 'plain' | 'expand';
const ROUTES: readonly Route[] = ['plain', 'expand'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { isFilterAST, parseFilterAST } from '@objectstack/spec/data';
import { ObjectStackAdapter, clearSharedDiscoveryCache, isMalformedFilterError } from './index';
import { ObjectStackAdapter, isMalformedFilterError } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

function makeAdapter() {
const calls: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ValueDataSource } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const ROWS = [
{ id: '1', a: 'x', s: 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { isFilterAST, parseFilterAST } from '@objectstack/spec/data';
import { ObjectStackAdapter, clearSharedDiscoveryCache, isMalformedFilterError } from './index';
import { ObjectStackAdapter, isMalformedFilterError } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

function makeAdapter() {
const calls: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { readCascadeDeleteObjects } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const LEAD = { name: 'crm_lead', fields: { name: { type: 'text' } } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { isActionSwitchedOff } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

const TASK = {
name: 'showcase_task',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { resolveObjectSortability } from '@objectstack/spec/api';
import { readObjectSortability, isPlatformSortableField } from '@object-ui/core';
import { ObjectStackAdapter, clearSharedDiscoveryCache } from './index';
import { ObjectStackAdapter } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/** The #10235 oracle object: a formula column beside persisted siblings. */
const OPPORTUNITY = {
Expand Down
3 changes: 2 additions & 1 deletion ui/packages/data-objectstack/src/getObjectSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { ObjectStackAdapter, clearSharedDiscoveryCache, ConnectionError, MetadataNotFoundError, ObjectStackError } from './index';
import { ObjectStackAdapter, ConnectionError, MetadataNotFoundError, ObjectStackError } from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/**
* A fetch mock that answers discovery + records the `GET /meta/object/:name`
Expand Down
33 changes: 6 additions & 27 deletions ui/packages/data-objectstack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import { MetadataCache } from './cache/MetadataCache';
import { AppBundleStore, indexAppBundle, type AppBundleAnswer, type AppBundlePeek } from './app-bundle';
import { MetadataClient } from './metadata-client';
import { formatMetadataError } from './metadata-error';
import { getSharedDiscovery } from './sharedDiscovery';
import {
ObjectStackError,
MetadataNotFoundError,
Expand Down Expand Up @@ -994,8 +995,6 @@ function cacheKeyNamesBundledItem(key: string, bundles: AppBundleStore): boolean
return bundles.holds(head, rest.join(':'));
}

const discoveryCache = new Map<string, Promise<unknown>>();

/**
* The server ORIGIN a `baseUrl` names: no trailing slash, and no trailing
* `/api/vN`. The adapter, the `ObjectStackClient` it wraps and
Expand All @@ -1009,31 +1008,11 @@ function serverOriginOf(baseUrl: string): string {
return (baseUrl || '').replace(/\/$/, '').replace(/\/api\/v\d+$/i, '');
}

/**
* Fetch the server `discovery` document once per (baseUrl) and reuse the
* resulting Promise. Used by `ObjectStackAdapter.connect()` (and any caller
* that wants the discovery payload without spinning up a new client).
*/
export async function getSharedDiscovery(
baseUrl: string,
fetcher: () => Promise<unknown>,
): Promise<unknown> {
const key = baseUrl || '<default>';
const cached = discoveryCache.get(key);
if (cached) return cached;
const p = fetcher().catch((err) => {
// Allow retry on failure
discoveryCache.delete(key);
throw err;
});
discoveryCache.set(key, p);
return p;
}

/** Test/dev helper to drop the cache (e.g. on logout or origin change). */
export function clearSharedDiscoveryCache(): void {
discoveryCache.clear();
}
export {
getSharedDiscovery,
// `clearSharedDiscoveryCache` is test-only and stays off the barrel
// (#25921); tests import it from `sharedDiscovery` directly.
} from './sharedDiscovery';

/**
* Read the cross-object atomic-batch capability from a `discovery` document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
classifyImportMappingsFailure,
type MetadataReadWarningEvent,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/**
* `listImportMappings(objectName)` feeds the import wizard's "saved mapping"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
ObjectStackAdapter,
clearSharedDiscoveryCache,
classifyImportMappingsFailure,
classifyViewsFailure,
type MetadataReadWarningEvent,
} from './index';
import { clearSharedDiscoveryCache } from './sharedDiscovery';

/**
* `listViews(object)` feeds the list-view switcher, and it degrades EVERY
Expand Down
Loading
Loading