@relyio/sdk 0.17.0 → 0.19.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 (74) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/automations/index.cjs +71 -0
  3. package/dist/automations/index.d.cts +1590 -0
  4. package/dist/automations/index.d.ts +1590 -0
  5. package/dist/automations/index.js +6 -0
  6. package/dist/{chunk-RSHMA4KT.cjs → chunk-2SPPU2WG.cjs} +68 -68
  7. package/dist/{chunk-VS2DEUTN.js → chunk-356SF5Y2.js} +463 -26
  8. package/dist/chunk-5F3YYPLZ.cjs +19237 -0
  9. package/dist/chunk-7I3SC7SV.cjs +40 -0
  10. package/dist/chunk-DBYMG6MQ.cjs +535 -0
  11. package/dist/chunk-DI6KFDBO.js +43 -0
  12. package/dist/chunk-HDHBYYEY.js +36 -0
  13. package/dist/chunk-L6DXCKVQ.cjs +50 -0
  14. package/dist/{chunk-TZL374LS.cjs → chunk-M7MWNV3Q.cjs} +21 -21
  15. package/dist/{chunk-H6IBQSMM.js → chunk-NJQK5STK.js} +3 -3
  16. package/dist/chunk-NN45CSPZ.cjs +872 -0
  17. package/dist/{chunk-6E22GYPB.cjs → chunk-P23G5NXD.cjs} +781 -337
  18. package/dist/chunk-PZCDJFMA.js +19195 -0
  19. package/dist/chunk-T7LGREB3.js +848 -0
  20. package/dist/{chunk-BBUB7C2Z.js → chunk-W2A4OTCI.js} +3 -3
  21. package/dist/chunk-W2GRVXDG.js +520 -0
  22. package/dist/{chunk-5UMY6CS4.js → chunk-ZAKEY6DY.js} +3 -3
  23. package/dist/{chunk-LSRPMNPT.cjs → chunk-ZO6QDYJG.cjs} +7 -7
  24. package/dist/client/index.cjs +8 -7
  25. package/dist/client/index.d.cts +4 -3
  26. package/dist/client/index.d.ts +4 -3
  27. package/dist/client/index.js +6 -5
  28. package/dist/{define-content-type-AuL9-oz6.d.cts → define-content-type-BZ6X8GvL.d.cts} +4547 -842
  29. package/dist/{define-content-type-BGoQxqLf.d.ts → define-content-type-C12jh8cY.d.ts} +4547 -842
  30. package/dist/{define-schema-DgCX9YB7.d.ts → define-schema-BPlZl4a2.d.cts} +258 -10
  31. package/dist/{define-schema-DkXwpp0I.d.cts → define-schema-CK7TtYot.d.ts} +258 -10
  32. package/dist/dev-handshake/index.cjs +9 -9
  33. package/dist/dev-handshake/index.js +2 -2
  34. package/dist/extensions/index.cjs +100 -0
  35. package/dist/extensions/index.d.cts +6 -0
  36. package/dist/extensions/index.d.ts +6 -0
  37. package/dist/extensions/index.js +96 -0
  38. package/dist/functions/index.cjs +71 -0
  39. package/dist/functions/index.d.cts +6 -0
  40. package/dist/functions/index.d.ts +6 -0
  41. package/dist/functions/index.js +62 -0
  42. package/dist/{index-BBp8_tn9.d.ts → index-BxNnlc5D.d.ts} +167 -494
  43. package/dist/{index-DaMZ4FQ_.d.ts → index-C-MymZTe.d.ts} +1 -1
  44. package/dist/{index-DxRmKPrR.d.cts → index-D5jyIeQ5.d.cts} +167 -494
  45. package/dist/{index-Bp4AiNT3.d.cts → index-DN0l8RHw.d.cts} +1 -1
  46. package/dist/index.cjs +208 -185
  47. package/dist/index.d.cts +147 -17
  48. package/dist/index.d.ts +147 -17
  49. package/dist/index.js +11 -16
  50. package/dist/markdown/index.cjs +382 -382
  51. package/dist/markdown/index.js +1 -1
  52. package/dist/preview/index.cjs +11 -10
  53. package/dist/preview/index.js +3 -2
  54. package/dist/register-BiMQKVp-.d.ts +693 -0
  55. package/dist/register-DeMsaurp.d.cts +693 -0
  56. package/dist/rich-text/index.cjs +12 -12
  57. package/dist/rich-text/index.d.cts +2 -2
  58. package/dist/rich-text/index.d.ts +2 -2
  59. package/dist/rich-text/index.js +2 -2
  60. package/dist/schema/index.cjs +63 -34
  61. package/dist/schema/index.d.cts +14 -5
  62. package/dist/schema/index.d.ts +14 -5
  63. package/dist/schema/index.js +3 -2
  64. package/dist/types/index.d.cts +1 -1
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/index.cjs +20 -20
  67. package/dist/utils/index.js +2 -2
  68. package/package.json +23 -5
  69. package/dist/chunk-6PTRZP5U.cjs +0 -433
  70. package/dist/chunk-DIZY6CKM.js +0 -950
  71. package/dist/chunk-GHYB6IZK.cjs +0 -983
  72. package/dist/chunk-MWMSFIWN.cjs +0 -17
  73. package/dist/chunk-OVMIHAYK.js +0 -411
  74. package/dist/chunk-XQ4QHWZE.js +0 -13
@@ -1,4 +1,240 @@
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-BGoQxqLf.js';
1
+ import { cK as ConditionTree, aS as FieldMember, A as AIConfig, an as FieldValues, ao as DeclaredFields, cR as components, cy as RecordFile, cx as FileUpload, r as KeyedMembers, cS as DisplayFieldOf, s as KeyedMembersOf, aV as ContentTypeDefinition, a$ as SingletonContentTypeDefinition, b4 as SettingsGroupDefinition, aL as LocaleDefinition, bP as RoleDefinition, c6 as WorkflowDefinition, co as ViewDefinition, b9 as AssetTypeDefinition, aX as InferContentType, bS as KeyedRoles, cr as KeyedViews, cT as CheckedLocales, cU as CheckedRoles, cV as CheckedWorkflow, cW as CheckedSection, cX as KeysDeclared, cY as ContributedRecordType, cZ as LocaleCodesOf, c_ as StagesDeclared, bT as KeyedRolesAsList, cs as KeyedViewsAsList } from './define-content-type-BZ6X8GvL.cjs';
2
+
3
+ /**
4
+ * A Record type's End-user Policies (spec 4, REL-3883, ADR 0027): what the End users of a
5
+ * customer's app — and anonymous visitors — may do with the type's Records, action by action.
6
+ *
7
+ * A rule is one of three names or a condition:
8
+ *
9
+ * - `'owner'` — the End user the Record's Owner field names, and no one else. The type must declare
10
+ * an Owner field (`fields.owner()`), and a visitor with no token is never one.
11
+ * - `'signedIn'` — any End user, whoever owns the Record; never a visitor.
12
+ * - `'anyone'` — every End user and every visitor.
13
+ * - a condition tree (`@relyio/schema/lists`) over three roots: `record.*` — the Record's own
14
+ * fields, compiled against the stored Records — and the two the asker supplies, `owner` (the End
15
+ * user's subject, absent for a visitor, so `owner.exists()` is "signed in") and `claims.*` (what
16
+ * their token claims). A condition holds of anyone it admits, a visitor included.
17
+ *
18
+ * An action with no rule gives End users and visitors nothing of the type: a type that declares no
19
+ * `endUsers` is closed to them, so adding a Record type never exposes it by accident. A write
20
+ * (`create`, `update`, `delete`) is a rule too, or for `create` and `update` `{ when, fields }`:
21
+ * who may, and which fields they may set (REL-3885 declares the shape and its deploy refusals,
22
+ * {@link endUserPolicyFaults}; REL-3884 enforces it). Every backend reads the declaration through the
23
+ * `endUserPolicies` projection, never from here.
24
+ */
25
+
26
+ /** The rules a Policy may name rather than spell as a condition. */
27
+ declare const NAMED_POLICY_RULES: readonly ['owner', 'signedIn', 'anyone'];
28
+ type NamedPolicyRule = (typeof NAMED_POLICY_RULES)[number];
29
+ /** One action's rule: a name, or a condition over the Record and the asker. */
30
+ type PolicyRule = NamedPolicyRule | ConditionTree;
31
+ /** A write rule naming the fields an End user may set: who may (`when`), and which (`fields`). */
32
+ interface FieldsWriteRule {
33
+ readonly when: PolicyRule;
34
+ readonly fields: readonly string[];
35
+ }
36
+ /**
37
+ * A `create` or `update` rule: a rule alone — the End users it admits set any field an End user may
38
+ * set — or `{ when, fields }`, naming the fields.
39
+ */
40
+ type WriteRule = PolicyRule | FieldsWriteRule;
41
+ /**
42
+ * What a Record type does with an End user's Records when the identity source reports them deleted
43
+ * (spec 4): `keep` them, or `delete` them through the pipeline. Only a type with an owner field.
44
+ */
45
+ declare const OWNER_DELETED_ACTIONS: readonly ['keep', 'delete'];
46
+ type OwnerDeletedAction = (typeof OWNER_DELETED_ACTIONS)[number];
47
+
48
+ /**
49
+ * Record type definition matching @relyio/schema RecordTypeSchema (spec 1, ADR 0023)
50
+ *
51
+ * A Record is the data an app writes while it runs — an order, a stock level, a review, a cart —
52
+ * declared in the schema beside the content types and deployed with them. It is live the moment it
53
+ * is written: no drafts, no publication, no locales, no version history. So a Record type is a
54
+ * content type's shape without the editorial half: no `workflow`, no `hierarchical`, and its fields
55
+ * take every kind but `slug` and are never `localized` (deploy refuses both:
56
+ * `RECORD_TYPE_SLUG_FIELD`, `RECORD_TYPE_LOCALIZED_FIELD`).
57
+ *
58
+ * A Record type's references point outward: at content types, asset types and other Record types.
59
+ * An entry never references a Record — a content type whose reference names a Record type fails to
60
+ * compile under `defineSchema`, and deploy refuses it (`REFERENCE_TO_RECORD_TYPE`).
61
+ */
62
+
63
+ /**
64
+ * A Record type's configuration in the keyed form (REL-1969), as a content type's: its key under
65
+ * `defineSchema({ recordTypes })` is its id — one namespace with every content, singleton, settings
66
+ * group and asset type id — and `fields` a record keyed by Field id. `displayName` is derived from
67
+ * the key when left out.
68
+ */
69
+ interface KeyedRecordTypeConfig<R extends KeyedMembers = KeyedMembers> {
70
+ /** Display name shown in the UI. Derived from the type's key when left out: `orderLine` → "Order line" */
71
+ displayName?: string;
72
+ /** Plural display name shown in the UI (e.g., "Orders" for "Order"); not derived */
73
+ displayNamePlural?: string;
74
+ /** Description of the Record type */
75
+ description?: string;
76
+ /** AI configuration: guidance for agents reading these Records */
77
+ ai?: AIConfig;
78
+ /** Access tags for role-based access control */
79
+ accessTags?: string[];
80
+ /** The Field a Record's title is in lists and references: one of this type's own (REL-2416) */
81
+ displayField?: DisplayFieldOf<R>;
82
+ /**
83
+ * Sets of this type's own Fields no two Records hold the same values of in one Dataset (REL-3782):
84
+ * `[['product', 'author']]` keeps one review per product per author. One Field alone says it with
85
+ * `unique: true` in its own config. A Record writing values another holds is refused, naming the
86
+ * set and the Record holding them.
87
+ */
88
+ unique?: ReadonlyArray<ReadonlyArray<DisplayFieldOf<R>>>;
89
+ /**
90
+ * How long each Record lives after its last write, in whole hours or days — `'36h'`, `'7d'`
91
+ * (REL-3775). Every write moves the deadline on, so an active Record never expires; past it, the
92
+ * Record is deleted as a delete would delete it. Left out, a Record lives until it is deleted.
93
+ */
94
+ expireAfter?: RecordExpiry;
95
+ /**
96
+ * What the End users of your app — and anonymous visitors with your publishable key — may do with
97
+ * this type's Records (spec 4, REL-3883). Left out, they read nothing of it: your server reads
98
+ * every Record with a secret key, as it always did.
99
+ *
100
+ * @example
101
+ * endUsers: { read: 'owner' } // each End user lists and gets only the Records they own
102
+ * endUsers: { read: conditionRoot('record').status.eq('visible') } // anyone, visible ones only
103
+ * endUsers: { update: { when: 'owner', fields: ['note'] } } // an owner changes the note alone
104
+ */
105
+ endUsers?: RecordTypeEndUsers<DisplayFieldOf<R>>;
106
+ /**
107
+ * What becomes of an End user's Records when your identity source reports them deleted — Clerk's
108
+ * `user.deleted` (spec 4): `'keep'` them, or `'delete'` them. Only a type with `fields.owner()`.
109
+ */
110
+ onOwnerDeleted?: OwnerDeletedAction;
111
+ /** Each Field under its id, in the order the form shows them */
112
+ fields: R;
113
+ }
114
+ /**
115
+ * A Record type's End-user Policies (spec 4, REL-3883), action by action. A rule is `'owner'` — the
116
+ * End user the type's `fields.owner()` names; `'signedIn'` — any End user; `'anyone'` — every End
117
+ * user and visitor; or a condition over `record.*` (the Record's fields), `owner` (the End user's
118
+ * subject, absent for a visitor) and `claims.*` (what their token claims), built with
119
+ * `conditionRoot`, `and`, `or` and `not`.
120
+ */
121
+ interface RecordTypeEndUsers<F extends string = string> {
122
+ /** Who may list, count, facet and get the Records. Left out, End users and visitors may not. */
123
+ readonly read?: PolicyRule;
124
+ /**
125
+ * Who may create a Record — a rule, or `{ when, fields }` naming the fields they may set, each one
126
+ * of this type's own. Never `'anyone'`, and never an owner, sequence, counter or Private field in
127
+ * `fields`. Left out, End users create none. RelyIO sets the owner from the End user's token.
128
+ */
129
+ readonly create?: RecordWriteRule<F>;
130
+ /** Who may update a Record, asked of it as stored, as `create`. Left out, End users update none. */
131
+ readonly update?: RecordWriteRule<F>;
132
+ /** Who may delete a Record, asked of it as stored. Never `'anyone'`. Left out, none. */
133
+ readonly delete?: PolicyRule;
134
+ /**
135
+ * How many writes a minute one End user makes to the type (REL-3884): 60 when left out. Over it,
136
+ * a write is refused `RATE_LIMIT_EXCEEDED` with `Retry-After`, before anything is written.
137
+ */
138
+ readonly perUser?: {
139
+ readonly writesPerMinute: number;
140
+ };
141
+ }
142
+ /**
143
+ * A `create` or `update` rule whose `fields` name this type's own Fields (REL-3884): the schema's
144
+ * `WriteRule`, checked as you type.
145
+ */
146
+ type RecordWriteRule<F extends string = string> = PolicyRule | {
147
+ readonly when: PolicyRule;
148
+ readonly fields: readonly F[];
149
+ };
150
+ /** A whole number of hours or days: `'36h'`, `'7d'`. Deploy refuses any other form. */
151
+ type RecordExpiry = `${number}h` | `${number}d`;
152
+ /**
153
+ * Record type definition - preserves field types for inference
154
+ */
155
+ interface RecordTypeDefinition<TFields extends readonly FieldMember[] = readonly FieldMember[]> {
156
+ readonly _tag: 'recordType';
157
+ /** Absent until `defineSchema` writes the type's key here; deploy takes the key either way. */
158
+ readonly name?: string;
159
+ /** Absent in the keyed form until `defineSchema` derives it from the type's key */
160
+ readonly displayName?: string;
161
+ readonly displayNamePlural?: string;
162
+ readonly description?: string;
163
+ /** AI configuration: guidance for agents reading these Records */
164
+ readonly ai?: AIConfig;
165
+ /** Field ID to use as a Record's display title */
166
+ readonly displayField?: string;
167
+ readonly accessTags?: string[];
168
+ /** Sets of Fields no two Records hold the same values of in one Dataset (REL-3782) */
169
+ readonly unique?: string[][];
170
+ /** How long each Record lives after its last write (REL-3775) */
171
+ readonly expireAfter?: RecordExpiry;
172
+ /** What End users and visitors may do with the Records (REL-3883) */
173
+ readonly endUsers?: RecordTypeEndUsers;
174
+ /** What becomes of an End user's Records when they are deleted (spec 4) */
175
+ readonly onOwnerDeleted?: OwnerDeletedAction;
176
+ readonly fields: TFields;
177
+ }
178
+ /**
179
+ * Define a Record type: the shape of the data an app writes while it runs.
180
+ *
181
+ * @example
182
+ * export const inventory = defineRecordType({
183
+ * fields: {
184
+ * product: fields.reference({ required: true, to: 'product' }),
185
+ * stock: fields.integer({ required: true, min: 0 }),
186
+ * },
187
+ * })
188
+ * // Under its key in defineSchema: recordTypes: { inventory }
189
+ */
190
+ declare function defineRecordType<R extends KeyedMembers>(config: KeyedRecordTypeConfig<R>): RecordTypeDefinition<readonly KeyedMembersOf<R>[]>;
191
+ /**
192
+ * Type alias for any Record type definition.
193
+ */
194
+ type AnyRecordTypeDefinition = RecordTypeDefinition<any>;
195
+ /**
196
+ * A Record's values as its Record type declares them (REL-3771): a required field always present,
197
+ * every other one optional, each typed as a read returns it. What `records(type).create` takes.
198
+ */
199
+ type RecordFieldsOf<T extends AnyRecordTypeDefinition> = FieldValues<DeclaredFields<T>>;
200
+ /**
201
+ * A Record's values as a write takes them (REL-3781, REL-3824): {@link RecordFieldsOf} without its
202
+ * Sequences, which RelyIO numbers and a create or an update that sets one is refused — and a File
203
+ * as the upload holding its bytes (`FileUpload`), never the address only a read answers. What
204
+ * `records(type).create` and `update` take.
205
+ */
206
+ type RecordWriteFieldsOf<T extends AnyRecordTypeDefinition> = {
207
+ [K in keyof Omit<RecordFieldsOf<T>, SequenceIdsOf<T>>]: WrittenAs<RecordFieldsOf<T>[K]>;
208
+ };
209
+ /**
210
+ * A Record's values as an update takes them (REL-3774, REL-3765): {@link RecordWriteFieldsOf}
211
+ * without its Counters — a create starts one, and after that it moves only by `increment` and
212
+ * `decrement`, applied in the write itself; a value an update set would overwrite a move made since
213
+ * the read, and the server refuses it (`COUNTER_USE_INCREMENT_OR_DECREMENT`). What
214
+ * `records(type).update` takes.
215
+ */
216
+ type RecordUpdateFieldsOf<T extends AnyRecordTypeDefinition> = Omit<RecordWriteFieldsOf<T>, CounterIdsOf<T>>;
217
+ /** The ids of a Record type's Counter fields. */
218
+ type CounterIdsOf<T extends AnyRecordTypeDefinition> = Extract<DeclaredFields<T>, {
219
+ readonly type: 'counter';
220
+ }>['id'];
221
+ /** A value as a write sends it: a File as its upload, every other value as a read answers it. */
222
+ type WrittenAs<V> = V extends RecordFile ? FileUpload : V;
223
+ /** The ids of a Record type's Sequence fields. */
224
+ type SequenceIdsOf<T extends AnyRecordTypeDefinition> = Extract<DeclaredFields<T>, {
225
+ readonly type: 'sequence';
226
+ }>['id'];
227
+ /**
228
+ * A Record as a read answers it: its fields, and `_metadata` — the document's `RecordMetadata`, no
229
+ * locale, publication or version (REL-3771).
230
+ *
231
+ * @example
232
+ * type Order = InferRecordType<typeof order>
233
+ * // { shopperEmail: string; total: number; …; _metadata: RecordMetadata }
234
+ */
235
+ type InferRecordType<T extends AnyRecordTypeDefinition> = RecordFieldsOf<T> & {
236
+ _metadata: components['schemas']['RecordMetadata'];
237
+ };
2
238
 
3
239
  /**
4
240
  * Query definition matching @relyio/schema QueryDefinitionSchema
@@ -544,6 +780,8 @@ interface SchemaConfig {
544
780
  settingsGroups?: Record<string, SettingsGroupDefinition>;
545
781
  /** Asset type definitions (optional) */
546
782
  assetTypes?: Record<string, AssetTypeDefinition>;
783
+ /** Record type definitions: the data the app writes while it runs (optional, spec 1) */
784
+ recordTypes?: Record<string, RecordTypeDefinition>;
547
785
  /** Custom roles for fine-grained access control, each under its id (optional) */
548
786
  roles?: KeyedRoles;
549
787
  /** Global workflow configuration with approval stages (optional) */
@@ -554,7 +792,7 @@ interface SchemaConfig {
554
792
  /**
555
793
  * Complete schema definition - Generic version for type inference
556
794
  */
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>> {
795
+ 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>, TRecords extends Record<string, RecordTypeDefinition> = Record<string, RecordTypeDefinition>> {
558
796
  readonly _tag: 'schema';
559
797
  readonly locales?: TLocales;
560
798
  readonly contentTypes: TContentTypes;
@@ -562,6 +800,7 @@ interface SchemaDefinition<TContentTypes extends Record<string, ContentTypeDefin
562
800
  readonly queries: TQueries;
563
801
  readonly settingsGroups?: TSettings;
564
802
  readonly assetTypes?: TAssets;
803
+ readonly recordTypes?: TRecords;
565
804
  readonly roles?: TRoles;
566
805
  readonly workflow?: TWorkflow;
567
806
  readonly views?: TViews;
@@ -569,13 +808,14 @@ interface SchemaDefinition<TContentTypes extends Record<string, ContentTypeDefin
569
808
  /**
570
809
  * Typed schema config for type inference
571
810
  */
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>> {
811
+ 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>, TRecords extends Record<string, RecordTypeDefinition> = Record<string, RecordTypeDefinition>> {
573
812
  locales?: TLocales;
574
813
  contentTypes: TContentTypes;
575
814
  singletonContentTypes?: TSingletons;
576
815
  queries?: TQueries;
577
816
  settingsGroups?: TSettings;
578
817
  assetTypes?: TAssets;
818
+ recordTypes?: TRecords;
579
819
  roles?: TRoles;
580
820
  workflow?: TWorkflow;
581
821
  views?: TViews;
@@ -615,7 +855,7 @@ interface TypedSchemaConfig<TContentTypes extends Record<string, ContentTypeDefi
615
855
  * contentTypes: { product },
616
856
  * })
617
857
  */
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>;
858
+ 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>, TRecords extends Record<string, RecordTypeDefinition> = Record<string, never>>(config: TypedSchemaConfig<TContentTypes, TSingletons, TQueries, TSettings, TLocales, TRoles, TWorkflow, TViews, TAssets, TRecords> & NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TRecords, TLocales, TRoles, TWorkflow>): SchemaDefinition<TContentTypes, TSingletons, TQueries, TSettings, TLocales, RolesAsList<TRoles>, TWorkflow, ViewsAsList<TViews>, TAssets, TRecords>;
619
859
  /**
620
860
  * What `defineSchema` holds a schema's names to (REL-2416): each section of types against what the
621
861
  * schema declares — a reference's `to` and rich text's `links.to` against its content, singleton and
@@ -625,7 +865,7 @@ declare function defineSchema<TContentTypes extends Record<string, ContentTypeDe
625
865
  * against the built-in roles and its role keys; and a type's stages against its workflow's stage
626
866
  * keys. Types only; `./checked-names.ts` says how.
627
867
  */
628
- type NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TLocales, TRoles, TWorkflow> = {
868
+ type NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TRecords, TLocales, TRoles, TWorkflow> = {
629
869
  readonly locales?: CheckedLocales<TLocales>;
630
870
  readonly roles?: CheckedRoles<TRoles>;
631
871
  readonly workflow?: CheckedWorkflow<TWorkflow, TRoles>;
@@ -633,10 +873,14 @@ type NamesChecked<TContentTypes, TSingletons, TSettings, TAssets, TLocales, TRol
633
873
  readonly singletonContentTypes?: CheckedSection<TSingletons, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
634
874
  readonly settingsGroups?: CheckedSection<TSettings, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
635
875
  readonly assetTypes?: CheckedSection<TAssets, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow>>;
876
+ readonly recordTypes?: CheckedSection<TRecords, DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow, TRecords>>;
636
877
  };
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>;
878
+ /**
879
+ * The names a schema declares, for its sections' names to be checked against. `TRecords` is the
880
+ * Record types a section's references may name: none for an entry type's.
881
+ */
882
+ interface DeclaredBy<TContentTypes, TSingletons, TAssets, TLocales, TWorkflow, TRecords = never> {
883
+ readonly targets: KeysDeclared<TContentTypes> | KeysDeclared<TSingletons> | KeysDeclared<TAssets> | KeysDeclared<TRecords> | ([TRecords] extends [never] ? never : ContributedRecordType);
640
884
  readonly locales: LocaleCodesOf<TLocales>;
641
885
  readonly stages: StagesDeclared<TWorkflow>;
642
886
  }
@@ -651,7 +895,7 @@ type ViewsAsList<V extends KeyedViews> = KeyedViewsAsList<V>;
651
895
  * Type alias for any schema definition.
652
896
  * Uses `any` intentionally for type inference utilities that need to accept any schema.
653
897
  */
654
- type AnySchemaDefinition = SchemaDefinition<any, any, any, any, any, any, any, any, any>;
898
+ type AnySchemaDefinition = SchemaDefinition<any, any, any, any, any, any, any, any, any, any>;
655
899
  /**
656
900
  * Get content type names from a schema
657
901
  */
@@ -688,6 +932,10 @@ type SchemaSettingsGroupNames<T extends AnySchemaDefinition> = NonNullable<T['se
688
932
  * Get asset type names from a schema
689
933
  */
690
934
  type SchemaAssetTypeNames<T extends AnySchemaDefinition> = NonNullable<T['assetTypes']> extends Record<string, AssetTypeDefinition> ? keyof NonNullable<T['assetTypes']> & string : never;
935
+ /**
936
+ * Get Record type names from a schema (spec 1), read through `NonNullable` as asset types are
937
+ */
938
+ type SchemaRecordTypeNames<T extends AnySchemaDefinition> = NonNullable<T['recordTypes']> extends Record<string, RecordTypeDefinition> ? keyof NonNullable<T['recordTypes']> & string : never;
691
939
  /**
692
940
  * Get locale codes from a schema: the codes its locales declare, or `string` for a schema that
693
941
  * declares none. `defineSchema` now types an absent `locales` as an empty list, so that a Field's
@@ -696,4 +944,4 @@ type SchemaAssetTypeNames<T extends AnySchemaDefinition> = NonNullable<T['assetT
696
944
  */
697
945
  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
946
 
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 };
947
+ export { type Parameterizable as $, type AnyRecordTypeDefinition as A, type WhereCondition as B, type WhereValue as C, type WhereOperator as D, type QueryScalar as E, type FieldsWriteRule as F, type SortCondition as G, type HavingOperator as H, type InferRecordType as I, type SortDirection as J, type KeyedRecordTypeConfig as K, type IncludeDefinition as L, type IncludeRelationship as M, type NamedPolicyRule as N, type OwnerDeletedAction as O, type PolicyRule as P, type QueryConfig as Q, type RolesAsList as R, type SchemaConfig as S, type SelectMapping as T, type FilterDefinition as U, type ViewsAsList as V, type WriteRule as W, type CachePolicy as X, type CachePolicyObject as Y, type IncludeSubQuery as Z, type IncludeSubQueries as _, type SchemaDefinition as a, type QueryParameter as a0, type QueryParameterType as a1, type QueryCardinality as a2, type InferQueryResponse as a3, type InferQueryParams as a4, type QueryParameterValue as a5, type AnyQueryParameters as a6, type DeclaredParameters as a7, 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 SchemaRecordTypeNames as i, type SchemaEntry as j, type SchemaEntryOf as k, defineRecordType as l, type RecordTypeDefinition as m, type RecordExpiry as n, type RecordFieldsOf as o, type RecordTypeEndUsers as p, type RecordUpdateFieldsOf as q, type RecordWriteFieldsOf as r, type RecordWriteRule as s, defineQuery as t, type QueryDefinition as u, type QueryType as v, type FullTextSearch as w, type FetchBlock as x, type AggregateBlock as y, type SearchBlock as z };