@relyio/sdk 0.12.0 → 0.14.0

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/dist/{chunk-3DRDHXLY.js → chunk-5UMY6CS4.js} +435 -23
  3. package/dist/{chunk-FRJEUAAF.js → chunk-DBBZVZOS.js} +968 -2670
  4. package/dist/{chunk-DXCVO6M5.cjs → chunk-GUPV2M3X.cjs} +969 -2680
  5. package/dist/{chunk-POEEDYFM.js → chunk-PCFTJLEP.js} +543 -260
  6. package/dist/{chunk-FI5VIF4M.cjs → chunk-RSHMA4KT.cjs} +442 -22
  7. package/dist/{chunk-3MSFWXQL.cjs → chunk-X4KSS7PP.cjs} +542 -260
  8. package/dist/client/index.cjs +3 -3
  9. package/dist/client/index.d.cts +4 -5
  10. package/dist/client/index.d.ts +4 -5
  11. package/dist/client/index.js +1 -1
  12. package/dist/{include-paths-CL4gHv6I.d.cts → define-content-type-BUZeWtpk.d.cts} +4458 -1312
  13. package/dist/{include-paths-CrJNTsMl.d.ts → define-content-type-DOrZb_a_.d.ts} +4458 -1312
  14. package/dist/define-schema-5aHmsA8j.d.ts +699 -0
  15. package/dist/define-schema-nCfZeboB.d.cts +699 -0
  16. package/dist/index-B97ZDj44.d.ts +507 -0
  17. package/dist/index-C-pcllqY.d.cts +507 -0
  18. package/dist/index-DOhFQbv7.d.ts +3065 -0
  19. package/dist/index-DgVV5Nj7.d.cts +3065 -0
  20. package/dist/index.cjs +114 -147
  21. package/dist/index.d.cts +49 -87
  22. package/dist/index.d.ts +49 -87
  23. package/dist/index.js +5 -29
  24. package/dist/markdown/index.cjs +13750 -0
  25. package/dist/markdown/index.d.cts +111 -0
  26. package/dist/markdown/index.d.ts +111 -0
  27. package/dist/markdown/index.js +13742 -0
  28. package/dist/rich-text/index.cjs +26 -6
  29. package/dist/rich-text/index.d.cts +3 -148
  30. package/dist/rich-text/index.d.ts +3 -148
  31. package/dist/rich-text/index.js +1 -1
  32. package/dist/rich-text.d-BWc-5gX1.d.cts +326 -0
  33. package/dist/rich-text.d-BWc-5gX1.d.ts +326 -0
  34. package/dist/schema/index.cjs +33 -37
  35. package/dist/schema/index.d.cts +37 -191
  36. package/dist/schema/index.d.ts +37 -191
  37. package/dist/schema/index.js +1 -1
  38. package/dist/types/index.d.cts +2 -3
  39. package/dist/types/index.d.ts +2 -3
  40. package/package.json +14 -3
  41. package/dist/define-schema-DgctHlI2.d.cts +0 -1034
  42. package/dist/define-schema-mrEZbY1h.d.ts +0 -1034
  43. package/dist/index-B9RfZVF1.d.ts +0 -861
  44. package/dist/index-BrvEg6-A.d.cts +0 -3729
  45. package/dist/index-Pw0onkJe.d.ts +0 -3729
  46. package/dist/index-b-AkfTUv.d.cts +0 -861
  47. package/dist/rich-text.d-rKmpgdGd.d.cts +0 -200
  48. package/dist/rich-text.d-rKmpgdGd.d.ts +0 -200
@@ -0,0 +1,699 @@
1
+ import { aL as ContentTypeDefinition, aR as SingletonContentTypeDefinition, aW as SettingsGroupDefinition, aC as LocaleDefinition, bw as RoleDefinition, bP as WorkflowDefinition, c5 as ViewDefinition, a$ as AssetTypeDefinition, aN as InferContentType, bz as KeyedRoles, c8 as KeyedViews, ce as CheckedLocales, cf as CheckedRoles, cg as CheckedWorkflow, ch as CheckedSection, ci as KeysDeclared, cj as LocaleCodesOf, ck as StagesDeclared, bA as KeyedRolesAsList, c9 as KeyedViewsAsList } from './define-content-type-DOrZb_a_.js';
2
+
3
+ /**
4
+ * Query definition matching @relyio/schema QueryDefinitionSchema
5
+ *
6
+ * Queries define predefined API endpoints with filtering, sorting, and caching.
7
+ *
8
+ * This is a hand-written mirror: `@relyio/sdk` is published standalone and does not depend on
9
+ * `@relyio/schema`, so a field added there has to be added here too. When the two drifted, `limit`
10
+ * was the casualty — the documentation writes `limit: '${limit?20}'` and this file said `number` —
11
+ * and so were `fullText` and `type`, which a query pulled by `relyio generate-types` carried and
12
+ * this refused. `@relyio/codegen-typescript`'s `src/__tests__/sdk-definition-config.types.ts` now
13
+ * fails to compile when a key, whether it is required, or the values it accepts differs from the
14
+ * schema's, block by block (REL-1457).
15
+ */
16
+ /** One value a query clause compares with. */
17
+ type QueryScalar = string | number | boolean;
18
+ /**
19
+ * A window back or forward from the moment of the read — `{ amount: 7, unit: 'days' }` — which
20
+ * `$inTheLast` and `$inTheNext` take, as a list's `where` takes them.
21
+ */
22
+ type QueryRelativeWindow = {
23
+ amount: number;
24
+ unit: 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
25
+ };
26
+ /**
27
+ * The operators `where` and `filters` compare a field with — `{ price: { $gte: 10 } }` — the
28
+ * `$`-prefixed operators a list's `where` takes, meaning what they mean there (REL-2439).
29
+ *
30
+ * The service's one vocabulary for `where`, `filters` and `having`, which deploy refuses any other
31
+ * key against (REL-1479). The bare form (`{ price: { gte: 10 } }`) is gone: deploy refuses it,
32
+ * saying what to write. A value may be a parameter expression: a list operator takes a list or a
33
+ * parameter that supplies one, a flag a boolean or a parameter. A parameter only ever fills a value;
34
+ * which operators a condition asks is written here, never supplied.
35
+ * `@relyio/codegen-typescript`'s `sdk-definition-config.types.ts` fails to compile when an operator,
36
+ * or what it takes, differs from the schema's.
37
+ */
38
+ type WhereOperator = {
39
+ /** Equal to */
40
+ $eq?: QueryScalar;
41
+ /** Not equal to */
42
+ $ne?: QueryScalar;
43
+ /** Greater than */
44
+ $gt?: QueryScalar;
45
+ /** Greater than or equal to */
46
+ $gte?: QueryScalar;
47
+ /** Less than */
48
+ $lt?: QueryScalar;
49
+ /** Less than or equal to */
50
+ $lte?: QueryScalar;
51
+ /** One of the values given */
52
+ $in?: QueryScalar[] | string;
53
+ /** None of the values given */
54
+ $nin?: QueryScalar[] | string;
55
+ /** Contains the text, ignoring case */
56
+ $contains?: QueryScalar;
57
+ /** Starts with the text, matching case */
58
+ $startsWith?: QueryScalar;
59
+ /** Ends with the text, matching case */
60
+ $endsWith?: QueryScalar;
61
+ /** The field holds a value (true) or does not (false) */
62
+ $exists?: boolean | string;
63
+ /** The value is empty (true) or not (false) */
64
+ $isNull?: boolean | string;
65
+ /** A date within the span back from the moment of the read */
66
+ $inTheLast?: QueryRelativeWindow;
67
+ /** A date within the span forward from the moment of the read */
68
+ $inTheNext?: QueryRelativeWindow;
69
+ };
70
+ /**
71
+ * The operators `having` compares a metric with: the same as `where`'s, each with a literal, since
72
+ * `having` reads the values the aggregate computed and substitutes no parameter. A metric holds no
73
+ * date of an entry's, so neither relative window is taken.
74
+ */
75
+ type HavingOperator = {
76
+ $eq?: QueryScalar;
77
+ $ne?: QueryScalar;
78
+ $gt?: QueryScalar;
79
+ $gte?: QueryScalar;
80
+ $lt?: QueryScalar;
81
+ $lte?: QueryScalar;
82
+ $in?: QueryScalar[];
83
+ $nin?: QueryScalar[];
84
+ $contains?: QueryScalar;
85
+ $startsWith?: QueryScalar;
86
+ $endsWith?: QueryScalar;
87
+ $exists?: boolean;
88
+ $isNull?: boolean;
89
+ $inTheLast?: never;
90
+ $inTheNext?: never;
91
+ };
92
+ type WhereValue = string | number | boolean | (string | number | boolean)[] | WhereOperator;
93
+ type WhereCondition = Record<string, WhereValue>;
94
+ type SortDirection = 'asc' | 'desc';
95
+ type SortCondition = Record<string, SortDirection> | Record<string, SortDirection>[];
96
+ /**
97
+ * A relationship joined by name — a reference the fetched type declares, or a reverse one another
98
+ * type declares to it (`reviews`) — optionally filtered, counted and aliased:
99
+ * `{ relationship: 'products', where: { status: 'active' }, aggregate: 'count', alias: 'productCount' }`.
100
+ * `relationship` is a name, with no parentheses. A `select` reads what it joins.
101
+ */
102
+ type IncludeRelationship = {
103
+ relationship: string;
104
+ where?: WhereCondition;
105
+ /**
106
+ * What the include answers instead of the entries it joins. `count` is the one modifier: `sum`,
107
+ * `avg`, `min` and `max` name no field to reduce — select one, like `products.price.sum` — and
108
+ * the service refuses them (REL-1479).
109
+ */
110
+ aggregate?: 'count';
111
+ /** The name the include answers under; the relationship's name when absent */
112
+ alias?: string;
113
+ };
114
+ /**
115
+ * What a fetch includes (REL-2035). A string is an **include path**, the grammar `?include=` and the
116
+ * SDK's `include()` read: field ids joined by `.`, crossing lists, page builders, objects and
117
+ * references, each hop written out, with the fields to return in parentheses —
118
+ * `'sections.customers.logo'`, `'sections.features(name,slug)'`. The query returns what
119
+ * `GET …?include=` returns for the same paths. A path's entries are expanded after the read, so a
120
+ * `select` cannot read them: join a relationship for that ({@link IncludeRelationship}).
121
+ */
122
+ type IncludeDefinition = string | (string | IncludeRelationship)[];
123
+ type SelectMapping = Record<string, string>;
124
+ /** `filters` are `where` conditions bound at call time: the same operators, written the same way. */
125
+ type FilterOperator = WhereOperator;
126
+ type FilterDefinition = Record<string, string | FilterOperator>;
127
+ /** A value that is either a literal or a `${param}` / `${param?default}` expression. */
128
+ type Parameterizable<T> = T | string;
129
+ type QueryParameterType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
130
+ /**
131
+ * A declared query parameter.
132
+ *
133
+ * Every `${...}` in a query and every `{name}` segment of its endpoint already declares one; this
134
+ * block adds a type and constraints. Nothing is inferred from a parameter's name.
135
+ */
136
+ interface QueryParameter {
137
+ /** The parameter, as it appears in `${...}` or in an endpoint segment */
138
+ name: string;
139
+ /** Coerces the caller's value; a value that will not coerce is a 400 */
140
+ type?: QueryParameterType;
141
+ /** Overrides what the query's own expressions say */
142
+ required?: boolean;
143
+ /** Used when the caller supplies nothing */
144
+ default?: string | number | boolean | (string | number | boolean)[];
145
+ minimum?: number;
146
+ maximum?: number;
147
+ /** String characters, or array items */
148
+ minLength?: number;
149
+ maxLength?: number;
150
+ /** A regular expression, applied to strings */
151
+ pattern?: string;
152
+ enum?: (string | number | boolean)[];
153
+ }
154
+ /** Whether the query answers with one record or a list. Independent of how many rows match. */
155
+ type QueryCardinality = 'one' | 'many';
156
+ type CachePolicyObject = {
157
+ /** Defaults to `public` */
158
+ policy?: 'public' | 'private' | 'no-cache';
159
+ ttl?: number;
160
+ staleWhileRevalidate?: number;
161
+ tags?: string[];
162
+ };
163
+ type CachePolicy = string | CachePolicyObject;
164
+ /** A text search over `fields` the query runs beside its operation block. */
165
+ type FullTextSearch = {
166
+ /** The fields searched; at least one */
167
+ fields: string[];
168
+ /** The search text, usually a parameter expression such as `${q}` */
169
+ query: string;
170
+ highlight?: boolean;
171
+ ranking?: 'simple' | 'complex';
172
+ };
173
+ /**
174
+ * Fetch block - retrieve content entries
175
+ */
176
+ interface FetchBlock {
177
+ /** Content type to fetch */
178
+ contentType?: string;
179
+ /** Singleton to fetch */
180
+ singleton?: string;
181
+ /** Filter conditions */
182
+ where?: WhereCondition;
183
+ /** Related content to include */
184
+ include?: IncludeDefinition;
185
+ /** Sort order */
186
+ sort?: SortCondition;
187
+ /** Maximum results */
188
+ limit?: Parameterizable<number>;
189
+ /** Results offset */
190
+ offset?: Parameterizable<number>;
191
+ }
192
+ /**
193
+ * Aggregate block - perform aggregations
194
+ */
195
+ interface AggregateBlock {
196
+ /** Source content type (required when not used with fetch) */
197
+ source?: string;
198
+ /** Filter conditions */
199
+ where?: WhereCondition;
200
+ /** Group by field(s) */
201
+ by?: string | string[] | (string | {
202
+ expression: string;
203
+ as?: string;
204
+ })[];
205
+ /**
206
+ * What to compute per group, keyed by the name each answers under: `<field>.<fn>`, where `fn` is
207
+ * `count`, `sum`, `avg`, `min`, `max`, `first` or `last` — `{ total: 'amount.sum' }`. Deploy
208
+ * requires it. The one spelling: `aggregations`, which this type called the main one, was a
209
+ * second name deploy refused (REL-1470).
210
+ */
211
+ metrics?: Record<string, string>;
212
+ /** Having clause for filtering aggregations */
213
+ having?: Record<string, QueryScalar | HavingOperator>;
214
+ /** Sort order */
215
+ sort?: SortCondition;
216
+ /** Maximum results */
217
+ limit?: Parameterizable<number>;
218
+ }
219
+ /**
220
+ * Search block - full-text and semantic search
221
+ */
222
+ interface SearchBlock {
223
+ /** Single content type */
224
+ contentType?: string;
225
+ /** Multiple content types or "*" for all */
226
+ contentTypes?: string | string[] | '*';
227
+ /** Search query string */
228
+ query: string;
229
+ /** Fields to search in */
230
+ searchFields?: string[];
231
+ /** Legacy search type */
232
+ searchType?: 'plainto' | 'phraseto' | 'websearch' | 'to_tsquery';
233
+ /** Filter conditions */
234
+ where?: WhereCondition;
235
+ /** Field mapping for results */
236
+ fields?: SelectMapping;
237
+ /** Include relevance score */
238
+ includeRank?: boolean;
239
+ /** Include score breakdown */
240
+ explain?: boolean;
241
+ /** Highlight matching terms */
242
+ highlight?: boolean | {
243
+ field?: string;
244
+ maxWords?: number;
245
+ minWords?: number;
246
+ shortWord?: number;
247
+ };
248
+ /** Sort order */
249
+ sort?: SortCondition;
250
+ /** Maximum results */
251
+ limit?: Parameterizable<number>;
252
+ /** Results offset */
253
+ offset?: Parameterizable<number>;
254
+ }
255
+ /**
256
+ * Include sub-queries for additional data
257
+ */
258
+ interface IncludeSubQuery {
259
+ source: string;
260
+ where?: WhereCondition;
261
+ sort?: SortCondition;
262
+ limit?: Parameterizable<number>;
263
+ select?: SelectMapping;
264
+ }
265
+ type IncludeSubQueries = Record<string, IncludeSubQuery>;
266
+ /**
267
+ * Which operation block a query runs. Inferred from the block it declares when absent.
268
+ *
269
+ * `similar` is not one: deploy refused a query built on it alone and nothing ran it. Similar
270
+ * content is `relyio.similar(uid)` (REL-1470).
271
+ */
272
+ type QueryType = 'fetch' | 'aggregate' | 'search';
273
+ /**
274
+ * Query definition configuration
275
+ */
276
+ interface QueryConfig {
277
+ /** Which operation block the query runs; inferred when absent */
278
+ type?: QueryType;
279
+ /** API endpoint path (required, e.g., /api/featured-products) */
280
+ endpoint: string;
281
+ /** Query description */
282
+ description?: string;
283
+ /** Fetch block for retrieving entries */
284
+ fetch?: FetchBlock;
285
+ /** Aggregate block for aggregations */
286
+ aggregate?: AggregateBlock;
287
+ /** Search block for full-text/semantic search */
288
+ search?: SearchBlock;
289
+ /** Include sub-queries */
290
+ include?: IncludeSubQueries;
291
+ /** Dynamic filter definitions */
292
+ filters?: FilterDefinition;
293
+ /** Full-text search over the fields it names */
294
+ fullText?: FullTextSearch;
295
+ /** Field selection/mapping */
296
+ select?: SelectMapping;
297
+ /** Cache policy */
298
+ cache?: CachePolicy;
299
+ /** Types and constraints for the parameters the query already declares by using them */
300
+ parameters?: QueryParameter[];
301
+ /** Whether the response is the record itself or a list. Defaults to `many` */
302
+ cardinality?: QueryCardinality;
303
+ }
304
+ /** A value a query parameter takes, as the query string carries it to the query. */
305
+ type QueryParameterValue = QueryScalar | readonly QueryScalar[];
306
+ /** What a query whose parameters no type states accepts: any name, any value. */
307
+ type AnyQueryParameters = {
308
+ readonly [name: string]: QueryParameterValue | undefined;
309
+ };
310
+ /** Type only: where a keyed definition keeps the parameters it declares (`InferQueryParams`). */
311
+ declare const parametersAs: unique symbol;
312
+ /**
313
+ * Query definition
314
+ *
315
+ * `TParameters` is what the query accepts, read from the definition as written (REL-2421); a
316
+ * definition typed by nothing more than this interface accepts any.
317
+ */
318
+ interface QueryDefinition<TParameters extends object = AnyQueryParameters> {
319
+ /** Type only: never present at runtime. */
320
+ readonly [parametersAs]?: TParameters;
321
+ readonly _tag: 'query';
322
+ /** Written from its key by `defineSchema` */
323
+ readonly name?: string;
324
+ readonly type?: QueryType;
325
+ readonly endpoint: string;
326
+ readonly description?: string;
327
+ readonly fetch?: FetchBlock;
328
+ readonly aggregate?: AggregateBlock;
329
+ readonly search?: SearchBlock;
330
+ readonly include?: IncludeSubQueries;
331
+ readonly filters?: FilterDefinition;
332
+ readonly fullText?: FullTextSearch;
333
+ readonly select?: SelectMapping;
334
+ readonly cache?: CachePolicy;
335
+ readonly parameters?: QueryParameter[];
336
+ readonly cardinality?: QueryCardinality;
337
+ }
338
+ /**
339
+ * Define a predefined query (REL-1969): it takes no name, because its key under `defineSchema`'s
340
+ * `queries` is its id. Its `where` is the one a list takes, its operators `$`-prefixed (REL-2439).
341
+ *
342
+ * @example
343
+ * defineSchema({
344
+ * contentTypes: { product },
345
+ * queries: {
346
+ * featuredProducts: defineQuery({
347
+ * endpoint: '/api/featured-products',
348
+ * fetch: { contentType: 'product', where: { featured: true }, limit: 10 },
349
+ * }),
350
+ * },
351
+ * })
352
+ *
353
+ * @example
354
+ * // queries: { featuredProducts }
355
+ * const featuredProducts = defineQuery({
356
+ * endpoint: '/api/featured-products',
357
+ * description: 'Get featured products for homepage',
358
+ * fetch: {
359
+ * contentType: 'product',
360
+ * where: {
361
+ * status: 'active',
362
+ * featured: true,
363
+ * },
364
+ * include: ['brand', 'categories'],
365
+ * sort: { publishedAt: 'desc' },
366
+ * limit: 10,
367
+ * },
368
+ * cache: {
369
+ * policy: 'public',
370
+ * ttl: 300,
371
+ * staleWhileRevalidate: 60,
372
+ * }
373
+ * })
374
+ *
375
+ * @example
376
+ * // queries: { searchProducts }
377
+ * const searchProducts = defineQuery({
378
+ * endpoint: '/api/search',
379
+ * description: 'Search products with semantic understanding',
380
+ * search: {
381
+ * contentType: 'product',
382
+ * query: '${q}',
383
+ * where: { status: 'active' },
384
+ * highlight: true,
385
+ * limit: 20,
386
+ * },
387
+ * filters: {
388
+ * 'price.base': { $gte: '${minPrice?0}', $lte: '${maxPrice?}' },
389
+ * category: '${categoryId?}',
390
+ * },
391
+ * cache: 'public 60s',
392
+ * })
393
+ *
394
+ * @example
395
+ * // queries: { productStats }
396
+ * const productStats = defineQuery({
397
+ * endpoint: '/api/products/stats',
398
+ * description: 'Get product statistics by category',
399
+ * aggregate: {
400
+ * source: 'product',
401
+ * where: { status: 'active' },
402
+ * by: ['category'],
403
+ * metrics: {
404
+ * totalProducts: 'id.count',
405
+ * avgPrice: 'price.base.avg',
406
+ * minPrice: 'price.base.min',
407
+ * maxPrice: 'price.base.max',
408
+ * },
409
+ * sort: { totalProducts: 'desc' },
410
+ * },
411
+ * cache: 'public 300s',
412
+ * })
413
+ */
414
+ declare function defineQuery<const TConfig extends QueryConfig>(config: TConfig): QueryDefinition<DeclaredParameters<TConfig>>;
415
+ /**
416
+ * Infer basic response type from a query definition
417
+ * Note: For accurate types, use the codegen tool
418
+ */
419
+ type InferQueryResponse<_T extends QueryDefinition> = unknown[];
420
+ /**
421
+ * The parameters a query accepts, by name (REL-2421): what `client.query(name, { params })` takes.
422
+ *
423
+ * Read from the keyed definition as written, as the API's `declareQueryParameters` reads the
424
+ * deployed one: each `{name}` segment of the endpoint (required — the route cannot match without
425
+ * it), each `${name}` in the definition's values (required) or `${name?…}` (optional), and each
426
+ * entry of `parameters`, whose `type` types the value and whose `required` decides. A name the
427
+ * query does not declare is not a parameter, so it does not compile.
428
+ */
429
+ type InferQueryParams<T extends QueryDefinition<object>> = T extends QueryDefinition<infer P> ? P : AnyQueryParameters;
430
+ /** Every string value in `T`, at any depth — values only: a key is a field path, never a parameter. */
431
+ type StringsIn<T> = T extends string ? T : T extends readonly (infer Item)[] ? StringsIn<Item> : T extends object ? {
432
+ [K in keyof T]-?: StringsIn<T[K]>;
433
+ }[keyof T] : never;
434
+ /** The `${…}` expressions in one string, each as its name and whether it is optional. */
435
+ type ExpressionsIn<S extends string> = S extends `${string}\${${infer Body}}${infer Rest}` ? (Body extends `${infer Name}?${string}` ? {
436
+ readonly name: Name;
437
+ readonly optional: true;
438
+ } : {
439
+ readonly name: Body;
440
+ readonly optional: false;
441
+ }) | ExpressionsIn<Rest> : never;
442
+ /** The `{name}` segments of an endpoint. */
443
+ type EndpointNames<E> = E extends `${string}{${infer Name}}${infer Rest}` ? Name | EndpointNames<Rest> : never;
444
+ /** The expressions of a definition: its values but `parameters` and `description`, as the API scans. */
445
+ type Expressions<C> = ExpressionsIn<StringsIn<Omit<C, 'parameters' | 'description'>>>;
446
+ /** The `parameters` entries a definition declares. */
447
+ type Declared<C> = C extends {
448
+ readonly parameters: readonly (infer Entry)[];
449
+ } ? Entry : never;
450
+ /** What a declared `type` makes a value. */
451
+ type ValueOfType<T> = T extends 'string' ? string : T extends 'number' | 'integer' ? number : T extends 'boolean' ? boolean : T extends 'array' ? readonly QueryScalar[] : T extends 'object' ? never : QueryParameterValue;
452
+ /** What a definition declares, read once: its endpoint's segments, its expressions, its entries. */
453
+ type Declaration<C> = {
454
+ readonly segments: EndpointNames<C extends {
455
+ readonly endpoint: infer E;
456
+ } ? E : never>;
457
+ readonly expressions: Expressions<C>;
458
+ readonly entries: Declared<C>;
459
+ };
460
+ /** What any declaration is. */
461
+ interface AnyDeclaration {
462
+ readonly segments: string;
463
+ readonly expressions: {
464
+ readonly name: string;
465
+ readonly optional: boolean;
466
+ };
467
+ readonly entries: unknown;
468
+ }
469
+ /** Every name a declaration holds. */
470
+ type NamesOf<D extends AnyDeclaration> = D['segments'] | NameOf<D['expressions']> | NameOf<D['entries']>;
471
+ /**
472
+ * The names a union of expressions or entries holds. Distributive on purpose: none is `never`,
473
+ * which a bare `extends` would match and answer the constraint, `string`, for.
474
+ */
475
+ type NameOf<E> = E extends {
476
+ readonly name: infer N extends string;
477
+ } ? N : never;
478
+ /** Whether `Name` is used bare (`${name}`) anywhere — which makes it required. */
479
+ type UsedBare<D extends AnyDeclaration, Name> = [
480
+ Extract<D['expressions'], {
481
+ readonly name: Name;
482
+ readonly optional: false;
483
+ }>
484
+ ] extends [never] ? false : true;
485
+ /** The `parameters` entry naming `Name`, or `never` where none does. */
486
+ type EntryFor<D extends AnyDeclaration, Name> = Extract<D['entries'], {
487
+ readonly name: Name;
488
+ }>;
489
+ /**
490
+ * Whether `Name` is required: an endpoint segment always; else its entry's `required`; else an entry
491
+ * that says nothing about it is required unless some use says it is optional and none is bare; else
492
+ * any bare use. No entry is asked about first: `never` matches every shape.
493
+ */
494
+ type IsRequired<D extends AnyDeclaration, Name> = [Name] extends [D['segments']] ? true : [EntryFor<D, Name>] extends [never] ? UsedBare<D, Name> : [EntryFor<D, Name>] extends [{
495
+ readonly required: infer R extends boolean;
496
+ }] ? R : [Extract<D['expressions'], {
497
+ readonly name: Name;
498
+ }>] extends [never] ? true : UsedBare<D, Name>;
499
+ /** The value `Name` takes: its entry's declared `type`, else any value a parameter takes. */
500
+ type ParameterValue<D extends AnyDeclaration, Name> = [EntryFor<D, Name>] extends [never] ? QueryParameterValue : [EntryFor<D, Name>] extends [{
501
+ readonly type: infer T;
502
+ }] ? ValueOfType<T> : QueryParameterValue;
503
+ type Simplify<T> = {
504
+ [K in keyof T]: T[K];
505
+ } & {};
506
+ /** The parameters a keyed definition declares: required ones required, the rest optional. */
507
+ type DeclaredParameters<C> = ParametersOf<Declaration<C>>;
508
+ type ParametersOf<D extends AnyDeclaration> = Simplify<{
509
+ readonly [Name in NamesOf<D> as IsRequired<D, Name> extends true ? Name : never]: ParameterValue<D, Name>;
510
+ } & {
511
+ readonly [Name in NamesOf<D> as IsRequired<D, Name> extends true ? never : Name]?: ParameterValue<D, Name>;
512
+ }>;
513
+
514
+ /**
515
+ * Schema definition matching @relyio/schema SchemaDefinitionSchema
516
+ *
517
+ * Note: `version` is NOT user-defined - it's auto-generated by the backend.
518
+ */
519
+
520
+ /**
521
+ * Schema configuration
522
+ *
523
+ * Matches the SchemaDefinitionSchema from @relyio/schema:
524
+ * - locales: Optional array of locale definitions for multi-language support
525
+ * - contentTypes: Required record of content type definitions
526
+ * - singletonContentTypes: Required record of singleton definitions (can be empty {})
527
+ * - queries: Required record of query definitions (can be empty {})
528
+ * - settingsGroups: Optional record of settings groups
529
+ * - roles: Optional record of custom roles, each keyed by its id
530
+ * - workflow: Optional workflow configuration with approval stages
531
+ *
532
+ * Note: `version` is auto-generated by the backend, not user-defined!
533
+ */
534
+ interface SchemaConfig {
535
+ /** Locale definitions for multi-language support (optional) */
536
+ locales?: LocaleDefinition[];
537
+ /** Content type definitions (required) */
538
+ contentTypes: Record<string, ContentTypeDefinition>;
539
+ /** Singleton content type definitions (required, can be empty) */
540
+ singletonContentTypes?: Record<string, SingletonContentTypeDefinition>;
541
+ /** Predefined query definitions (required, can be empty) */
542
+ queries?: Record<string, QueryDefinition>;
543
+ /** Settings group definitions (optional) */
544
+ settingsGroups?: Record<string, SettingsGroupDefinition>;
545
+ /** Asset type definitions (optional) */
546
+ assetTypes?: Record<string, AssetTypeDefinition>;
547
+ /** Custom roles for fine-grained access control, each under its id (optional) */
548
+ roles?: KeyedRoles;
549
+ /** Global workflow configuration with approval stages (optional) */
550
+ workflow?: WorkflowDefinition;
551
+ /** Pre-configured entry list views, each under its id (optional) */
552
+ views?: KeyedViews;
553
+ }
554
+ /**
555
+ * Complete schema definition - Generic version for type inference
556
+ */
557
+ interface SchemaDefinition<TContentTypes extends Record<string, ContentTypeDefinition> = Record<string, ContentTypeDefinition>, TSingletons extends Record<string, SingletonContentTypeDefinition> = Record<string, SingletonContentTypeDefinition>, TQueries extends Record<string, QueryDefinition> = Record<string, QueryDefinition>, TSettings extends Record<string, SettingsGroupDefinition> = Record<string, SettingsGroupDefinition>, TLocales extends readonly LocaleDefinition[] = readonly LocaleDefinition[], TRoles extends readonly RoleDefinition[] = readonly RoleDefinition[], TWorkflow extends WorkflowDefinition | undefined = WorkflowDefinition | undefined, TViews extends readonly ViewDefinition[] = readonly ViewDefinition[], TAssets extends Record<string, AssetTypeDefinition> = Record<string, AssetTypeDefinition>> {
558
+ readonly _tag: 'schema';
559
+ readonly locales?: TLocales;
560
+ readonly contentTypes: TContentTypes;
561
+ readonly singletonContentTypes: TSingletons;
562
+ readonly queries: TQueries;
563
+ readonly settingsGroups?: TSettings;
564
+ readonly assetTypes?: TAssets;
565
+ readonly roles?: TRoles;
566
+ readonly workflow?: TWorkflow;
567
+ readonly views?: TViews;
568
+ }
569
+ /**
570
+ * Typed schema config for type inference
571
+ */
572
+ interface TypedSchemaConfig<TContentTypes extends Record<string, ContentTypeDefinition>, TSingletons extends Record<string, SingletonContentTypeDefinition>, TQueries extends Record<string, QueryDefinition>, TSettings extends Record<string, SettingsGroupDefinition>, TLocales extends readonly LocaleDefinition[] = readonly LocaleDefinition[], TRoles extends KeyedRoles = KeyedRoles, TWorkflow extends WorkflowDefinition | undefined = WorkflowDefinition | undefined, TViews extends KeyedViews = KeyedViews, TAssets extends Record<string, AssetTypeDefinition> = Record<string, AssetTypeDefinition>> {
573
+ locales?: TLocales;
574
+ contentTypes: TContentTypes;
575
+ singletonContentTypes?: TSingletons;
576
+ queries?: TQueries;
577
+ settingsGroups?: TSettings;
578
+ assetTypes?: TAssets;
579
+ roles?: TRoles;
580
+ workflow?: TWorkflow;
581
+ views?: TViews;
582
+ }
583
+ /**
584
+ * Define a complete schema
585
+ *
586
+ * This creates a schema definition that can be:
587
+ * 1. Deployed via the CLI
588
+ * 2. Used for type inference in the SDK client
589
+ *
590
+ * @example
591
+ * import { defineSchema, defineContentType, defineLocale, fields, fieldset } from '@relyio/sdk/schema'
592
+ *
593
+ * const enUS = defineLocale('en-US', { displayName: 'English (US)', default: true })
594
+ * const esES = defineLocale('es-ES', { displayName: 'Spanish', fallback: ['en-US'] })
595
+ *
596
+ * const product = defineContentType({
597
+ * fields: {
598
+ * title: fields.shortText({ required: true, localized: true }),
599
+ * price: fields.decimal({ min: 0, decimalPlaces: 2 }),
600
+ * // One value of a fieldset: `{ _type: 'seo', _key, metaTitle?, metaDescription? }`
601
+ * seo: fields.object({
602
+ * of: fieldset('seo', {
603
+ * displayName: 'SEO metadata',
604
+ * fields: {
605
+ * metaTitle: fields.shortText({ maxLength: 60 }),
606
+ * metaDescription: fields.longText({ maxLength: 160 }),
607
+ * },
608
+ * }),
609
+ * }),
610
+ * },
611
+ * })
612
+ *
613
+ * export const schema = defineSchema({
614
+ * locales: [enUS, esES],
615
+ * contentTypes: { product },
616
+ * })
617
+ */
618
+ declare function defineSchema<TContentTypes extends Record<string, ContentTypeDefinition>, TSingletons extends Record<string, SingletonContentTypeDefinition> = Record<string, never>, TQueries extends Record<string, QueryDefinition> = Record<string, never>, TSettings extends Record<string, SettingsGroupDefinition> = Record<string, never>, TLocales extends readonly LocaleDefinition[] = readonly never[], TRoles extends KeyedRoles = Record<never, never>, TWorkflow extends WorkflowDefinition | undefined = undefined, TViews extends KeyedViews = Record<never, never>, TAssets extends Record<string, AssetTypeDefinition> = Record<string, never>>(config: TypedSchemaConfig<TContentTypes, TSingletons, TQueries, TSettings, TLocales, TRoles, TWorkflow, TViews, TAssets> & NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TLocales, TRoles, TWorkflow>): SchemaDefinition<TContentTypes, TSingletons, TQueries, TSettings, TLocales, RolesAsList<TRoles>, TWorkflow, ViewsAsList<TViews>, TAssets>;
619
+ /**
620
+ * What `defineSchema` holds a schema's names to (REL-2416): each section of types against what the
621
+ * schema declares — a reference's `to` and rich text's `links.to` against its content, singleton and
622
+ * asset type keys (a reference may point at a singleton: `@relyio/schema`'s
623
+ * `ResolvedReferenceTarget`), and a Field's `requiredLocales` against its locale codes; its locales'
624
+ * `fallback` against their codes; the roles its workflow's stages name, and its roles' `includes`,
625
+ * against the built-in roles and its role keys; and a type's stages against its workflow's stage
626
+ * keys. Types only; `./checked-names.ts` says how.
627
+ */
628
+ type NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TLocales, TRoles, TWorkflow> = {
629
+ readonly locales?: CheckedLocales<TLocales>;
630
+ readonly roles?: CheckedRoles<TRoles>;
631
+ readonly workflow?: CheckedWorkflow<TWorkflow, TRoles>;
632
+ readonly contentTypes: CheckedSection<TContentTypes, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
633
+ readonly singletonContentTypes?: CheckedSection<TSingletons, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
634
+ readonly settingsGroups?: CheckedSection<TSettings, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
635
+ readonly assetTypes?: CheckedSection<TAssets, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
636
+ };
637
+ /** The names a schema declares, for its sections' names to be checked against. */
638
+ interface DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow> {
639
+ readonly targets: KeysDeclared<TContentTypes> | KeysDeclared<TSingletons> | KeysDeclared<TAssets>;
640
+ readonly locales: LocaleCodesOf<TLocales>;
641
+ readonly stages: StagesDeclared<TWorkflow>;
642
+ }
643
+ /**
644
+ * The roles `defineSchema` returns for the keyed record it was given: the list it compiles to, each
645
+ * role carrying its key as a literal `id` (REL-2414).
646
+ */
647
+ type RolesAsList<R extends KeyedRoles> = KeyedRolesAsList<R>;
648
+ /** The views `defineSchema` returns for the ones it was given, as {@link RolesAsList} says of roles. */
649
+ type ViewsAsList<V extends KeyedViews> = KeyedViewsAsList<V>;
650
+ /**
651
+ * Type alias for any schema definition.
652
+ * Uses `any` intentionally for type inference utilities that need to accept any schema.
653
+ */
654
+ type AnySchemaDefinition = SchemaDefinition<any, any, any, any, any, any, any, any, any>;
655
+ /**
656
+ * Get content type names from a schema
657
+ */
658
+ type SchemaContentTypeNames<T extends AnySchemaDefinition> = keyof T['contentTypes'] & string;
659
+ /**
660
+ * An entry of content type `K`, typed by schema `T` as a read returns it — what `content(K)` reads,
661
+ * with references resolved against `T` (`INV-SS-TYPES-INFERRED`).
662
+ */
663
+ type SchemaEntry<T extends AnySchemaDefinition, K extends SchemaContentTypeNames<T>> = InferContentType<T['contentTypes'][K], T>;
664
+ /**
665
+ * An entry of any one of the content types `K` names — every content type by default — as a search
666
+ * across them returns it: a union, so `_metadata.type` tells a caller which it holds.
667
+ */
668
+ type SchemaEntryOf<T extends AnySchemaDefinition, K extends SchemaContentTypeNames<T> = SchemaContentTypeNames<T>> = {
669
+ [N in K]: SchemaEntry<T, N>;
670
+ }[K];
671
+ /**
672
+ * Get singleton names from a schema
673
+ */
674
+ type SchemaSingletonNames<T extends AnySchemaDefinition> = keyof T['singletonContentTypes'] & string;
675
+ /**
676
+ * Get query names from a schema
677
+ */
678
+ type SchemaQueryNames<T extends AnySchemaDefinition> = keyof T['queries'] & string;
679
+ /**
680
+ * Get settings group names from a schema.
681
+ *
682
+ * `settingsGroups`, `assetTypes` and `locales` are optional members of `SchemaDefinition`, so
683
+ * indexing one yields `X | undefined`, which never extends the record — every typed client's
684
+ * `settings()`, `asset()` and `with({ locale })` took `never`. The three read through `NonNullable`.
685
+ */
686
+ type SchemaSettingsGroupNames<T extends AnySchemaDefinition> = NonNullable<T['settingsGroups']> extends Record<string, SettingsGroupDefinition> ? keyof NonNullable<T['settingsGroups']> & string : never;
687
+ /**
688
+ * Get asset type names from a schema
689
+ */
690
+ type SchemaAssetTypeNames<T extends AnySchemaDefinition> = NonNullable<T['assetTypes']> extends Record<string, AssetTypeDefinition> ? keyof NonNullable<T['assetTypes']> & string : never;
691
+ /**
692
+ * Get locale codes from a schema: the codes its locales declare, or `string` for a schema that
693
+ * declares none. `defineSchema` now types an absent `locales` as an empty list, so that a Field's
694
+ * `requiredLocales` is checked against no locale (REL-2416); a read's locale keeps what it took
695
+ * before — any code — until the read options check it (REL-2417).
696
+ */
697
+ type SchemaLocaleCodes<T extends AnySchemaDefinition> = NonNullable<T['locales']> extends readonly LocaleDefinition[] ? [NonNullable<T['locales']>[number]] extends [never] ? string : NonNullable<T['locales']>[number]['code'] : never;
698
+
699
+ export { type AggregateBlock as A, type QueryParameter as B, type CachePolicy as C, type QueryParameterType as D, type QueryCardinality as E, type FullTextSearch as F, type InferQueryResponse as G, type HavingOperator as H, type IncludeDefinition as I, type InferQueryParams as J, type QueryParameterValue as K, type AnyQueryParameters as L, type DeclaredParameters as M, type Parameterizable as P, type QueryConfig as Q, type RolesAsList as R, type SchemaConfig as S, type ViewsAsList as V, type WhereCondition as W, type SchemaDefinition as a, type SchemaContentTypeNames as b, type SchemaSingletonNames as c, defineSchema as d, type SchemaQueryNames as e, type SchemaLocaleCodes as f, type SchemaSettingsGroupNames as g, type SchemaAssetTypeNames as h, type SchemaEntry as i, type SchemaEntryOf as j, defineQuery as k, type QueryDefinition as l, type QueryType as m, type FetchBlock as n, type SearchBlock as o, type WhereValue as p, type WhereOperator as q, type QueryScalar as r, type SortCondition as s, type SortDirection as t, type IncludeRelationship as u, type SelectMapping as v, type FilterDefinition as w, type CachePolicyObject as x, type IncludeSubQuery as y, type IncludeSubQueries as z };