@spooky-sync/query-builder 0.0.1-canary.19 → 0.0.1-canary.20
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/package.json
CHANGED
|
@@ -120,6 +120,66 @@ new QueryBuilder(schema, 'user')
|
|
|
120
120
|
|
|
121
121
|
Cardinality is inferred from the schema. For `'one'` relationships, the result is an object. For `'many'`, it is an array.
|
|
122
122
|
|
|
123
|
+
## Backend Schema
|
|
124
|
+
|
|
125
|
+
The `backends` field in `SchemaStructure` defines available HTTP backends, their outbox tables, and typed routes. This is generated by `spooky generate` from your `spooky.yml` config and OpenAPI spec.
|
|
126
|
+
|
|
127
|
+
### Schema Structure
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
export interface SchemaStructure {
|
|
131
|
+
// ...tables, relationships...
|
|
132
|
+
readonly backends: Record<string, HTTPOutboxBackendDefinition>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface HTTPOutboxBackendDefinition {
|
|
136
|
+
readonly outboxTable: string; // The SurrealDB table used as the outbox (e.g., 'job')
|
|
137
|
+
readonly routes: Record<string, HTTPBackendRouteDefinition>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface HTTPBackendRouteDefinition {
|
|
141
|
+
readonly args: Record<string, HTTPBackendRouteArgsDefinition>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface HTTPBackendRouteArgsDefinition {
|
|
145
|
+
readonly type: ValueType; // 'string' | 'number' | 'boolean' | 'null' | 'json'
|
|
146
|
+
readonly optional: boolean;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Generated Example
|
|
151
|
+
|
|
152
|
+
Given a `spooky.yml` with an `api` backend and an OpenAPI spec defining a `/spookify` route with an `id` parameter, `spooky generate` produces:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
export const schema = {
|
|
156
|
+
// ...tables, relationships...
|
|
157
|
+
backends: {
|
|
158
|
+
"api": {
|
|
159
|
+
outboxTable: 'job' as const,
|
|
160
|
+
routes: {
|
|
161
|
+
"/spookify": {
|
|
162
|
+
args: {
|
|
163
|
+
"id": {
|
|
164
|
+
type: 'string' as const,
|
|
165
|
+
optional: false as const
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
} as const satisfies SchemaStructure;
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Backend Type Helpers
|
|
176
|
+
|
|
177
|
+
- `BackendNames<S>` — Union of all backend name strings (e.g., `'api'`)
|
|
178
|
+
- `BackendRoutes<S, B>` — Union of all route paths for backend `B` (e.g., `'/spookify'`)
|
|
179
|
+
- `RoutePayload<S, B, R>` — Typed payload object for route `R` on backend `B`. Required args become required fields, optional args become optional fields. Types are mapped from `ValueType` to TypeScript types.
|
|
180
|
+
|
|
181
|
+
These types are used by `db.run()` to provide full type safety — backend name, route path, and payload are all checked at compile time.
|
|
182
|
+
|
|
123
183
|
## Type Helpers
|
|
124
184
|
|
|
125
185
|
See [references/type-helpers.md](references/type-helpers.md) for a full reference of all type utilities.
|