Skip to content

Commit b66d9c6

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-1wujme
2 parents fd12db8 + 8589756 commit b66d9c6

16 files changed

Lines changed: 819 additions & 36 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@objectstack/runtime': minor
3+
'@objectstack/cloud-connection': minor
4+
'@objectstack/organizations': patch
5+
---
6+
7+
feat(runtime,cloud-connection): the marketplace install, the sample-data reseed, the restart heal and the per-organization seed replay pick `Seed.locale` datasets by the organization's language
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: semantic
11+
12+
An app that ships one demo dataset per language market (`locale: ['zh-CN']` beside `locale: ['en-US']`) now gets the right one on every path that seeds an organization, not only on the boot path. Before, the install paths passed no locale, so a Chinese organization received the English rows and a page of refused-insert warnings for the Chinese twins (or both sets, where no unique key stopped the second), and one server's per-organization replay gave every new organization the boot app's `i18n.defaultLocale`.
13+
14+
The locale is resolved for the organization the rows land in. The first answer wins:
15+
16+
1. the organization's `localization.locale` setting, through the settings service's own cascade (an env override, the organization's row, the deployment-wide `global` row). Only a value somebody set counts: the manifest's built-in `en-US` default (`source: 'default'`) is not the organization's choice;
17+
2. `sys_user.locale` of the person installing, reseeding or founding the organization;
18+
3. the app's declared `i18n.defaultLocale`.
19+
20+
Nothing answers ⇒ no locale is sent, and every dataset loads as before (the loader still warns, naming each locale-scoped dataset it let through). A dataset without `locale` loads whatever the answer is. When no dataset in a load declares `locale`, neither the setting nor the user is read.
21+
22+
- **The per-organization replay** resolves the locale per organization, at replay time, instead of once at boot. At founding the organization has no setting of its own yet, so its founder's language decides; an organization inserted with no person behind it takes the app's default. The replayer (`seed-replayer` service) now takes an optional second argument, `(organizationId, { userId })`; a caller passing only the organization id works as before.
23+
- **`@objectstack/organizations`**: the org-scoping middleware hands the replayer the insert's attributed user (better-auth's create runs as system with the signed-in creator attributed) as the founder.
24+
- **`@objectstack/cloud-connection`**: the install and the reseed pass the installing user and the package's own `i18n.defaultLocale`; the restart heal passes the package's default only (no person starts it); the replayer this plugin registers when the host has none passes the founder and no app default, because it replays every installed package at once.
25+
- **`@objectstack/runtime`** exports the shared producer: `resolveSeedLocaleForLoad(host, { seeds, organizationId, userId, appDefaultLocale })`, `appDefaultSeedLocale(body)`, `seedsDeclareLocale(seeds)`, `describeSeedLocale(resolved)` and the `ResolvedSeedLocale` / `SeedLocaleQuestion` / `SeedLocaleSource` types.
26+
- A settings or user read that throws is not skipped over: the seed reports the failure (the install's seed summary, the reseed's `RESEED_SKIPPED`, the replay's warning) and writes nothing, rather than seeding another language over a choice that could not be read. A host with no `settings` service skips step 1.
27+
28+
Unchanged: the boot seed and the dev hot-reload seeder still filter on the app's `i18n.defaultLocale`; package apply and draft publish still pass no locale.

‎content/docs/data-modeling/seed-data.mdx‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,26 @@ operator's job — to switch locales cleanly, start from a fresh database.
306306
the seed loader, so declaring a locale on a dataset takes effect with no extra
307307
wiring. Declare no `i18n` block and no locale is sent at all — which is the
308308
unrestricted setting, not a filter.
309+
310+
**Installs and new organizations load for the organization's language.** A
311+
marketplace install, a sample-data reseed, the restart heal of an installed
312+
package, and the replay that seeds each new organization pick the locale for
313+
the organization the rows land in. The first of these that answers wins:
314+
315+
1. the organization's **Setup → Localization → Default language**, when
316+
somebody set it, for that organization or for the whole deployment (the
317+
built-in `en-US` default does not count as set);
318+
2. the language of the person installing, reseeding or creating the
319+
organization;
320+
3. the app's `i18n.defaultLocale`.
321+
322+
So one package can ship a Chinese and an English demo catalogue side by side,
323+
and a Chinese organization gets the Chinese one. A new organization has no
324+
Localization setting of its own yet, so its creator's language decides, and
325+
one created with no person behind it takes the app's default. On a runtime
326+
whose seed data comes only from marketplace packages, a new organization's
327+
replay skips the third step: it replays every installed package at once, and
328+
no one package's default speaks for all of them.
309329
</Callout>
310330

311331
<Callout type="warn">
@@ -316,15 +336,15 @@ operator's job — to switch locales cleanly, start from a fresh database.
316336
scope that is not taking effect is one log line to diagnose rather than a
317337
silent no-op.
318338

319-
**Publishing and installing are locale-neutral acts, by decision.** Applying
320-
a package, publishing a draft and installing from the marketplace each build
321-
their own seed-load request and pass no locale, so a `locale`-scoped dataset
322-
reaching one of those paths loads for every market and is named in that
323-
warning. This is the declared bound of the axis rather than an unfinished
324-
path — a package is assembled once for every market, and selecting a market
325-
is what happens when it is opened, on the boot path above. Ruled
326-
2026-09-10 on
327-
[#17011](https://github.com/objectstack-ai/objectstack/issues/17011#issuecomment-5615361502).
339+
**Applying a package and publishing a draft are locale-neutral.** Those two
340+
build their own seed-load request and pass no locale, so a `locale`-scoped
341+
dataset reaching one of them loads for every market and is named in that
342+
warning. Installing from the marketplace was locale-neutral too until the
343+
install paths started picking by the organization's language, above (ruled
344+
2026-11-05 on
345+
[#30281](https://github.com/objectstack-ai/objectstack/issues/30281), which
346+
reverses the install half of
347+
[#17011](https://github.com/objectstack-ai/objectstack/issues/17011#issuecomment-5615361502)).
328348
</Callout>
329349

330350
---

‎packages/cloud-connection/src/cloud-connection-auth-gate.pin.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ vi.mock('@objectstack/runtime', () => ({
6363
}
6464
},
6565
recordSeedOutcome: vi.fn(),
66+
// [#30281] The seed-locale producer, answering "no locale": this suite's
67+
// subject is not the locale (pinned in marketplace-install-local-seed-replayer.test.ts).
68+
resolveSeedLocaleForLoad: async () => undefined,
69+
appDefaultSeedLocale: () => undefined,
70+
describeSeedLocale: () => 'none',
6671
}));
6772

6873
import { assertEngineDeleteDispatch } from '@objectstack/metadata-core';

‎packages/cloud-connection/src/marketplace-install-local-capability-enumeration.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ vi.mock('@objectstack/runtime', () => ({
8383
}
8484
},
8585
recordSeedOutcome: vi.fn(),
86+
// [#30281] The seed-locale producer, answering "no locale": this suite's
87+
// subject is not the locale (pinned in marketplace-install-local-seed-replayer.test.ts).
88+
resolveSeedLocaleForLoad: async () => undefined,
89+
appDefaultSeedLocale: () => undefined,
90+
describeSeedLocale: () => 'none',
8691
}));
8792

8893
import { assertEngineDeleteDispatch } from '@objectstack/metadata-core';

‎packages/cloud-connection/src/marketplace-install-local-heal.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ vi.mock('@objectstack/runtime', () => ({
4242
},
4343
// #3430 — the heal path records a per-source outcome for the boot banner.
4444
recordSeedOutcome: vi.fn(),
45+
// [#30281] The seed-locale producer, answering "no locale": this suite's
46+
// subject is not the locale (pinned in marketplace-install-local-seed-replayer.test.ts).
47+
resolveSeedLocaleForLoad: async () => undefined,
48+
appDefaultSeedLocale: () => undefined,
49+
describeSeedLocale: () => 'none',
4550
}));
4651
// Only the seed-request parse is stubbed; every other export stays the real one,
4752
// because `@objectstack/core` reads `@objectstack/spec/data` values at module load

‎packages/cloud-connection/src/marketplace-install-local-no-active-organization.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ vi.mock('@objectstack/runtime', () => ({
5252
}
5353
},
5454
recordSeedOutcome: vi.fn(),
55+
// [#30281] The seed-locale producer, answering "no locale": this suite's
56+
// subject is not the locale (pinned in marketplace-install-local-seed-replayer.test.ts).
57+
resolveSeedLocaleForLoad: async () => undefined,
58+
appDefaultSeedLocale: () => undefined,
59+
describeSeedLocale: () => 'none',
5560
}));
5661
// Only the seed-request parse is stubbed; every other export stays the real one,
5762
// because `@objectstack/core` reads `@objectstack/spec/data` values at module load.

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
13881388
}
13891389

13901390
try {
1391-
const summary = await this.runInlineSeed(ctx, datasets);
1391+
// [#30281] No user starts a boot heal: the setting, then this
1392+
// package's declared default locale.
1393+
const summary = await this.runInlineSeed(ctx, datasets, undefined, { app: converted });
13921394
const landed = (summary.inserted ?? 0) + (summary.updated ?? 0);
13931395
if (landed > 0) {
13941396
entry.withSampleData = true;
@@ -1626,7 +1628,9 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
16261628
*/
16271629
private buildSeedReplayer = (ctx: PluginContext) => {
16281630
const empty = () => ({ inserted: 0, updated: 0, skipped: 0, errors: [] as any[] });
1629-
return async (organizationId: string) => {
1631+
// [#30281] `options.userId` is the organization's founder when the
1632+
// org-scoping middleware knows one — the AppPlugin replayer's shape.
1633+
return async (organizationId: string, options?: { userId?: string }) => {
16301634
if (!organizationId) return empty();
16311635
const datasetsNow = this.readSharedSeedDatasets(ctx);
16321636
if (!Array.isArray(datasetsNow) || datasetsNow.length === 0) return empty();
@@ -1645,7 +1649,11 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
16451649
ctx.logger?.warn?.(`[MarketplaceInstallLocal] seed-replayer: objectql/metadata unavailable — org ${organizationId} not seeded`);
16461650
return empty();
16471651
}
1648-
const s = await this.runInlineSeed(ctx, datasetsNow, organizationId);
1652+
// [#30281] The locale is resolved per organization: its setting,
1653+
// then the founder's language. No app default rung — the shared
1654+
// list is every installed package's datasets, and no one package's
1655+
// declared default speaks for the union.
1656+
const s = await this.runInlineSeed(ctx, datasetsNow, organizationId, { userId: options?.userId });
16491657
return { inserted: s.inserted, updated: s.updated, skipped: s.skipped, errors: s.errorList };
16501658
};
16511659
};
@@ -2446,7 +2454,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
24462454
// • load translation bundles into the i18n service
24472455
// • stash seed datasets on the kernel + run them now so the
24482456
// installed app has demo data on first paint.
2449-
const seededSummary = await this.applySideEffects(ctx, converted, { seedNow: true, c });
2457+
const seededSummary = await this.applySideEffects(ctx, converted, { seedNow: true, c, userId });
24502458
// `skipped` counts too: an all-skip run means the rows are ALREADY in
24512459
// the database (e.g. a reinstall/upgrade over live sample data) — the
24522460
// install carries sample data either way. Leaving the flag false here
@@ -4249,7 +4257,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
42494257
// The ledger keeps the body as installed: `entry` is written back below
42504258
// with its `manifest` untouched.
42514259
const converted = this.convertPackageBodyForward(ctx, entry.manifest);
4252-
const summary = await this.applySideEffects(ctx, converted, { seedNow: true, c, door: 'reseed' });
4260+
const summary = await this.applySideEffects(ctx, converted, { seedNow: true, c, door: 'reseed', userId: admission.userId });
42534261
// [ADR-0123 D2 / D4] A walled session with no active organization: the
42544262
// reseed is a tenant-scoped write with no organization to write under.
42554263
if (summary.seeded.mode === 'refused') {
@@ -4890,7 +4898,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
48904898
private applySideEffects = async (
48914899
ctx: PluginContext,
48924900
manifest: any,
4893-
opts: { seedNow: boolean; c?: any; door?: Exclude<SampleDataDoor, 'purge'> },
4901+
opts: { seedNow: boolean; c?: any; door?: Exclude<SampleDataDoor, 'purge'>; userId?: string },
48944902
): Promise<{ translationsLoaded: number; seeded: { mode: 'inline' | 'replayer' | 'skipped' | 'refused'; inserted?: number; updated?: number; skipped?: number; errors?: number; reason?: string; errorSample?: string } }> => {
48954903
const appId = String(manifest?.id ?? 'unknown');
48964904
let translationsLoaded = 0;
@@ -5008,7 +5016,12 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
50085016
}
50095017
}
50105018
if (!multiTenant || organizationId) {
5011-
const s = await this.runInlineSeed(ctx, datasets, organizationId);
5019+
// [#30281] The installing (or reseeding) user and this
5020+
// package's own declared default locale.
5021+
const s = await this.runInlineSeed(ctx, datasets, organizationId, {
5022+
userId: opts.userId,
5023+
app: manifest,
5024+
});
50125025
seedSummary = { mode: 'inline', ...s };
50135026
ctx.logger?.info?.(`[MarketplaceInstallLocal] inline seed for ${appId}${organizationId ? ` (org=${organizationId})` : ''}: inserted=${s.inserted} updated=${s.updated} skipped=${s.skipped} errors=${s.errors}`);
50145027
}
@@ -5025,24 +5038,41 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
50255038
/**
50265039
* One SeedLoaderService run over `datasets` (multi-pass, each dataset in
50275040
* its own `mode`, the spec default `ignore` when it declares none) — the
5028-
* shared engine behind install-time seeding, the reseed endpoint and the
5029-
* rehydrate-time healer. Throws when objectql/metadata are unavailable;
5030-
* per-row write failures are counted into `errors`, not thrown.
5041+
* shared engine behind install-time seeding, the reseed endpoint, the
5042+
* rehydrate-time healer and this file's per-org replayer. Throws when
5043+
* objectql/metadata are unavailable, or when the seed locale cannot be
5044+
* read; per-row write failures are counted into `errors`, not thrown.
5045+
*
5046+
* [#30281] `localeFrom` names who the load is for, and the runtime's
5047+
* `resolveSeedLocaleForLoad` turns it into the `Seed.locale` filter: the
5048+
* organization's Localization setting, then `userId`'s language, then
5049+
* `app`'s declared `i18n.defaultLocale` (`app` is the package body; ruling
5050+
* A, maintainer, 2026-11-05: the install paths
5051+
* pick datasets by locale). Nothing answers ⇒ no locale, and every dataset
5052+
* loads as before. A dataset without `locale` loads whatever it answers.
50315053
*/
50325054
private runInlineSeed = async (
50335055
ctx: PluginContext,
50345056
datasets: any[],
50355057
organizationId?: string,
5058+
localeFrom: { userId?: string; app?: unknown } = {},
50365059
): Promise<{ inserted: number; updated: number; skipped: number; errors: number; errorList: any[]; droppedRefs: number; errorSample?: string }> => {
50375060
const ql: any = ctx.getService('objectql');
50385061
let metadata: any;
50395062
try { metadata = ctx.getService('metadata'); } catch { /* none */ }
50405063
if (!ql || !metadata) throw new Error('objectql-or-metadata-missing');
50415064

5042-
const [{ SeedLoaderService }, { SeedLoaderRequestSchema }] = await Promise.all([
5065+
const [{ SeedLoaderService, appDefaultSeedLocale, describeSeedLocale, resolveSeedLocaleForLoad }, { SeedLoaderRequestSchema }] = await Promise.all([
50435066
import('@objectstack/runtime'),
50445067
import('@objectstack/spec/data'),
50455068
]);
5069+
const seedLocale = await resolveSeedLocaleForLoad(ctx, {
5070+
seeds: datasets,
5071+
organizationId,
5072+
userId: localeFrom.userId,
5073+
appDefaultLocale: appDefaultSeedLocale(localeFrom.app),
5074+
});
5075+
ctx.logger?.info?.(`[MarketplaceInstallLocal] seed locale${organizationId ? ` for org ${organizationId}` : ''}: ${describeSeedLocale(seedLocale)}`);
50465076
const seedLoader = new (SeedLoaderService as any)(ql, metadata, ctx.logger);
50475077
const request = (SeedLoaderRequestSchema as any).parse({
50485078
// ADR-0036 / seed rename: the field is `seeds` (was `datasets`).
@@ -5054,6 +5084,9 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
50545084
// `mode: 'upsert'` (the spec default, ruling 6631016988).
50555085
multiPass: true,
50565086
...(organizationId ? { organizationId } : {}),
5087+
// Spread, never `locale: undefined`: absence is what the
5088+
// loader's unresolved-scope warning is keyed on.
5089+
...(seedLocale ? { locale: seedLocale.locale } : {}),
50575090
},
50585091
});
50595092
const result = await seedLoader.load(request);

‎packages/cloud-connection/src/marketplace-install-local-reseed.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ vi.mock('@objectstack/runtime', () => ({
3535
SeedLoaderService: class {
3636
async load(request: any) { loadCalls.push(request); return seedResult; }
3737
},
38+
// [#30281] The seed-locale producer, answering "no locale": this suite's
39+
// subject is not the locale (pinned in marketplace-install-local-seed-replayer.test.ts).
40+
resolveSeedLocaleForLoad: async () => undefined,
41+
appDefaultSeedLocale: () => undefined,
42+
describeSeedLocale: () => 'none',
3843
}));
3944
// Only the seed-request parse is stubbed; every other export stays the real one,
4045
// because `@objectstack/core` reads `@objectstack/spec/data` values at module load

0 commit comments

Comments
 (0)