Skip to content

Commit fb3126a

Browse files
Copilothuangyiirene
andcommitted
Fix documentation examples to be consistent with namespace exports
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 46e16ce commit fb3126a

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

packages/spec/README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,44 +141,51 @@ const user: User = {
141141
### Validation (Runtime)
142142

143143
```typescript
144+
// Style 1: Namespace from root
144145
import { Data } from '@objectstack/spec';
145-
// OR
146-
import { ObjectSchema } from '@objectstack/spec/data';
146+
const result = Data.ObjectSchema.safeParse(userConfig);
147147

148+
// Style 2: Namespace via subpath
149+
import * as Data from '@objectstack/spec/data';
148150
const result = Data.ObjectSchema.safeParse(userConfig);
149-
// OR
151+
152+
// Style 3: Direct subpath import
153+
import { ObjectSchema } from '@objectstack/spec/data';
150154
const result = ObjectSchema.safeParse(userConfig);
151155

152156
if (!result.success) {
153157
console.error("Invalid Object definition", result.error);
154158
}
155159
```
156-
import * as Data from '@objectstack/spec/data';
157-
158-
const result = Data.ObjectSchema.safeParse(userConfig);
159-
```
160160

161161
### Type Definitions (Compile Time)
162162

163163
```typescript
164+
// Style 1: Namespace from root
164165
import type { Data } from '@objectstack/spec';
165-
// Or: import type { Field } from '@objectstack/spec/data';
166-
167166
const myField: Data.Field = {
168167
name: "task_name",
169168
type: "text",
170169
label: "Task Name"
171170
};
171+
172+
// Style 2: Direct subpath import
173+
import type { Field } from '@objectstack/spec/data';
174+
const myField: Field = {
175+
name: "task_name",
176+
type: "text",
177+
label: "Task Name"
178+
};
172179
```
173180

174-
Using subpath imports:
181+
Using namespace imports for multiple protocols:
175182

176183
```typescript
177-
import type { Field } from '@objectstack/spec/data';
178-
import type { User } from '@objectstack/spec/system';
184+
import type * as Data from '@objectstack/spec/data';
185+
import type * as System from '@objectstack/spec/system';
179186

180-
const field: Field = { /* ... */ };
181-
const user: User = { /* ... */ };
187+
const field: Data.Field = { /* ... */ };
188+
const user: System.User = { /* ... */ };
182189
```
183190

184191
### JSON Schema (Tooling)

0 commit comments

Comments
 (0)