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 3aa0b42
Browse filesBrowse the repository at this point in the historyBrowse files
feat(spec,driver-sql,service-datasource): Oracle Database as a federation dialect — read live, write behind both opt-ins, never managed (#31351)
<!-- claude-projects-attribution: {"github_login":"marchtian"} -->
_Requested by **田騏** · [project
thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSiCoB7HoenXh7jmQHqPgnxH8)_Fixes#31328
## What changes
Oracle Database becomes a **federation dialect** of `driver-sql`. An
external datasource over Oracle reads live, and writes when both write
opt-ins are on. It is never managed.
**`@objectstack/spec`**
- The `oracle` driver row (alias `oracledb`) is federation-only. It is
`hasLocalDefault: false` and never a boot selection. A `managed` oracle
datasource, including the default mode, is refused at `defineStack` at
path `schemaMode`, and the message names the scope and the fix.
- `OracleConfigSchema` (`driver/oracle.zod.ts`): `connectString`, or
`host` / `port` (default 1521) / `serviceName`, plus `username`.
`password`, `url` and the TLS keys are refused by name, each with the
spelling that works.
- A datasource `ssl` block that asks for TLS is refused on oracle. Thin
mode takes TLS from a `tcps://` connect string and the factory never
hands the block to the driver, so the block would be dropped. A private
certificate authority is reached through a PEM wallet the connect string
names (`?wallet_location=DIR` holding `ewallet.pem`, or
`(SECURITY=(MY_WALLET_DIRECTORY=DIR))` in a descriptor); the connect
string reaches the driver verbatim. That route follows node-oracledb
6.10's Thin-mode source and has not been run against a live TLS
listener.
- Type-compat `SqlDialect` gains `'oracle'`, with
`DIALECT_ALIASES.oracle` and parameterised `NUMBER(p,s)` / `RAW(16)`
handling. On oracle every field pairing over a `RAW(16)` uuid column
(`lookup` included) is `'lossy'`, so a draft carries a review marker
until #31390 binds the uuid string back to RAW.
- ADR-0015 §4.6 lists Oracle, and §5.1 names the DDL gate's
federation-only arm. This is governed and owes a CONTRACT_REVIEW_TIER
review.
**`@objectstack/driver-sql`**
- `client: 'oracledb'` uses a knex client subclass over node-oracledb
**Thin** mode. `oracledb` is an optional peer.
- Paging uses `OFFSET … ROWS FETCH NEXT … ROWS ONLY`, so the minimum
version is **Oracle 12c R1**.
- Identifiers are quoted as the catalog folds them (UPPER).
- `LIKE` gets a bound `ESCAPE`. `$contains` is case-exact, and
`$icontains` folds ASCII only through `translate()`.
- A `NUMBER(1)` flag reads as a boolean, and a boolean writes 1 / 0.
`BOOLEAN` is native on 23ai.
- Temporal values: datetime and date comparands and writes bind as
instants (`TIMESTAMP WITH TIME ZONE`) on a UTC session. The fetch path
repairs Thin's local-clock decode of `DATE` / `TIMESTAMP`. `RAW(16)`
reads as a UUID string. Date buckets use `to_char(sys_extract_utc(…))`.
- Introspection runs four catalog reads, scoped to
`SYS_CONTEXT('USERENV','CURRENT_SCHEMA')`: ALL_TABLES, ALL_TAB_COLUMNS,
and PK/unique and FK from ALL_CONSTRAINTS. A cross-schema FK parent
carries `referencedSchema`.
- Refusals:
- every DDL operation: `UnsupportedDialectEmissionError`, reason
`federation-only`;
- a `''` comparand on `= $eq $ne $in $nin $gt $gte $lt $lte $between`:
`INVALID_FILTER`, withheld subtree. Oracle stores `''` as NULL, so the
comparison would silently mean IS NULL;
- JSON-array membership: `INVALID_FILTER`;
- upsert: `NOT_IMPLEMENTED` / 501. No MERGE is emitted, and the docs
state this.
- **Arms found only on the live server**, not in the card. Each has a
compile pin and a live pin:
- `$empty` on a text column compiles as IS NULL / IS NOT NULL. `= ''` /
`<> ''` compare against NULL there, so `$empty: false` answered no rows.
- A `Date` comparand against a NON-temporal column binds as its
canonical ISO text. Bound as a TIMESTAMP, it made Oracle convert the
text column, which raised on every non-timestamp row.
**`@objectstack/service-datasource`**
- The shared factory has an oracle arm. It composes
`host:port/serviceName` or passes `connectString` verbatim, and the
password is the bound secret. A legacy stored `ssl` block is refused at
this last door too.
- `oracledb` joins `OPTIONAL_DRIVER_CLIENT_PACKAGES`, so a missing
package is answered with its install. This is pinned through the real
factory and boot path.
**Docs:** `external-datasources.mdx` gains an Oracle section covering
the config shape, minimum version, Thin mode, TLS, value mapping,
introspection scope, and every refusal including the upsert 501.
## Pre-existing defects found here: ported separately, now on main
Oracle made three defects visible that exist on **every dialect**,
because every Oracle table is bound through `external.columnMap` (its
columns are UPPER-case): `aggregate()` / `distinct()` and `update()` /
`delete()` / `bulkDelete()` named the field instead of the mapped
column, and a paged read got no unique tie-breaker. They were carried
here as temporary commits and ported to `main` through #31340 and
#31342. Both have landed, and main is merged, so none of those commits
or changesets remain in this PR's diff.
## Why
#31328: federation over the Oracle estates that customers already run,
with no ETL.
## Verification
- **Live conformance:**
`sql-driver-oracle-federation-conformance.test.ts` runs against
gvenzl/oracle-free 23ai: **261/261 pass**, under `TZ=America/New_York`
and again under `TZ=Asia/Shanghai`. The same harness runs on SQLite as a
control: raw remote DDL, `columnMap`, external mode, rows written
through `create()`.
- Case-sets run: `FILTER_LOGIC_CASES`, `FILTER_TEXT_CASES`,
`PAGINATION_CASES`, `PAGINATION_UNORDERED_CASES`,
`PAGINATION_ZERO_LIMIT_CASES`, `FILTER_COMPARAND_TYPE_CASES` (the
executed half; the door-refusal half is dialect-free and pinned
elsewhere), `AGGREGATION_CASES`, `TEMPORAL_CASES`.
- Not run, each with its reason:
- `TEMPORAL_TIME_CASES`: Oracle has no TIME type, so a remote
time-of-day column has no single storage form to hold the set to.
- `VALUE_ROUNDTRIP_CASES`, `READABLE_IDS_CASES`,
`UNIQUE_NULL_DISTINCT_CASES`: they pin the driver's OWN managed storage
forms and indexes, which a federation-only dialect never creates.
- `BULK_WRITE_HOOK`: an engine-layer contract, not a dialect one.
- **CI does not provision Oracle.** Without `OS_TEST_ORACLE_URL` the
Oracle cell is a **named skip** ("is provisioned — set
OS_TEST_ORACLE_URL…"), never a pass. `OS_EXPECT_LIVE_ORACLE=1` turns
that skip into a failure. The cell lives in
`live-dialect-matrix.testkit.ts` as `ORACLE_CELL`, outside
`DIALECT_CELLS`, and `OS_EXPECT_LIVE_DIALECT_MATRIX` does not apply to
it.
- **Compile-level pins:** 41 in `sql-driver-oracle-dialect.test.ts`,
covering every emitter arm and refusal. The two new builders have
refusal-seam rows.
- **Also verified live** beyond the conformance file: create (with and
without id; a RAW(16) default reads back as a uuid), update, updateMany,
delete, bulkCreate, deleteMany, introspection (PK, composite PK,
single-column unique, FK, types), BOOLEAN / NUMBER(1) / CLOB reads.
- **Suites at cdd0a22:** driver-sql 4066 passed / 219 skipped; the
live Oracle conformance file 261/261. service-datasource 1285 passed.
spec `src/data` 6051 passed. `check:generated` fresh, and
`check:test-typecheck` OK with an 8 GB heap.
- Dispatch gates: posted in the os-dev-report comment.
**Known limitations (in the docs):**
- During a DST spring-forward gap hour in a non-UTC server process, the
read repair is off by the gap. Running with `TZ=UTC` removes the gap.
- A `NUMBER` above 2^53 loses precision.
- Filtering or writing a `RAW(16)` column by its uuid string is
unsupported; the type matrix flags those pairings `'lossy'`. `HEXTORAW`
binding: #31390.
- Introspection lists the current schema only. Another owner's table is
bound by `remoteName: 'OWNER.TABLE'`.
- Oracle is not yet offered in the Studio driver catalog's connection
form: #31389.
Clause-②: yes (widening)
Metadata-protocol: added
Changed lines: 2851 (+2765 / -86), under the 3000 threshold.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_017ihL2cVRvyiEh4PJ1FTQGi
<!-- signed: epic:#27261#1 · marchtian ·
session_017ihL2cVRvyiEh4PJ1FTQGi -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(spec,driver-sql,service-datasource): Oracle Database as a federation dialect: read live, write behind both opt-ins, never managed
8
+
9
+
Clause-②: yes (widening)
10
+
Metadata-protocol: added
11
+
12
+
- **`@objectstack/spec`**: a datasource may name `driver: 'oracle'` (alias `oracledb`), with `OracleConfigSchema` as its `config` contract: `connectString`, or `host` / `port` (default 1521) / `serviceName`, and `username`. `password` (the credential is the bound secret), `url`, and the TLS keys are refused by name with the spelling that works. The row is federation-only (`FEDERATION_ONLY_DRIVER_IDS`, `isFederationOnlyDriver`) with no local default. It is never a boot selection, and a `managed` oracle datasource, including the default mode, is refused at `defineStack` with the scope and the fix named. A datasource `ssl` block that asks for TLS is refused on oracle too, because Thin mode takes TLS from a `tcps://` connect string and would drop the block. A private certificate authority is reached through a PEM wallet the connect string names (`?wallet_location=DIR`, or `MY_WALLET_DIRECTORY` in a descriptor). Two published types narrow with no runtime change: `resolveDatabaseDriverId()` now returns `DatabaseSelectionDriverId | undefined` and `DATABASE_DRIVER_SELECTION_IDS` is `readonly DatabaseSelectionDriverId[]` (new types `DatabaseSelectionDriverId` and `FederationOnlyDriverId`), because no selection spelling resolves to a federation-only id. A consumer that asks `DATABASE_DRIVER_SELECTION_IDS.includes(id)` with a wider `BuiltinDriverId` widens the list first: `(DATABASE_DRIVER_SELECTION_IDS as readonly string[]).includes(id)`. The type-compatibility matrix gains `'oracle'` (`DIALECT_ALIASES.oracle`, `NUMBER(p,s)` / `RAW(16)` parameterised), and ADR-0015 §4.6 lists it. On oracle, `isCompatible` answers `'lossy'` for every field over a `RAW(16)` uuid column, `lookup` included, because the driver cannot yet filter or write it by its UUID string.
13
+
- **`@objectstack/driver-sql`**: `client: 'oracledb'` speaks Oracle over node-oracledb in Thin mode, with no Oracle Client libraries. `oracledb` is an optional peer. Minimum Oracle 12c Release 1. Paging uses `OFFSET … ROWS FETCH NEXT … ROWS ONLY`. Identifiers are quoted as the catalog folds them (UPPER). `LIKE` gets a bound `ESCAPE`, and the `$icontains` fold is ASCII-only. A NUMBER(1) flag reads as a boolean. Datetime and date comparands and writes bind as instants on a UTC session, and DATE / TIMESTAMP reads are repaired from Thin's local-clock decode. RAW(16) reads as a UUID string. `$empty` on a text column is its NULL row. Catalog introspection covers the current schema: ALL_TABLES, ALL_TAB_COLUMNS, and PK/unique/FK from ALL_CONSTRAINTS. Refusals: every DDL operation (`UnsupportedDialectEmissionError`, reason `federation-only`); a `''` equality or range comparand (`INVALID_FILTER`, because Oracle stores `''` as NULL and would answer IS NULL); JSON-array membership (`INVALID_FILTER`); and upsert (`NOT_IMPLEMENTED`, 501, because no MERGE is emitted).
14
+
-**`@objectstack/service-datasource`**: the shared driver factory builds the oracle arm. It composes `host:port/serviceName` or passes `connectString` verbatim, and the password is the bound secret. A missing `oracledb` package is answered with that package's install.
15
+
16
+
Held to the shared conformance case-sets over a live Oracle 23ai (`OS_TEST_ORACLE_URL`, declared skip without it, `OS_EXPECT_LIVE_ORACLE=1` to require it). The Oracle section of the external-datasources guide states the minimum version, the config shape, and each refusal.
credentialsRef: 'sys_secret:4b1e…', // the password is the bound secret, never inline
504
+
},
505
+
});
506
+
```
507
+
508
+
**Requirements**
509
+
510
+
-**Oracle Database 12c Release 1 or later.** Pages are read with
511
+
`OFFSET … ROWS FETCH NEXT … ROWS ONLY`, which 12c introduced. Verified live on
512
+
Oracle Database 23ai Free.
513
+
-**The `oracledb` package.** It is an optional install of `@objectstack/driver-sql`
514
+
(`npm install oracledb`). It runs in **Thin mode**, which is pure JavaScript and
515
+
needs no Oracle Client libraries. Without the package, the datasource's connect
516
+
fails with an error that names that install.
517
+
518
+
**The `config` block**
519
+
520
+
| Key | Meaning |
521
+
| --- | --- |
522
+
|`connectString`| An Easy Connect string (`host:port/service_name`), a `tcps://…` string, or a TNS descriptor. Wins over the keys below when set. |
523
+
|`host` / `port` / `serviceName`| Composed into `host:port/serviceName` when there is no `connectString`. `port` defaults to 1521. |
524
+
|`username`| The database user. Its schema is the one the Tables tab lists. |
525
+
526
+
`password` and `url` are refused by name. The password is the bound secret, and an
527
+
Oracle connect string is not a URL.
528
+
529
+
**TLS** is chosen by the connect string: `connectString: 'tcps://erp-db.internal:2484/ERPPDB1'`.
530
+
The server is verified against the host's trusted certificate authorities. If the
531
+
database's certificate comes from a private certificate authority, put that CA in a
532
+
PEM wallet (a directory holding `ewallet.pem`) on the host and name the directory in
533
+
the connect string, which reaches the driver unchanged:
534
+
`'tcps://erp-db.internal:2484/ERPPDB1?wallet_location=/etc/oracle/wallet'`, or
535
+
`(SECURITY=(MY_WALLET_DIRECTORY=/etc/oracle/wallet))` inside a descriptor. This route
536
+
follows node-oracledb's Thin-mode connect-string handling and has not been tested
537
+
against a live TLS listener here. A datasource `ssl` block and `ca`, `cert`, `key` or
538
+
`rejectUnauthorized` config keys are refused rather than silently dropped, because
539
+
the driver reads TLS only from the connect string.
540
+
541
+
**Binding tables.** Oracle stores an unquoted identifier in UPPER case, so an
542
+
imported table's columns are `CUST_NO`, `FULL_NAME`, and so on. The Tables tab and
543
+
`import_object` map each one to a lower-case field through `external.columnMap`. The
544
+
driver quotes the catalog spelling back in every statement. The Tables tab lists the
545
+
tables of the connecting user's current schema. Reach another owner's table with an
546
+
object whose `remoteName` is `OWNER.TABLE`.
547
+
548
+
**How values read and compare**
549
+
550
+
| Remote column | Field | Notes |
551
+
| --- | --- | --- |
552
+
|`BOOLEAN` (23ai) |`boolean`| Exact. |
553
+
|`NUMBER(1)` flag |`boolean`| Judged lossy by the type matrix: it is an integer column. It reads as `true` / `false`, and a write sends `1` / `0`. |
554
+
|`CHAR(1)` flag (`'Y'` / `'N'`) |`text`| Judged incompatible with a `boolean` field, so bind it as text. A boolean binding would read every non-NULL letter as `true`. |
555
+
|`DATE`|`datetime`| An Oracle `DATE` carries a time of day. A `date` field over it is judged lossy: the time is dropped. |
556
+
|`TIMESTAMP WITH TIME ZONE`|`datetime`| Compared and returned as UTC instants. |
557
+
|`CLOB`|`textarea`||
558
+
|`RAW(16)`|`text`| Read as a lower-case UUID string. Every field pairing over it is judged lossy, so a draft marks it for review: it cannot be filtered or written by that string yet (see below). |
559
+
560
+
The driver pins every session to UTC. Thin mode decodes `DATE` and `TIMESTAMP`
561
+
values with the server process's local clock, and the driver repairs that on read.
562
+
The repair is exact except during the hour a daylight-saving spring-forward skips in
563
+
the process's own time zone. Run the server with `TZ=UTC` and there is no such hour.
564
+
565
+
**What Oracle answers differently**
566
+
567
+
-**`''` is NULL in Oracle.** A filter that compares against an empty string
568
+
(`= ''`, `$ne: ''`, `$in: ['']`, a range bound of `''`) is refused with
569
+
`INVALID_FILTER`, because Oracle would answer it as a comparison with NULL rather
570
+
than as written. Use `$null` / `$empty` instead. `$empty` on a text column matches
571
+
exactly the NULL rows there.
572
+
-**Upsert is refused** with `NOT_IMPLEMENTED` (HTTP 501). The driver emits no
573
+
`MERGE`. Use create and update.
574
+
-**JSON-array membership** (`$contains` on a multi-value field) is refused. There is
575
+
no Oracle construct modelled for it.
576
+
-**Filtering or writing a `RAW(16)` column by its UUID string is not supported.**
577
+
The driver presents the value as a string on read, but it does not convert the
578
+
string back to `RAW` for a comparison or a write. This includes a `lookup` keyed
579
+
by a `SYS_GUID()` column. Binding through `HEXTORAW` is tracked in
|**port**|`integer`| optional (default: `1521`) | Listener port |
63
+
|**serviceName**|`string`| optional | Database service name |
64
+
|**username**|`string`| optional | Authentication user (also the default schema) |
65
+
|**password**|`never`| optional | Set through the connection form's secret field or `external.credentialsRef` — encrypted into `sys_secret`, never stored in `config`. A datasource defined in code (`defineDatasource`) leaves the credential out of the declaration: it is read at connect time from the runtime environment variable derived from the datasource name (`OS_DATASOURCE_WAREHOUSE_PASSWORD` for a datasource named `warehouse`), which `os serve` / `os start` honour by default (`OS_DATASOURCE_ENV_CREDENTIALS=on`). |
Copy file name to clipboardExpand all lines: content/docs/references/data/index.mdx
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Data Protocol — complete schema reference
3
3
navTitle: Data Protocol
4
-
description: "The ObjectStack Data Protocol in 32 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
4
+
description: "The ObjectStack Data Protocol in 33 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
5
5
---
6
6
7
7
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
@@ -21,6 +21,7 @@ This section contains all protocol schemas for the data layer of ObjectStack.
0 commit comments