@quadrokit/client 0.3.15 → 0.3.16
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/README.md +65 -0
- package/dist/generate/codegen.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ Environment variables (often via `.env` in the project root): `VITE_4D_ORIGIN`,
|
|
|
58
58
|
| **`datastore.gen.ts`** | When the catalog lists datastore REST methods (e.g. `testFn`): **`QuadroDatastoreMethodFn`**. Omitted when there are no such exposed methods. **`authentify`** is not special-cased here — it is typed under **`QuadroClient`** only when the catalog exposes it (see **`hasAuthentify`** in **`catalog.gen.json`**). |
|
|
59
59
|
| **`catalog.gen.json`** | Catalog runtime spec (dataclass layouts, methods, relations) consumed by `@quadrokit/client/runtime` — keeps **`client.gen.ts`** tiny. |
|
|
60
60
|
| **`client.gen.ts`** | Thin `createClient(config)` that wires `QuadroHttp` + `buildQuadroClientFromCatalogSpec` + `catalog.gen.json`. Config supports optional **`events`** (see [Request lifecycle events](#request-lifecycle-events)). |
|
|
61
|
+
| **`_quadroFns.gen.ts`** | Shared helpers: **`ResolveOverride`**, **`QuadroDataClassFn`**, **`QuadroEntityFn`**, **`QuadroEntityCollectionFn`**, **`QuadroDatastoreFn`** (used by **`*.gen.ts`** and optional override files). |
|
|
62
|
+
| **`entities/<Class>.overrides.ts`**, **`datastore.overrides.ts`** | Optional stubs you edit to **narrow method signatures** (see [Narrowing function signatures](#narrowing-function-signatures-override-files)). Created if missing; preserved across regenerate when possible. |
|
|
61
63
|
| **`meta.json`** | `__NAME`, `sessionCookieName` hint for 4D session cookies. |
|
|
62
64
|
|
|
63
65
|
Point your app imports at the generated folder, for example:
|
|
@@ -257,6 +259,69 @@ If the catalog does not list a method, it will not appear on the client — rege
|
|
|
257
259
|
|
|
258
260
|
---
|
|
259
261
|
|
|
262
|
+
## Narrowing function signatures (override files)
|
|
263
|
+
|
|
264
|
+
Generated ORDA **dataClass**, **entity**, and **entityCollection** methods, plus **datastore** methods, default to **loose** generics (`unknown` / `readonly unknown[]` for results and argument tuples). To type **return values** and **parameters** in TypeScript, add entries to the optional **override** modules beside the codegen output. The generator wires each method type as **`ResolveOverride<YourOverrides, "methodName", DefaultFn>`** in **`*.gen.ts`**: if your interface defines that **exact property name** (same spelling as the catalog / JS API), your signature wins; otherwise the default **`Quadro*Fn`** stands.
|
|
265
|
+
|
|
266
|
+
### Where the files live
|
|
267
|
+
|
|
268
|
+
**Split typings (default):** for each exposed dataclass, **`entities/<ClassName>.overrides.ts`** declares up to three interfaces:
|
|
269
|
+
|
|
270
|
+
| Interface | Catalog `applyTo` | Example call site |
|
|
271
|
+
|-----------|-------------------|-------------------|
|
|
272
|
+
| **`<ClassName>DataclassOverrides`** | dataClass | `quadro.Car.findACar(...)` |
|
|
273
|
+
| **`<ClassName>EntityOverrides`** | entity | `(await quadro.Car.get(id)).isAvailable(...)` |
|
|
274
|
+
| **`<ClassName>EntityCollectionOverrides`** | entityCollection | On **`all()`** / **`query()`** handles and related **`list`** APIs |
|
|
275
|
+
|
|
276
|
+
**`datastore.overrides.ts`** (next to **`types.gen.ts`**) maps **top-level** datastore methods on **`quadro`** by **catalog method name**.
|
|
277
|
+
|
|
278
|
+
**Single `types.gen.ts` (**`--no-split-type-files`**):** same idea, with **`./<ClassName>.overrides.ts`** and **`./datastore.overrides.ts`** next to **`types.gen.ts`**.
|
|
279
|
+
|
|
280
|
+
Stub files may **re-export** **`QuadroDataClassFn`**, **`QuadroEntityFn`**, **`QuadroEntityCollectionFn`**, **`QuadroDatastoreFn`** from **`_quadroFns.gen.ts`**; you can **`import type`** those helpers from **`_quadroFns.gen.js`** (or `.ts`) when you add properties.
|
|
281
|
+
|
|
282
|
+
### Fn type parameters (from `_quadroFns.gen.ts`)
|
|
283
|
+
|
|
284
|
+
- **`QuadroDataClassFn<R, A>`** — **`R`**: resolved **`Promise`** result type; **`A`**: **tuple** of positional arguments (sent as the JSON array body to 4D).
|
|
285
|
+
- **`QuadroEntityFn<R, A>`** — same shape for **per-entity** calls.
|
|
286
|
+
- **`QuadroEntityCollectionFn<R, A>`** — same **`R`** / **`A`**; real calls also accept **`init`** with **`EntityCollectionMethodOptions`** (`selection`, `entitySet`, …).
|
|
287
|
+
- **`QuadroDatastoreFn<B, R>`** — **`B`**: body type; **`R`**: result type for **`quadro.<datastoreMethod>(body?)`**.
|
|
288
|
+
|
|
289
|
+
### Examples
|
|
290
|
+
|
|
291
|
+
**Per-class overrides** (`entities/Car.overrides.ts` in the split layout):
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import type { QuadroDataClassFn, QuadroEntityFn } from '../_quadroFns.gen.js'
|
|
295
|
+
import type { Car } from './Car.gen.js'
|
|
296
|
+
|
|
297
|
+
export interface CarDataclassOverrides {
|
|
298
|
+
/** Catalog method name must match exactly (e.g. findACar). */
|
|
299
|
+
findACar: QuadroDataClassFn<Car[], [string, string]>
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface CarEntityOverrides {
|
|
303
|
+
isAvailable: QuadroEntityFn<boolean, readonly []>
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface CarEntityCollectionOverrides {}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Datastore overrides** (`datastore.overrides.ts`):
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import type { QuadroDatastoreFn } from './_quadroFns.gen.js'
|
|
313
|
+
|
|
314
|
+
export interface DatastoreOverrides {
|
|
315
|
+
testFn: QuadroDatastoreFn<{ foo: string }, { ok: true }>
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Regenerate behavior
|
|
320
|
+
|
|
321
|
+
Run **`quadrokit-client generate`** after catalog changes. The tool **rewrites** **`*.gen.ts`** (and related generated files) but **keeps** your existing **`*.overrides.ts`** content when refreshing **`entities/`** (and only creates stub override files if missing). Do not rely on editing **`*.gen.ts`** — put signature narrowing in override modules only.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
260
325
|
## Low-level runtime (advanced)
|
|
261
326
|
|
|
262
327
|
Import from **`@quadrokit/client/runtime`** when you need primitives without codegen:
|
|
@@ -155,7 +155,7 @@ function emitOverridesStubFile(className, quadroFnRelativeToStub) {
|
|
|
155
155
|
return `/* eslint-disable */
|
|
156
156
|
/**
|
|
157
157
|
* Optional: narrow REST method typings for ${className}.
|
|
158
|
-
* Add entries under the interfaces (e.g. findACar: QuadroDataClassFn<[
|
|
158
|
+
* Add entries under the interfaces (e.g. findACar: QuadroDataClassFn<Car[], [string, string]> — R then A).
|
|
159
159
|
* Import fn types from \`'${quadroFnRelativeToStub}'\` when you add entries (or reference re-exports below).
|
|
160
160
|
*/
|
|
161
161
|
export type {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadrokit/client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"description": "Typed 4D REST client and catalog code generator for QuadroKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"generate:fixture": "bun run src/cli.ts generate --url file://../../assets/catalog.json --out ../../.quadrokit/generated-demo"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@quadrokit/shared": "^0.3.
|
|
36
|
+
"@quadrokit/shared": "^0.3.16",
|
|
37
37
|
"undici": "^6.21.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|