@stndrds/schema 0.1.0-alpha.63 → 0.1.0-alpha.64

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { CurrencyCode, IconName, ColorId, CountryIso3, MimeType } from '@stndrds/constants';
2
+ import { IconName, CountryIso3, CurrencyCode, ColorId, MimeType } from '@stndrds/constants';
3
3
  import { Uuid } from './utils.js';
4
4
 
5
5
  /**
@@ -152,9 +152,9 @@ interface FeatureFlagsConfig {
152
152
  }
153
153
 
154
154
  /**
155
- * Allowed property types in .qualifyWith()
155
+ * Allowed attribute types in .qualifyWith()
156
156
  *
157
- * IMPORTANT: Complex types (formula, rollup, relation, file, user, document)
157
+ * IMPORTANT: Complex types (formula, rollup, relation, file, user, document, richtext)
158
158
  * are NOT supported to avoid duplicating backend behavior.
159
159
  */
160
160
  type PropertyType = "text" | "textarea" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "select" | "multiselect" | "rating" | "location";
@@ -164,132 +164,29 @@ type PropertyType = "text" | "textarea" | "number" | "checkbox" | "date" | "phon
164
164
  declare const FORBIDDEN_PROPERTY_TYPES: readonly ["formula", "rollup", "relation", "file", "user", "document", "richtext"];
165
165
  type ForbiddenPropertyType = (typeof FORBIDDEN_PROPERTY_TYPES)[number];
166
166
  /**
167
- * Base interface for all property definitions
168
- */
169
- interface BasePropertyDefinition {
170
- name: string;
171
- label?: string;
172
- required?: boolean;
173
- description?: string;
174
- }
175
- /**
176
- * Text property definition
177
- */
178
- interface TextPropertyDefinition extends BasePropertyDefinition {
179
- type: "text";
180
- minLength?: number;
181
- maxLength?: number;
182
- pattern?: string;
183
- placeholder?: string;
184
- }
185
- /**
186
- * Textarea property definition
187
- */
188
- interface TextareaPropertyDefinition extends BasePropertyDefinition {
189
- type: "textarea";
190
- minLength?: number;
191
- maxLength?: number;
192
- placeholder?: string;
193
- }
194
- /**
195
- * Number property definition
196
- */
197
- interface NumberPropertyDefinition extends BasePropertyDefinition {
198
- type: "number";
199
- min?: number;
200
- max?: number;
201
- decimal?: number;
202
- integer?: boolean;
203
- placeholder?: string;
204
- }
205
- /**
206
- * Checkbox property definition
207
- */
208
- interface CheckboxPropertyDefinition extends BasePropertyDefinition {
209
- type: "checkbox";
210
- }
211
- /**
212
- * Date property definition
213
- */
214
- interface DatePropertyDefinition extends BasePropertyDefinition {
215
- type: "date";
216
- includeTime?: boolean;
217
- min?: string;
218
- max?: string;
219
- }
220
- /**
221
- * Phone property definition
222
- */
223
- interface PhonePropertyDefinition extends BasePropertyDefinition {
224
- type: "phone";
225
- }
226
- /**
227
- * Currency property definition
228
- */
229
- interface CurrencyPropertyDefinition extends BasePropertyDefinition {
230
- type: "currency";
231
- currency?: CurrencyCode;
232
- min?: number;
233
- max?: number;
234
- }
235
- /**
236
- * Status property definition
237
- */
238
- interface StatusPropertyDefinition extends BasePropertyDefinition {
239
- type: "status";
240
- options: Array<Option & {
241
- group: StatusGroup;
242
- }>;
243
- }
244
- /**
245
- * Select property definition
246
- */
247
- interface SelectPropertyDefinition extends BasePropertyDefinition {
248
- type: "select";
249
- options: Option[];
250
- }
251
- /**
252
- * Multiselect property definition
253
- */
254
- interface MultiselectPropertyDefinition extends BasePropertyDefinition {
255
- type: "multiselect";
256
- options: Option[];
257
- maxSelections?: number;
258
- }
259
- /**
260
- * Rating property definition
261
- */
262
- interface RatingPropertyDefinition extends BasePropertyDefinition {
263
- type: "rating";
264
- max?: number;
265
- icon?: IconName;
266
- }
267
- /**
268
- * Location property definition
269
- */
270
- interface LocationPropertyDefinition extends BasePropertyDefinition {
271
- type: "location";
272
- }
273
- /**
274
- * Union of all property definitions
167
+ * Union of attribute types allowed as qualified relation properties.
168
+ *
169
+ * These are the same Attribute types used for object attributes,
170
+ * restricted to simple types that don't require complex backend duplication.
275
171
  */
276
- type PropertyDefinition = TextPropertyDefinition | TextareaPropertyDefinition | NumberPropertyDefinition | CheckboxPropertyDefinition | DatePropertyDefinition | PhonePropertyDefinition | CurrencyPropertyDefinition | StatusPropertyDefinition | SelectPropertyDefinition | MultiselectPropertyDefinition | RatingPropertyDefinition | LocationPropertyDefinition;
172
+ type PropertyAttribute = TextAttribute | TextAreaAttribute | NumberAttribute | CheckboxAttribute | DateAttribute | PhoneAttribute | CurrencyAttribute | StatusAttribute | SelectAttribute | MultiselectAttribute | RatingAttribute | LocationAttribute;
277
173
  /**
278
- * Schema defining properties for a qualified relation
174
+ * Schema defining properties for a qualified relation.
175
+ *
176
+ * Uses the same Attribute types as object attributes, enabling DRY builders:
279
177
  *
280
178
  * @example
281
179
  * ```typescript
282
- * const schema: PropertySchema = {
283
- * definitions: [
284
- * { name: "role", type: "select", options: [...], required: true },
285
- * { name: "shares", type: "number", min: 0 },
286
- * { name: "percentage", type: "number", min: 0, max: 100, decimal: 2 }
287
- * ]
288
- * };
180
+ * relation({ name: "companies", label: "Companies" })
181
+ * .to("companies").many()
182
+ * .qualifyWith(
183
+ * select({ name: "role", label: "Role" }).options([...]).required(),
184
+ * number({ name: "shares", label: "Shares" }).min(0),
185
+ * )
289
186
  * ```
290
187
  */
291
188
  interface PropertySchema {
292
- definitions: PropertyDefinition[];
189
+ definitions: PropertyAttribute[];
293
190
  }
294
191
 
295
192
  type AttributeType = "text" | "textarea" | "richtext" | "number" | "checkbox" | "date" | "phone" | "currency" | "status" | "location" | "select" | "multiselect" | "file" | "user" | "relation" | "rating" | "formula" | "rollup" | "document";
@@ -448,6 +345,20 @@ interface UserAttribute extends BaseAttribute<string> {
448
345
  * Use with `.toAny()` builder method
449
346
  */
450
347
  declare const RELATION_TARGET_ANY: "*";
348
+ /**
349
+ * Configuration for bilateral synchronization (bidirectional relations)
350
+ */
351
+ interface BilateralConfig {
352
+ /** Target object containing the inverse attribute */
353
+ object: string;
354
+ /** Name of the inverse attribute */
355
+ attribute: string;
356
+ /** Optional cardinality override (inferred by default) */
357
+ cardinality?: "one" | "many";
358
+ /** When true, this side owns the storage direction for qualified properties.
359
+ * Set to false on the inverse side (enriched at read time). */
360
+ storageOwner?: boolean;
361
+ }
451
362
  /**
452
363
  * Target object for a relation - defines which objects can be linked
453
364
  */
@@ -479,6 +390,8 @@ interface RelationAttributeBase extends Omit<BaseAttribute<unknown>, "defaultVal
479
390
  targets: RelationTarget[];
480
391
  /** Optional properties schema for qualified relations */
481
392
  properties?: PropertySchema;
393
+ /** Configuration for bilateral synchronization (opt-in) */
394
+ bilateral?: BilateralConfig;
482
395
  }
483
396
  /**
484
397
  * Single relation attribute (one-to-one or many-to-one)
@@ -537,6 +450,18 @@ type RelationAttribute = SingleRelationAttribute | MultiRelationAttribute;
537
450
  * Universal relations have `targets: [{ object: "*" }]`
538
451
  */
539
452
  declare function isUniversalRelation(attr: RelationAttribute): boolean;
453
+ /**
454
+ * Check if a relation attribute has bilateral synchronization enabled
455
+ */
456
+ declare function isBilateralRelation(attr: RelationAttribute): attr is RelationAttribute & {
457
+ bilateral: BilateralConfig;
458
+ };
459
+ /**
460
+ * Infer the cardinality of the inverse relation
461
+ * - one → many (contact.company ↔ company.contacts)
462
+ * - many → many (contact.tags ↔ tag.contacts)
463
+ */
464
+ declare function inferInverseCardinality(cardinality: "one" | "many"): "one" | "many";
540
465
  interface TextAreaAttribute extends BaseAttribute<string> {
541
466
  type: "textarea";
542
467
  }
@@ -1628,4 +1553,4 @@ declare function isRecordComplete(objectDef: ObjectDefinition, data: Record<stri
1628
1553
  */
1629
1554
  declare function computeRecordStatus(objectDef: ObjectDefinition, data: Record<string, unknown>): CompletionStatus;
1630
1555
 
1631
- export { type DateFormat as $, type Attribute as A, type FormulaReturnType as B, type CheckboxPropertyDefinition as C, type DateAttribute as D, type RollupAttribute as E, type FeatureGate as F, type RollupFunction as G, type AttributeType as H, type ObjectDefinition as I, type FlagValueType as J, type FeatureFlagDefinition as K, type LocationPropertyDefinition as L, type MultiselectPropertyDefinition as M, type NumberPropertyDefinition as N, type Option as O, type PropertyDefinition as P, type FlagLevel as Q, type RatingPropertyDefinition as R, type StatusPropertyDefinition as S, type TextPropertyDefinition as T, type UserAttribute as U, type FeatureFlagsRepository as V, type StaticFlagDefault as W, type ResolvedFlag as X, type AttributeGroup as Y, type BaseAttribute as Z, type NumberUnit as _, type DocumentAttribute as a, createRelationValidator as a$, type DateValue as a0, type Phone as a1, type Currency as a2, type Location as a3, type LocationGranularity as a4, RELATION_TARGET_ANY as a5, type RelationAttribute as a6, isUniversalRelation as a7, type FlagOverride as a8, type FeatureFlagsConfig as a9, multiselectConfigSchema as aA, fileConfigSchema as aB, userConfigSchema as aC, relationConfigSchema as aD, ratingConfigSchema as aE, formulaConfigSchema as aF, rollupConfigSchema as aG, documentConfigSchema as aH, attributeConfigSchemas as aI, getAttributeConfigSchema as aJ, validateAttributeConfig as aK, parseAttributeConfig as aL, safeParseAttributeConfig as aM, createTextValidator as aN, createNumberValidator as aO, createCheckboxValidator as aP, createDateValidator as aQ, createPhoneValidator as aR, createCurrencyValidator as aS, createStatusValidator as aT, createSelectValidator as aU, createMultiselectValidator as aV, createLocationValidator as aW, createFileValidator as aX, createUserValidator as aY, createSingleRelationValidator as aZ, createMultiRelationValidator as a_, RESERVED_ATTRIBUTE_NAMES as aa, SYSTEM_FIELD_NAMES as ab, type ReservedAttributeName as ac, type SystemFieldName as ad, type Timestamps as ae, type SharingMode as af, type ObjectAttribute as ag, type CompletionStatus as ah, type ObjectRecord as ai, type PropertyType as aj, FORBIDDEN_PROPERTY_TYPES as ak, type ForbiddenPropertyType as al, formatZodErrors as am, type ValidationMessages as an, DEFAULT_VALIDATION_MESSAGES as ao, textConfigSchema as ap, textareaConfigSchema as aq, richtextConfigSchema as ar, numberConfigSchema as as, checkboxConfigSchema as at, dateConfigSchema as au, phoneConfigSchema as av, currencyConfigSchema as aw, statusConfigSchema as ax, locationConfigSchema as ay, selectConfigSchema as az, type TextareaPropertyDefinition as b, createRatingValidator as b0, createFormulaValidator as b1, createRollupValidator as b2, createTextAreaValidator as b3, createRichtextValidator as b4, createAttributeValidator as b5, createFormAttributeValidator as b6, createObjectValidator as b7, type ValidationResult as b8, validateAttribute as b9, validateObject as ba, validateObjectOrThrow as bb, createDraftValidator as bc, validateDraft as bd, validateDraftOrThrow as be, getMissingRequiredAttributes as bf, isRecordComplete as bg, computeRecordStatus as bh, type DatePropertyDefinition as c, type PhonePropertyDefinition as d, type CurrencyPropertyDefinition as e, type StatusGroup as f, type SelectPropertyDefinition as g, type PropertySchema as h, type TextAttribute as i, type TextAreaAttribute as j, type RichtextAttribute as k, type RichtextFeature as l, type NumberAttribute as m, type CheckboxAttribute as n, type PhoneAttribute as o, type CurrencyAttribute as p, type StatusAttribute as q, type SelectAttribute as r, type MultiselectAttribute as s, type LocationAttribute as t, type FileAttribute as u, type SingleRelationAttribute as v, type MultiRelationAttribute as w, type RelationTarget as x, type RatingAttribute as y, type FormulaAttribute as z };
1556
+ export { RESERVED_ATTRIBUTE_NAMES as $, type Attribute as A, type BilateralConfig as B, type CheckboxAttribute as C, type DateAttribute as D, type NumberUnit as E, type FeatureGate as F, type DateFormat as G, type DateValue as H, type Phone as I, type Currency as J, type Location as K, type LocationAttribute as L, type MultiselectAttribute as M, type NumberAttribute as N, type Option as O, type PhoneAttribute as P, type LocationGranularity as Q, type RichtextAttribute as R, type StatusAttribute as S, type TextAttribute as T, type UserAttribute as U, RELATION_TARGET_ANY as V, isUniversalRelation as W, isBilateralRelation as X, inferInverseCardinality as Y, type FlagOverride as Z, type FeatureFlagsConfig as _, type DocumentAttribute as a, type ValidationResult as a$, SYSTEM_FIELD_NAMES as a0, type ReservedAttributeName as a1, type SystemFieldName as a2, type Timestamps as a3, type SharingMode as a4, type ObjectAttribute as a5, type CompletionStatus as a6, type ObjectRecord as a7, type PropertyType as a8, FORBIDDEN_PROPERTY_TYPES as a9, getAttributeConfigSchema as aA, validateAttributeConfig as aB, parseAttributeConfig as aC, safeParseAttributeConfig as aD, createTextValidator as aE, createNumberValidator as aF, createCheckboxValidator as aG, createDateValidator as aH, createPhoneValidator as aI, createCurrencyValidator as aJ, createStatusValidator as aK, createSelectValidator as aL, createMultiselectValidator as aM, createLocationValidator as aN, createFileValidator as aO, createUserValidator as aP, createSingleRelationValidator as aQ, createMultiRelationValidator as aR, createRelationValidator as aS, createRatingValidator as aT, createFormulaValidator as aU, createRollupValidator as aV, createTextAreaValidator as aW, createRichtextValidator as aX, createAttributeValidator as aY, createFormAttributeValidator as aZ, createObjectValidator as a_, type ForbiddenPropertyType as aa, type PropertyAttribute as ab, type PropertySchema as ac, formatZodErrors as ad, type ValidationMessages as ae, DEFAULT_VALIDATION_MESSAGES as af, textConfigSchema as ag, textareaConfigSchema as ah, richtextConfigSchema as ai, numberConfigSchema as aj, checkboxConfigSchema as ak, dateConfigSchema as al, phoneConfigSchema as am, currencyConfigSchema as an, statusConfigSchema as ao, locationConfigSchema as ap, selectConfigSchema as aq, multiselectConfigSchema as ar, fileConfigSchema as as, userConfigSchema as at, relationConfigSchema as au, ratingConfigSchema as av, formulaConfigSchema as aw, rollupConfigSchema as ax, documentConfigSchema as ay, attributeConfigSchemas as az, type TextAreaAttribute as b, validateAttribute as b0, validateObject as b1, validateObjectOrThrow as b2, createDraftValidator as b3, validateDraft as b4, validateDraftOrThrow as b5, getMissingRequiredAttributes as b6, isRecordComplete as b7, computeRecordStatus as b8, type RichtextFeature as c, type CurrencyAttribute as d, type SelectAttribute as e, type FileAttribute as f, type RatingAttribute as g, type RelationAttribute as h, type SingleRelationAttribute as i, type MultiRelationAttribute as j, type RelationTarget as k, type FormulaAttribute as l, type FormulaReturnType as m, type RollupAttribute as n, type RollupFunction as o, type AttributeType as p, type ObjectDefinition as q, type FlagValueType as r, type FeatureFlagDefinition as s, type FlagLevel as t, type FeatureFlagsRepository as u, type StaticFlagDefault as v, type ResolvedFlag as w, type StatusGroup as x, type AttributeGroup as y, type BaseAttribute as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stndrds/schema",
3
- "version": "0.1.0-alpha.63",
3
+ "version": "0.1.0-alpha.64",
4
4
  "description": "Standard schema definitions and utilities",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -35,7 +35,7 @@
35
35
  "jose": "^6.1.3",
36
36
  "pdf-lib": "^1.17.1",
37
37
  "zod": "^4.2.1",
38
- "@stndrds/constants": "0.1.0-alpha.63"
38
+ "@stndrds/constants": "0.1.0-alpha.64"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^25.0.3",