You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 135c2fb
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-datasource)!: an object imported from a package's external datasource is saved into that package or its customization package (#30602)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg7tzcrehvbdg7wEixkg22DP)_
domain:server#6 · os-bill · session_01Utp6CXCS98uhsFQYk64epE
Fixes#30469
Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: none — `git grep -n -i -E "datasource (table
)?(sync|import)|external object|import_object|customization
pair|customization package|\.custom" -- skills` on `8c52a7af` answers
lines about overrides, object extensions and the permission-set clone
landing in a base's `.custom` package
(`skills/objectstack-platform/SKILL.md:128`,
`skills/objectstack-data/SKILL.md:366`,
`skills/objectstack-automation/SKILL.md:51` and their evals) and the
datasources catalog entry (`skills/objectstack-data/SKILL.md:47`);
`skills/objectstack-data/rules/datasources.md` names no import. No
published sentence says where an imported object is saved or what it is
named.
## 维护者速读
- 改了什么:从外部数据源导入的表,现在按数据源归谁来存:Setup
里加的数据源照旧不进包;包声明的数据源,可写包就存进该包,只读的已装包就存进它的定制包
`包名.custom`,并跟着该包导出。只读包下导入的对象名改为定制包前缀,例如 showcase 的 `customers` 从
`showcase_customers` 变成 `showcase_custom_customers`。
- 为什么改:你 14:46Z 裁定 B(裁定记录
6660988968)。之前导入的对象名字说属于某个包,存储却不属于任何包,包导出带不走,换环境就丢。
- 风险与回滚:BREAKING
收窄:只读包数据源上用旧前缀的显式名字现在被拒(提示里给出新名字);墙内形态(group/isolated)下定制包还不存在时导入被拒,提示请平台运营方先建;已导入的旧对象不迁移、不改名,重新导入会得到新名字的对象,旧的由管理员删。回滚即
revert 本 PR。
-
先看:`packages/services/service-datasource/src/plugin.ts`(`resolveImportLanding`:三行归属与墙内分支)、`external-datasource-service.ts`(`importObject`
先定落点、最后才建定制包再保存),再看
`src/__tests__/external-namespace-reads-engine-registry.test.ts` 末尾新增的
describe。
- 两分钟验证:`pnpm --filter @objectstack/service-datasource exec vitest run
src/__tests__/external-namespace-reads-engine-registry.test.ts -t "lands
in the package of its datasource"`,预期 14 条通过。
- 需要你做的:无,席位落地。ADR-0146 D3「It receives」加一项、D11 加半句仍是你的 Tier H 待办(本 PR 不改
ADR)。
## What changes
Ruling B on where an imported object lives (ruling record 6660988968,
maintainer 「同意」), built as the seat fixed it for walled postures.
- **Placement follows the datasource's `_packageId`** (`plugin.ts`, new
`resolveImportLanding`):
- no package, the `sys_metadata` sentinel, or a datasource that cannot
be read → a package-less row, as before (ADR-0146 D11). The save request
is byte-for-byte the old one (no `packageId` key);
- a writable package (the save door's own ADR-0070 predicate,
`isWritablePackage` on the `'protocol'` service) → saved into that
package, named in its namespace;
- a read-only installed base → saved into its customization package
`BASE.custom`, named in the pair's namespace. The pair comes from the
ensure door (`ensureCustomizationPackage` on the same `'protocol'`
service), the only creation path (ADR-0146 D3).
- **Ordering in `importObject`.** The landing is resolved first (a
landing that cannot be had refuses before any remote introspection); an
explicit `name` is judged against the landing's namespace; then the
draft; then `prepare` (the ensure door) runs immediately before the
save. A refused name, a missing remote table or a refused draft
therefore makes no pair and saves nothing.
- **Walled postures (`group`, `isolated`).** There the platform operator
alone creates a customization package, through the ensure door's HTTP
route (ADR-0146 D3, ADR-0131 D3). So the import never creates a pair
under a wall: a pair that already exists receives the import; while none
does, the import is refused (`400 EXTERNAL_IMPORT_ERROR`, the code the
import door answers every refusal with) with a message naming the
platform operator and `POST /api/v1/packages/BASE/ensure-customization`.
It is never saved package-less instead (ADR-0070 D3). The posture is the
`tenancy` service's effective one, through the shared
`classifyAdmissionTenancyPosture`.
- **A protocol that cannot answer** (no `isWritablePackage` /
`ensureCustomizationPackage`) refuses an import over a packaged
datasource rather than guessing.
- **The draft door is unchanged**: `…/tables/:remote/draft` still names
the object in the datasource package's own namespace, because its
`*.object.ts` is committed into that package's source.
- `ExternalDatasourceServiceConfig` gains the optional
`resolveImportLanding`; `persistObject` takes an optional `packageId`;
`ImportLanding` is exported. A host that wires no landing keeps the old
placement.
- Existing package-less imported objects are not migrated or renamed.
Re-importing the same table makes a new object under the new name beside
the old one; the administrator deletes the old one (pinned on the
showcase below).
### The name, measured before it was fixed
On a booted showcase at `1fd0c32c` (scratch file, not committed):
`ensureCustomizationPackage({ basePackageId: 'com.example.showcase' })`
answered `com.example.showcase.custom`, namespace `showcase_custom`. A
save of `showcase_customers` into the pair was refused `422
NAMESPACE_PREFIX` ("Rename it to 'showcase_custom_showcase_customers'");
`showcase_custom_customers` was saved, listed with `_packageId:
com.example.showcase.custom`, and carried by `GET
/packages/com.example.showcase.custom/export` and `GET
/packages/export`. The pair does not share the base's namespace at the
save door, so the name is `BASE_NS_custom_TABLE`.
## Tests
- **Unit** (`external-namespace-reads-engine-registry.test.ts`, new
top-level `describe('[#30469 item 2] an import lands in the package of
its datasource')`, 14 cases): package-less and `sys_metadata` controls;
writable package; read-only base → ensure then save into the pair, in
that order; an explicit base-namespace name refused with the validator's
message for the pair, before the pair and before introspection; a
missing remote table makes no pair; an ensure refusal refuses the import
and saves nothing; for `group` and `isolated`, the import never creates
the pair and refuses naming the platform operator, and an existing pair
receives the import; `single` control; a protocol without the landing
doors refuses; the draft door keeps the base namespace. Four existing
cases in the same file now give their protocol fake the writability
answer.
- **Showcase**
(`external-import-code-datasource-namespace.dogfood.test.ts`): an import
with no name lands as `showcase_custom_customers` in
`com.example.showcase.custom`, both exports carry it, its rows read, and
a package-less `showcase_customers` saved before stays `sys_metadata`
and outside the pair's export; a new top-level `describe` boots under
`group` (`multiTenant: 'posture-only'`) and pins the refusal (nothing
saved, no pair), then the operator's ensure door, then the import
landing in the pair.
- Four more showcase files import over `showcase_external` under
explicit names; their names now carry `showcase_custom_`
(`external-federation-read-capability`,
`external-import-destructive-remedy`, `external-import-saves-like-meta`
(cold boot), `external-validate-sees-runtime-save`). All five files:
24/24 + the new cases green.
- **Red on the base `898145b6`** (source restored to the base, tests
kept): unit 10 failed / 15 passed of the file's 25 (the 10 non-control
new cases; the 4 new controls and the 11 older cases pass); showcase 4
failed / 7 passed (`expected 'showcase_customers' to be
'showcase_custom_customers'`; the walled import answered `201` where
`400` is pinned).
- **Ablation** (once, `scripts/ablation-replace.mjs`): the walled
condition replaced by `false` (anchor ×1 → ×0, marker ×0 → ×1) → the
four walled cases red (`Tests 4 failed | 21 passed`); restored blob
`09eaac88` = HEAD, `git diff HEAD` empty.
## Acceptance notes
- The import's object label is `toLabel(name)`, unchanged, so an import
over a read-only base now reads `Showcase Custom Customers`. The label
rule is not touched here.
- The ensure door's own refusals (a base with no namespace, a non-SemVer
version) reach the import caller as the import door's `400
EXTERNAL_IMPORT_ERROR` with the door's sentence; nothing is saved.
- ADR-0146 text (D3 "It receives" gains imports over the base's
datasource; D11 "environment metadata" gains imports over a Setup-added
datasource) is the maintainer's Tier H todo and is not edited here.
## Verification
<details><summary>Package suite and typecheck</summary>
On `8c52a7af` (after the `origin/main` merge; the one later commit
`100d47a7` rewords a comment in `plugin.ts`): `pnpm --filter
@objectstack/service-datasource run typecheck` exit 0; `vitest run
--maxWorkers=2`: Test Files 72 passed (72), Tests 1205 passed (1205).
</details>
<details><summary>Full dogfood battery (BREAKING narrowing)</summary>
`pnpm --filter @objectstack/dogfood test` under the verify lock on
`8c52a7af` with the closure built: Test Files 420 passed, 3 skipped
(423); Tests 3500 passed, 36 skipped (3536); `VERDICT command-exit 0`.
The tree differs from the head `100d47a7` by one comment in `plugin.ts`.
</details>
<details><summary>Derived gates (head 100d47a)</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 66 commands at `100d47a7`; each ran
with its exit code recorded before any pipe; `--ran`: 66 derived, 66
run, 0 NOT-MEASURED, 0 UNRUN, every exit 0. `pnpm lint` exit 0. `node
scripts/pm/check-governed-merges.mjs --test` on the final file list: 0
of 10 paths governed, 667 changed lines.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CbDkdjhP7yRbNoEsZu)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(service-datasource)!: an object imported from a package's external datasource is saved into that package, or into its customization package
6
+
7
+
Clause-②: yes (narrowing) — `POST /api/v1/datasources/:name/external/tables/:remote/import` (and the MCP `import_object` tool) now saves the object into the package that declares the datasource, or into that package's customization package `<base>.custom` when the package is read-only, and names it in that package's namespace. An explicit `name` in the read-only base's own namespace (`showcase_orders` over the showcase's `showcase_external`) is now refused with ADR-0028's message naming the pair-prefixed name (`showcase_custom_orders`); under a walled tenancy posture (`group`, `isolated`) an import that needs a customization package that does not exist yet is refused, naming the platform operator and the ensure door. `ExternalDatasourceServiceConfig` gains the optional `resolveImportLanding`, `persistObject` an optional third `packageId` argument, and the package exports the `ImportLanding` type.
8
+
Metadata-protocol: none
9
+
10
+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped: the imported object's definition keeps its shape, and the import request and its answer keep theirs. What moves is which package the import door saves the object into and therefore which namespace its name carries; rows already stored are not rewritten, so there is nothing for a migration to rewrite. -->
11
+
12
+
**BREAKING** accept-set narrowing at the external-datasource import door (`@objectstack/service-datasource`), ruling B on where an imported object lives (ruling record 6660988968).
13
+
14
+
-**Where an import lands.** The datasource's owning package decides. A datasource no package declares (added in Setup) keeps today's answer: a package-less row, environment metadata that no package export carries (ADR-0146 D11). A datasource declared by a writable package saves the object into that package. A datasource declared by a read-only installed package (a booted code package or a marketplace install) saves it into that package's customization package `<base>.custom`, which the import obtains from the ensure door first (ADR-0146 D2/D3), so `os package export` and `GET /api/v1/packages/<base>.custom/export` carry it.
15
+
-**The name it gets.** The save door judges the name against the package written into, so an import over a read-only package's datasource is named in the pair's namespace: the showcase's `customers` table imports as `showcase_custom_customers`, where it imported as `showcase_customers`. The draft door (`…/tables/:remote/draft`, the `*.object.ts` an author commits into the package's own source) still names it in the datasource package's namespace.
16
+
-**Walled postures.** Under `group` and `isolated` the platform operator alone creates a customization package. The import never creates it: it saves into one that already exists, and while none does it is refused (`400 EXTERNAL_IMPORT_ERROR`) with a message naming the platform operator and `POST /api/v1/packages/<base>/ensure-customization`. It is never saved package-less instead.
17
+
-**Objects imported before this release** stay where they are, package-less and under their old names. Importing the same table again makes a second object under the new name in the customization package; delete the old one once nothing points at it.
0 commit comments