Skip to content

Commit 6e64a05

Browse files
os-zhuangclaude
andcommitted
feat(spec): defineX factories + XInput aliases for the 16 remaining writable domains (#2035)
Adds one type-safe authoring entry per writable domain — defineDatasource, defineConnector, definePolicy, defineSharingRule, defineRole, definePermissionSet, defineEmailTemplateDefinition, defineReport, defineWebhook, defineObjectExtension, defineCube, defineMapping, defineTheme, defineTranslationBundle, definePage, defineAction — mirroring the 19 existing factories (XSchema.parse(z.input)). Each factory is a *value* export: a broken import hard-errors instead of silently degrading to `any` (the #2023 failure mode), and authoring errors surface at .parse() time with field-level messages. Also backfills the six missing input aliases: PolicyInput, CubeInput, MappingInput, ThemeInput, TranslationBundleInput, PageInput. Purely additive — no existing exports change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 124959e commit 6e64a05

18 files changed

Lines changed: 199 additions & 0 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"@objectstack/spec": minor
3+
---
4+
5+
spec: add `defineX` factories for the remaining 16 writable domains and the 6
6+
missing `XInput` aliases — one consistent, type-safe authoring entry per domain
7+
(#2035).
8+
9+
New factories: `defineDatasource`, `defineConnector`, `definePolicy`,
10+
`defineSharingRule`, `defineRole`, `definePermissionSet`,
11+
`defineEmailTemplateDefinition`, `defineReport`, `defineWebhook`,
12+
`defineObjectExtension`, `defineCube`, `defineMapping`, `defineTheme`,
13+
`defineTranslationBundle`, `definePage`, `defineAction`. Each mirrors the 19
14+
existing factories (`XSchema.parse(z.input<…>)`): input-shape ergonomics +
15+
authoring-time validation. Because a factory is a *value* import, a broken
16+
import hard-errors instead of silently degrading to `any` (the #2023 failure
17+
mode), and errors surface at `.parse()` time with field-level messages.
18+
19+
Also adds the previously-missing input aliases `PolicyInput`, `CubeInput`,
20+
`MappingInput`, `ThemeInput`, `TranslationBundleInput`, `PageInput`.
21+
22+
Purely additive: no existing exports change.

packages/spec/src/automation/webhook.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ export type Webhook = z.infer<typeof WebhookSchema>;
144144
/** Authoring input for {@link Webhook} — defaulted fields are optional. */
145145
export type WebhookInput = z.input<typeof WebhookSchema>;
146146
export type WebhookReceiver = z.infer<typeof WebhookReceiverSchema>;
147+
148+
/**
149+
* Type-safe factory for an outbound webhook. Validates at authoring time via
150+
* `.parse()` and accepts input-shape config (optional defaults, CEL
151+
* shorthand) — preferred over a bare `: Webhook` literal.
152+
*/
153+
export function defineWebhook(config: z.input<typeof WebhookSchema>): Webhook {
154+
return WebhookSchema.parse(config);
155+
}

packages/spec/src/data/analytics.zod.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,15 @@ export type Metric = z.infer<typeof MetricSchema>;
174174
export type Dimension = z.infer<typeof DimensionSchema>;
175175
export type CubeJoin = z.infer<typeof CubeJoinSchema>;
176176
export type Cube = z.infer<typeof CubeSchema>;
177+
/** Authoring input for {@link Cube} — defaulted fields are optional. */
178+
export type CubeInput = z.input<typeof CubeSchema>;
179+
180+
/**
181+
* Type-safe factory for an analytics semantic-layer cube. Validates at authoring time via
182+
* `.parse()` and accepts input-shape config (optional defaults, CEL
183+
* shorthand) — preferred over a bare `: Cube` literal.
184+
*/
185+
export function defineCube(config: z.input<typeof CubeSchema>): Cube {
186+
return CubeSchema.parse(config);
187+
}
177188
export type AnalyticsQuery = z.infer<typeof AnalyticsQuerySchema>;

packages/spec/src/data/datasource.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,12 @@ export type Datasource = z.infer<typeof DatasourceSchema>;
260260
/** Authoring input for {@link Datasource} — defaulted fields are optional. */
261261
export type DatasourceInput = z.input<typeof DatasourceSchema>;
262262
export type DatasourceCapabilitiesType = z.infer<typeof DatasourceCapabilities>;
263+
264+
/**
265+
* Type-safe factory for an external data connection (datasource). Validates at authoring time via
266+
* `.parse()` and accepts input-shape config (optional defaults, CEL
267+
* shorthand) — preferred over a bare `: Datasource` literal.
268+
*/
269+
export function defineDatasource(config: z.input<typeof DatasourceSchema>): Datasource {
270+
return DatasourceSchema.parse(config);
271+
}

packages/spec/src/data/mapping.zod.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,15 @@ export const MappingSchema = lazySchema(() => z.object({
9292
}));
9393

9494
export type Mapping = z.infer<typeof MappingSchema>;
95+
/** Authoring input for {@link Mapping} — defaulted fields are optional. */
96+
export type MappingInput = z.input<typeof MappingSchema>;
97+
98+
/**
99+
* Type-safe factory for a data import/export mapping. Validates at authoring time via
100+
* `.parse()` and accepts input-shape config (optional defaults, CEL
101+
* shorthand) — preferred over a bare `: Mapping` literal.
102+
*/
103+
export function defineMapping(config: z.input<typeof MappingSchema>): Mapping {
104+
return MappingSchema.parse(config);
105+
}
95106
export type FieldMapping = z.infer<typeof FieldMappingSchema>;

packages/spec/src/data/object.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,12 @@ export const ObjectExtensionSchema = lazySchema(() => z.object({
10111011
export type ObjectExtension = z.infer<typeof ObjectExtensionSchema>;
10121012
/** Authoring input for {@link ObjectExtension} — defaulted fields are optional. */
10131013
export type ObjectExtensionInput = z.input<typeof ObjectExtensionSchema>;
1014+
1015+
/**
1016+
* Type-safe factory for an extension to an object owned by another package. Validates at authoring time via
1017+
* `.parse()` and accepts input-shape config (optional defaults, CEL
1018+
* shorthand) — preferred over a bare `: ObjectExtension` literal.
1019+
*/
1020+
export function defineObjectExtension(config: z.input<typeof ObjectExtensionSchema>): ObjectExtension {
1021+
return ObjectExtensionSchema.parse(config);
1022+
}

packages/spec/src/identity/role.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ export const RoleSchema = lazySchema(() => z.object({
4545
export type Role = z.infer<typeof RoleSchema>;
4646
/** Authoring input for {@link Role} — defaulted fields are optional. */
4747
export type RoleInput = z.input<typeof RoleSchema>;
48+
49+
/**
50+
* Type-safe factory for a role in the role hierarchy. Validates at authoring time via
51+
* `.parse()` and accepts input-shape config (optional defaults, CEL
52+
* shorthand) — preferred over a bare `: Role` literal.
53+
*/
54+
export function defineRole(config: z.input<typeof RoleSchema>): Role {
55+
return RoleSchema.parse(config);
56+
}

packages/spec/src/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ export { defineBook } from './system/book.zod';
8080
export { defineAgent } from './ai/agent.zod';
8181
export { defineTool } from './ai/tool.zod';
8282
export { defineSkill } from './ai/skill.zod';
83+
84+
// DX factories for the remaining authoring domains (issue #2035) — one type-safe
85+
// entry per writable domain, mirroring the 19 factories above. `defineX` is a
86+
// *value* import: a broken import hard-errors instead of silently degrading to
87+
// `any` (the #2023 failure mode). Input-shape config + runtime `.parse()`.
88+
export { defineDatasource } from './data/datasource.zod';
89+
export { defineConnector } from './integration/connector.zod';
90+
export { definePolicy } from './security/policy.zod';
91+
export { defineSharingRule } from './security/sharing.zod';
92+
export { defineRole } from './identity/role.zod';
93+
export { definePermissionSet } from './security/permission.zod';
94+
export { defineEmailTemplateDefinition } from './system/email-template.zod';
95+
export { defineReport } from './ui/report.zod';
96+
export { defineWebhook } from './automation/webhook.zod';
97+
export { defineObjectExtension } from './data/object.zod';
98+
export { defineCube } from './data/analytics.zod';
99+
export { defineMapping } from './data/mapping.zod';
100+
export { defineTheme } from './ui/theme.zod';
101+
export { defineTranslationBundle } from './system/translation.zod';
102+
export { definePage } from './ui/page.zod';
103+
export { defineAction } from './ui/action.zod';
83104
export type { Agent } from './ai/agent.zod';
84105
export type { Tool } from './ai/tool.zod';
85106
export type { Skill } from './ai/skill.zod';

packages/spec/src/integration/connector.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,12 @@ export const ConnectorSchema = lazySchema(() => z.object({
630630
export type Connector = z.infer<typeof ConnectorSchema>;
631631
/** Authoring input for {@link Connector} — defaulted fields are optional. */
632632
export type ConnectorInput = z.input<typeof ConnectorSchema>;
633+
634+
/**
635+
* Type-safe factory for an external-system connector. Validates at authoring time via
636+
* `.parse()` and accepts input-shape config (optional defaults, CEL
637+
* shorthand) — preferred over a bare `: Connector` literal.
638+
*/
639+
export function defineConnector(config: z.input<typeof ConnectorSchema>): Connector {
640+
return ConnectorSchema.parse(config);
641+
}

packages/spec/src/security/permission.zod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,12 @@ export type PermissionSet = z.infer<typeof PermissionSetSchema>;
196196
export type PermissionSetInput = z.input<typeof PermissionSetSchema>;
197197
export type ObjectPermission = z.infer<typeof ObjectPermissionSchema>;
198198
export type FieldPermission = z.infer<typeof FieldPermissionSchema>;
199+
200+
/**
201+
* Type-safe factory for a permission set / profile. Validates at authoring time via
202+
* `.parse()` and accepts input-shape config (optional defaults, CEL
203+
* shorthand) — preferred over a bare `: PermissionSet` literal.
204+
*/
205+
export function definePermissionSet(config: z.input<typeof PermissionSetSchema>): PermissionSet {
206+
return PermissionSetSchema.parse(config);
207+
}

0 commit comments

Comments
 (0)