Skip to content

Commit cb75175

Browse files
authored
Merge pull request #74 from constructive-io/devin/1774461709-document-type-imports
docs: document SDK type deep imports and blueprint snake_case convention
2 parents e7b01a5 + aaba156 commit cb75175

2 files changed

Lines changed: 86 additions & 4 deletions

File tree

.agents/skills/constructive-graphql/references/codegen-orm-output.md

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,31 @@ export function createClient(options: {
4141

4242
### types.ts
4343

44+
Barrel that re-exports from `input-types.ts`:
45+
46+
```typescript
47+
export * from './input-types';
48+
```
49+
50+
### input-types.ts
51+
4452
All TypeScript types including:
4553

46-
- Entity interfaces
47-
- Select types with const generics
48-
- Filter types
49-
- Input types
54+
- Entity interfaces (e.g. `User`, `Database`, `Table`, `Field`, `Policy`)
55+
- Provision types (e.g. `SecureTableProvision`, `RelationProvision`, `Blueprint`)
56+
- Filter types (e.g. `StringFilter`, `UUIDFilter`, `JSONFilter`)
57+
- Input types for mutations (e.g. `CreateUserInput`, `UpdateTableInput`)
58+
- Enum types and custom scalar types
59+
60+
### select-types.ts
61+
62+
Select types with const generics for type-narrowed queries:
63+
5064
- Result types with discriminated unions
65+
- Const-generic select types (only selected fields appear in return type)
66+
- Connection/pagination result types
67+
68+
> **Important:** `index.ts` re-exports `select-types` but NOT `types.ts`/`input-types.ts` to avoid name collisions (many types like `Field`, `Table`, `Policy` exist in both files with different shapes). See [Accessing Input Types](#accessing-input-types-deep-imports) below.
5169
5270
## Client API
5371

@@ -436,3 +454,65 @@ const result = await db.login({
436454
password: 'secret',
437455
}).execute();
438456
```
457+
458+
## Accessing Input Types (Deep Imports)
459+
460+
The ORM `index.ts` re-exports `select-types` but deliberately does **not** re-export `types.ts` / `input-types.ts`. This is because many type names exist in both files with incompatible shapes (e.g. `Field`, `Table`, `Policy`, `Index`, `User`~80+ collisions). A blanket `export *` from both would cause TypeScript `TS2308` ambiguity errors.
461+
462+
### Why the collision exists
463+
464+
- **`input-types.ts`** contains the full entity interfaces with all fields (used for create/update inputs and query results)
465+
- **`select-types.ts`** contains const-generic select types that narrow the return type to only selected fields
466+
467+
Both files define types with the same names (e.g. `Field` in `input-types.ts` is the full entity, `Field` in `select-types.ts` is the select-narrowed version). Re-exporting both through `index.ts` would be ambiguous.
468+
469+
### How to access input types
470+
471+
Use a **deep import** to reach `input-types.ts` directly. This works with standard Node.js module resolution — no `exports` field or special configuration needed:
472+
473+
```typescript
474+
// Deep import from the SDK package
475+
import type {
476+
SecureTableProvision,
477+
RelationProvision,
478+
Blueprint,
479+
BlueprintTemplate,
480+
Field,
481+
Table,
482+
Policy,
483+
} from '@constructive-io/sdk/public/orm/input-types';
484+
```
485+
486+
This pattern follows the same convention as `react/jsx-runtime` or `next/server` — a file at a known path inside the package.
487+
488+
### Per-API type paths
489+
490+
Each API target generates its own ORM with its own type files:
491+
492+
| API | Deep import path |
493+
|-----|-----------------|
494+
| `public` | `@constructive-io/sdk/public/orm/input-types` |
495+
| `admin` | `@constructive-io/sdk/admin/orm/input-types` |
496+
| `auth` | `@constructive-io/sdk/auth/orm/input-types` |
497+
| `objects` | `@constructive-io/sdk/objects/orm/input-types` |
498+
| `migrate` | `@constructive-io/sdk/migrate/orm/input-types` |
499+
500+
### Namespace import (alternative)
501+
502+
If you use the `@constructive-io/node` package (which wraps the SDK), types are available through the namespace:
503+
504+
```typescript
505+
import { public_ } from '@constructive-io/node';
506+
507+
// Access types through the namespace
508+
type MyBlueprint = public_.Blueprint;
509+
type MyTable = public_.SecureTableProvision;
510+
```
511+
512+
The namespace import pulls from `select-types` (via `index.ts`), so it gives you the select-narrowed versions. For the full entity types (e.g. for constructing mutation inputs), use the deep import path above.
513+
514+
### Important notes
515+
516+
- The deep import path depends on the SDK's internal file layout. If the SDK reorganizes directories in a future version, the path may change.
517+
- Add `@constructive-io/sdk` as a **direct dependency** (not just devDependency) if your package needs these types at build time — this ensures pnpm creates the symlink for the deep path to resolve.
518+
- The `types.ts` barrel (`export * from './input-types'`) exists as a convenience re-export within the `orm/` directory but is not chained through `index.ts`.

.agents/skills/constructive/references/blueprint-definition-format.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The blueprint `definition` is a JSONB document that declaratively describes a complete domain schema. It uses structured table config with inline `$type` discriminators for nodes, policies, and relations.
44

5+
> **snake_case convention:** The definition uses **snake_case** keys (`table_name`, `grant_roles`, `delete_action`, etc.) because it is stored as opaque JSONB in PostgreSQL. PostGraphile/GraphQL does not transform keys inside JSONB fields — the JSON is passed through to the `construct_blueprint()` PL/pgSQL function as-is, which reads snake_case keys directly. This is intentional and differs from the camelCase conventions used in the SDK's ORM types (`SecureTableProvision`, `RelationProvision`), which represent the metaschema row types. When writing blueprint definitions, always use snake_case.
6+
57
## Top-Level Structure
68

79
```json

0 commit comments

Comments
 (0)