@plasius/schema 1.1.1 → 1.2.1

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/dist/index.d.cts CHANGED
@@ -241,7 +241,7 @@ type InferField<T> = T extends {
241
241
  shape: infer Shape extends SchemaShape;
242
242
  } ? InferFromShape<Shape> : unknown;
243
243
  type IsOptional<T> = T extends {
244
- optional: true;
244
+ isRequired: false;
245
245
  } ? true : false;
246
246
  type InferFromShape<S extends SchemaShape> = {
247
247
  [K in keyof S]: IsOptional<S[K]> extends true ? InferField<S[K]> | undefined : InferField<S[K]>;
@@ -289,6 +289,21 @@ declare function getSchemaForType(type: string): Schema<any> | undefined;
289
289
  * Returns all schemas registered in the in-process global registry.
290
290
  */
291
291
  declare function getAllSchemas(): Schema<any>[];
292
+ /**
293
+ * Renders a schema into a simplified descriptor for front-end consumption.
294
+ * Intended for documentation and admin tooling rather than validation.
295
+ */
296
+ declare function renderSchemaDescription(schema: Schema<any>): {
297
+ title: string;
298
+ fields: Array<{
299
+ name: string;
300
+ type: FieldType;
301
+ optional: boolean;
302
+ description: string;
303
+ deprecated: boolean;
304
+ pii?: string;
305
+ }>;
306
+ };
292
307
 
293
308
  declare function createComponentSchema<T extends SchemaShape>(shape: SchemaShape, name: string, version: string, tableName?: string, schemaValidator?: (entity: Infer<T>) => boolean): Schema<SchemaShape>;
294
309
  declare function registerComponentSchema(type: string, schema: Schema<SchemaShape>): void;
@@ -388,4 +403,225 @@ declare function validateName(value: unknown): boolean;
388
403
  declare function validateUserId(value: unknown): boolean;
389
404
  declare function validateUserIdArray(value: unknown): boolean;
390
405
 
391
- export { type DeepReadonly, FieldBuilder, type FieldDefinition, type FieldType, type FieldTypeMap, type Infer, type PIIEnforcement, type RefEntityId, type Schema, type SchemaOptions, type SchemaShape, type SchemaUpgradeFunction, type SchemaUpgradeResult, type SchemaUpgradeSpec, type SchemaUpgradeStep, type ValidateCompositionOptions, type ValidationResult, createComponentSchema, createSchema, field, getAllComponentSchemas, getAllSchemas, getComponentSchema, getSchemaForType, isoCountryCodes, isoCurrencyCodes, registerComponentSchema, validateCountryCode, validateCurrencyCode, validateDateTimeISO, validateEmail, validateName, validatePercentage, validatePhone, validateRichText, validateSafeText, validateSemVer, validateUUID, validateUrl, validateUserId, validateUserIdArray };
406
+ /**
407
+ * ISO 639-1 language codes (two-letter).
408
+ * Tip: Keep this list as source of truth for supported languages in your app.
409
+ */
410
+ declare enum IsoLanguageCode {
411
+ Afar = "aa",
412
+ Abkhazian = "ab",
413
+ Afrikaans = "af",
414
+ Akan = "ak",
415
+ Albanian = "sq",
416
+ Amharic = "am",
417
+ Arabic = "ar",
418
+ Aragonese = "an",
419
+ Armenian = "hy",
420
+ Assamese = "as",
421
+ Avaric = "av",
422
+ Aymara = "ay",
423
+ Azerbaijani = "az",
424
+ Bashkir = "ba",
425
+ Bambara = "bm",
426
+ Basque = "eu",
427
+ Belarusian = "be",
428
+ Bengali = "bn",
429
+ Bislama = "bi",
430
+ Bosnian = "bs",
431
+ Breton = "br",
432
+ Bulgarian = "bg",
433
+ Burmese = "my",
434
+ Catalan = "ca",
435
+ Chamorro = "ch",
436
+ Chechen = "ce",
437
+ Chinese = "zh",
438
+ ChurchSlavic = "cu",
439
+ Chuvash = "cv",
440
+ Cornish = "kw",
441
+ Corsican = "co",
442
+ Cree = "cr",
443
+ Croatian = "hr",
444
+ Czech = "cs",
445
+ Danish = "da",
446
+ Divehi = "dv",
447
+ Dutch = "nl",
448
+ Dzongkha = "dz",
449
+ English = "en",
450
+ Esperanto = "eo",
451
+ Estonian = "et",
452
+ Ewe = "ee",
453
+ Faroese = "fo",
454
+ Fijian = "fj",
455
+ Finnish = "fi",
456
+ French = "fr",
457
+ WesternFrisian = "fy",
458
+ Fulah = "ff",
459
+ Gaelic = "gd",
460
+ Galician = "gl",
461
+ Ganda = "lg",
462
+ Georgian = "ka",
463
+ German = "de",
464
+ Greek = "el",
465
+ Kalaallisut = "kl",
466
+ Guarani = "gn",
467
+ Gujarati = "gu",
468
+ Haitian = "ht",
469
+ Hausa = "ha",
470
+ Hebrew = "he",
471
+ Herero = "hz",
472
+ Hindi = "hi",
473
+ HiriMotu = "ho",
474
+ Hungarian = "hu",
475
+ Icelandic = "is",
476
+ Ido = "io",
477
+ Igbo = "ig",
478
+ Indonesian = "id",
479
+ Interlingua = "ia",
480
+ Interlingue = "ie",
481
+ Inuktitut = "iu",
482
+ Inupiaq = "ik",
483
+ Irish = "ga",
484
+ Italian = "it",
485
+ Japanese = "ja",
486
+ Javanese = "jv",
487
+ Kannada = "kn",
488
+ Kanuri = "kr",
489
+ Kashmiri = "ks",
490
+ Kazakh = "kk",
491
+ CentralKhmer = "km",
492
+ Kikuyu = "ki",
493
+ Kinyarwanda = "rw",
494
+ Kyrgyz = "ky",
495
+ Komi = "kv",
496
+ Kongo = "kg",
497
+ Korean = "ko",
498
+ Kuanyama = "kj",
499
+ Kurdish = "ku",
500
+ Lao = "lo",
501
+ Latin = "la",
502
+ Latvian = "lv",
503
+ Limburgan = "li",
504
+ Lingala = "ln",
505
+ Lithuanian = "lt",
506
+ LubaKatanga = "lu",
507
+ Luxembourgish = "lb",
508
+ Macedonian = "mk",
509
+ Malagasy = "mg",
510
+ Malay = "ms",
511
+ Malayalam = "ml",
512
+ Maltese = "mt",
513
+ Manx = "gv",
514
+ Maori = "mi",
515
+ Marathi = "mr",
516
+ Marshallese = "mh",
517
+ Mongolian = "mn",
518
+ Nauru = "na",
519
+ Navajo = "nv",
520
+ NorthNdebele = "nd",
521
+ SouthNdebele = "nr",
522
+ Ndonga = "ng",
523
+ Nepali = "ne",
524
+ Norwegian = "no",
525
+ NorwegianBokmal = "nb",
526
+ NorwegianNynorsk = "nn",
527
+ SichuanYi = "ii",
528
+ Occitan = "oc",
529
+ Ojibwa = "oj",
530
+ Oriya = "or",
531
+ Oromo = "om",
532
+ Ossetian = "os",
533
+ Pali = "pi",
534
+ Pashto = "ps",
535
+ Persian = "fa",
536
+ Polish = "pl",
537
+ Portuguese = "pt",
538
+ Punjabi = "pa",
539
+ Quechua = "qu",
540
+ Romansh = "rm",
541
+ Romanian = "ro",
542
+ Rundi = "rn",
543
+ Russian = "ru",
544
+ Samoan = "sm",
545
+ Sango = "sg",
546
+ Sanskrit = "sa",
547
+ Sardinian = "sc",
548
+ Serbian = "sr",
549
+ Shona = "sn",
550
+ Sindhi = "sd",
551
+ Sinhala = "si",
552
+ Slovak = "sk",
553
+ Slovenian = "sl",
554
+ Somali = "so",
555
+ SouthernSotho = "st",
556
+ Spanish = "es",
557
+ Sundanese = "su",
558
+ Swahili = "sw",
559
+ Swati = "ss",
560
+ Swedish = "sv",
561
+ Tagalog = "tl",
562
+ Tahitian = "ty",
563
+ Tajik = "tg",
564
+ Tamil = "ta",
565
+ Tatar = "tt",
566
+ Telugu = "te",
567
+ Thai = "th",
568
+ Tibetan = "bo",
569
+ Tigrinya = "ti",
570
+ Tonga = "to",
571
+ Tsonga = "ts",
572
+ Tswana = "tn",
573
+ Turkish = "tr",
574
+ Turkmen = "tk",
575
+ Twi = "tw",
576
+ Uighur = "ug",
577
+ Ukrainian = "uk",
578
+ Urdu = "ur",
579
+ Uzbek = "uz",
580
+ Venda = "ve",
581
+ Vietnamese = "vi",
582
+ Volapuk = "vo",
583
+ Walloon = "wa",
584
+ Welsh = "cy",
585
+ Wolof = "wo",
586
+ Xhosa = "xh",
587
+ Yiddish = "yi",
588
+ Yoruba = "yo",
589
+ Zhuang = "za",
590
+ Zulu = "zu"
591
+ }
592
+ /** Type guard: primary language must be one of the enum values. */
593
+ declare function isIsoLanguageCode(value: unknown): value is IsoLanguageCode;
594
+ /**
595
+ * Region validator per BCP 47:
596
+ * - ISO 3166-1 alpha-2: 2 uppercase letters (e.g., GB, US)
597
+ * - UN M.49 numeric: 3 digits (e.g., 419 for Latin America)
598
+ *
599
+ * NOTE: This validates *shape* not membership against the 3166 list.
600
+ * If you want hard membership, we can add a Set of all alpha-2 regions.
601
+ */
602
+ declare function isRegionSubtag(value: string): boolean;
603
+ /** Script subtag per ISO 15924: one capital + three lowercase (e.g., Latn, Cyrl, Hans). */
604
+ declare function isScriptSubtag(value: string): boolean;
605
+ /** Variant subtag per BCP 47: 5–8 alnum, or 4 starting with a digit. */
606
+ declare function isVariantSubtag(value: string): boolean;
607
+ /** Extension sequence: singleton (alnum except 'x') + one or more 2–8 alnum subtags. */
608
+ declare function isExtensionSingleton(value: string): boolean;
609
+ declare function isExtensionSubtag(value: string): boolean;
610
+ /** Private-use subtag: 'x' then one or more 1–8 alnum subtags. */
611
+ declare function isPrivateUseSingleton(value: string): boolean;
612
+ declare function isPrivateUseSubtag(value: string): boolean;
613
+ /**
614
+ * Validates:
615
+ * - plain language: "en"
616
+ * - language + region: "en-GB"
617
+ * - language + script + region: "sr-Cyrl-RS"
618
+ * - language + variants: "sl-rozaj-biske", "de-CH-1996"
619
+ * - extensions: "en-GB-u-ca-gregory"
620
+ * - private-use: "en-x-klingon" or just "x-piglatin"
621
+ *
622
+ * Returns true only if the primary language is in IsoLanguageCode
623
+ * and the rest of the tag conforms to BCP 47 structure.
624
+ */
625
+ declare function validateLanguage(value: unknown): boolean;
626
+
627
+ export { type DeepReadonly, FieldBuilder, type FieldDefinition, type FieldType, type FieldTypeMap, type Infer, IsoLanguageCode, type PIIEnforcement, type RefEntityId, type Schema, type SchemaOptions, type SchemaShape, type SchemaUpgradeFunction, type SchemaUpgradeResult, type SchemaUpgradeSpec, type SchemaUpgradeStep, type ValidateCompositionOptions, type ValidationResult, createComponentSchema, createSchema, field, getAllComponentSchemas, getAllSchemas, getComponentSchema, getSchemaForType, isExtensionSingleton, isExtensionSubtag, isIsoLanguageCode, isPrivateUseSingleton, isPrivateUseSubtag, isRegionSubtag, isScriptSubtag, isVariantSubtag, isoCountryCodes, isoCurrencyCodes, registerComponentSchema, renderSchemaDescription, validateCountryCode, validateCurrencyCode, validateDateTimeISO, validateEmail, validateLanguage, validateName, validatePercentage, validatePhone, validateRichText, validateSafeText, validateSemVer, validateUUID, validateUrl, validateUserId, validateUserIdArray };
package/dist/index.d.ts CHANGED
@@ -241,7 +241,7 @@ type InferField<T> = T extends {
241
241
  shape: infer Shape extends SchemaShape;
242
242
  } ? InferFromShape<Shape> : unknown;
243
243
  type IsOptional<T> = T extends {
244
- optional: true;
244
+ isRequired: false;
245
245
  } ? true : false;
246
246
  type InferFromShape<S extends SchemaShape> = {
247
247
  [K in keyof S]: IsOptional<S[K]> extends true ? InferField<S[K]> | undefined : InferField<S[K]>;
@@ -289,6 +289,21 @@ declare function getSchemaForType(type: string): Schema<any> | undefined;
289
289
  * Returns all schemas registered in the in-process global registry.
290
290
  */
291
291
  declare function getAllSchemas(): Schema<any>[];
292
+ /**
293
+ * Renders a schema into a simplified descriptor for front-end consumption.
294
+ * Intended for documentation and admin tooling rather than validation.
295
+ */
296
+ declare function renderSchemaDescription(schema: Schema<any>): {
297
+ title: string;
298
+ fields: Array<{
299
+ name: string;
300
+ type: FieldType;
301
+ optional: boolean;
302
+ description: string;
303
+ deprecated: boolean;
304
+ pii?: string;
305
+ }>;
306
+ };
292
307
 
293
308
  declare function createComponentSchema<T extends SchemaShape>(shape: SchemaShape, name: string, version: string, tableName?: string, schemaValidator?: (entity: Infer<T>) => boolean): Schema<SchemaShape>;
294
309
  declare function registerComponentSchema(type: string, schema: Schema<SchemaShape>): void;
@@ -388,4 +403,225 @@ declare function validateName(value: unknown): boolean;
388
403
  declare function validateUserId(value: unknown): boolean;
389
404
  declare function validateUserIdArray(value: unknown): boolean;
390
405
 
391
- export { type DeepReadonly, FieldBuilder, type FieldDefinition, type FieldType, type FieldTypeMap, type Infer, type PIIEnforcement, type RefEntityId, type Schema, type SchemaOptions, type SchemaShape, type SchemaUpgradeFunction, type SchemaUpgradeResult, type SchemaUpgradeSpec, type SchemaUpgradeStep, type ValidateCompositionOptions, type ValidationResult, createComponentSchema, createSchema, field, getAllComponentSchemas, getAllSchemas, getComponentSchema, getSchemaForType, isoCountryCodes, isoCurrencyCodes, registerComponentSchema, validateCountryCode, validateCurrencyCode, validateDateTimeISO, validateEmail, validateName, validatePercentage, validatePhone, validateRichText, validateSafeText, validateSemVer, validateUUID, validateUrl, validateUserId, validateUserIdArray };
406
+ /**
407
+ * ISO 639-1 language codes (two-letter).
408
+ * Tip: Keep this list as source of truth for supported languages in your app.
409
+ */
410
+ declare enum IsoLanguageCode {
411
+ Afar = "aa",
412
+ Abkhazian = "ab",
413
+ Afrikaans = "af",
414
+ Akan = "ak",
415
+ Albanian = "sq",
416
+ Amharic = "am",
417
+ Arabic = "ar",
418
+ Aragonese = "an",
419
+ Armenian = "hy",
420
+ Assamese = "as",
421
+ Avaric = "av",
422
+ Aymara = "ay",
423
+ Azerbaijani = "az",
424
+ Bashkir = "ba",
425
+ Bambara = "bm",
426
+ Basque = "eu",
427
+ Belarusian = "be",
428
+ Bengali = "bn",
429
+ Bislama = "bi",
430
+ Bosnian = "bs",
431
+ Breton = "br",
432
+ Bulgarian = "bg",
433
+ Burmese = "my",
434
+ Catalan = "ca",
435
+ Chamorro = "ch",
436
+ Chechen = "ce",
437
+ Chinese = "zh",
438
+ ChurchSlavic = "cu",
439
+ Chuvash = "cv",
440
+ Cornish = "kw",
441
+ Corsican = "co",
442
+ Cree = "cr",
443
+ Croatian = "hr",
444
+ Czech = "cs",
445
+ Danish = "da",
446
+ Divehi = "dv",
447
+ Dutch = "nl",
448
+ Dzongkha = "dz",
449
+ English = "en",
450
+ Esperanto = "eo",
451
+ Estonian = "et",
452
+ Ewe = "ee",
453
+ Faroese = "fo",
454
+ Fijian = "fj",
455
+ Finnish = "fi",
456
+ French = "fr",
457
+ WesternFrisian = "fy",
458
+ Fulah = "ff",
459
+ Gaelic = "gd",
460
+ Galician = "gl",
461
+ Ganda = "lg",
462
+ Georgian = "ka",
463
+ German = "de",
464
+ Greek = "el",
465
+ Kalaallisut = "kl",
466
+ Guarani = "gn",
467
+ Gujarati = "gu",
468
+ Haitian = "ht",
469
+ Hausa = "ha",
470
+ Hebrew = "he",
471
+ Herero = "hz",
472
+ Hindi = "hi",
473
+ HiriMotu = "ho",
474
+ Hungarian = "hu",
475
+ Icelandic = "is",
476
+ Ido = "io",
477
+ Igbo = "ig",
478
+ Indonesian = "id",
479
+ Interlingua = "ia",
480
+ Interlingue = "ie",
481
+ Inuktitut = "iu",
482
+ Inupiaq = "ik",
483
+ Irish = "ga",
484
+ Italian = "it",
485
+ Japanese = "ja",
486
+ Javanese = "jv",
487
+ Kannada = "kn",
488
+ Kanuri = "kr",
489
+ Kashmiri = "ks",
490
+ Kazakh = "kk",
491
+ CentralKhmer = "km",
492
+ Kikuyu = "ki",
493
+ Kinyarwanda = "rw",
494
+ Kyrgyz = "ky",
495
+ Komi = "kv",
496
+ Kongo = "kg",
497
+ Korean = "ko",
498
+ Kuanyama = "kj",
499
+ Kurdish = "ku",
500
+ Lao = "lo",
501
+ Latin = "la",
502
+ Latvian = "lv",
503
+ Limburgan = "li",
504
+ Lingala = "ln",
505
+ Lithuanian = "lt",
506
+ LubaKatanga = "lu",
507
+ Luxembourgish = "lb",
508
+ Macedonian = "mk",
509
+ Malagasy = "mg",
510
+ Malay = "ms",
511
+ Malayalam = "ml",
512
+ Maltese = "mt",
513
+ Manx = "gv",
514
+ Maori = "mi",
515
+ Marathi = "mr",
516
+ Marshallese = "mh",
517
+ Mongolian = "mn",
518
+ Nauru = "na",
519
+ Navajo = "nv",
520
+ NorthNdebele = "nd",
521
+ SouthNdebele = "nr",
522
+ Ndonga = "ng",
523
+ Nepali = "ne",
524
+ Norwegian = "no",
525
+ NorwegianBokmal = "nb",
526
+ NorwegianNynorsk = "nn",
527
+ SichuanYi = "ii",
528
+ Occitan = "oc",
529
+ Ojibwa = "oj",
530
+ Oriya = "or",
531
+ Oromo = "om",
532
+ Ossetian = "os",
533
+ Pali = "pi",
534
+ Pashto = "ps",
535
+ Persian = "fa",
536
+ Polish = "pl",
537
+ Portuguese = "pt",
538
+ Punjabi = "pa",
539
+ Quechua = "qu",
540
+ Romansh = "rm",
541
+ Romanian = "ro",
542
+ Rundi = "rn",
543
+ Russian = "ru",
544
+ Samoan = "sm",
545
+ Sango = "sg",
546
+ Sanskrit = "sa",
547
+ Sardinian = "sc",
548
+ Serbian = "sr",
549
+ Shona = "sn",
550
+ Sindhi = "sd",
551
+ Sinhala = "si",
552
+ Slovak = "sk",
553
+ Slovenian = "sl",
554
+ Somali = "so",
555
+ SouthernSotho = "st",
556
+ Spanish = "es",
557
+ Sundanese = "su",
558
+ Swahili = "sw",
559
+ Swati = "ss",
560
+ Swedish = "sv",
561
+ Tagalog = "tl",
562
+ Tahitian = "ty",
563
+ Tajik = "tg",
564
+ Tamil = "ta",
565
+ Tatar = "tt",
566
+ Telugu = "te",
567
+ Thai = "th",
568
+ Tibetan = "bo",
569
+ Tigrinya = "ti",
570
+ Tonga = "to",
571
+ Tsonga = "ts",
572
+ Tswana = "tn",
573
+ Turkish = "tr",
574
+ Turkmen = "tk",
575
+ Twi = "tw",
576
+ Uighur = "ug",
577
+ Ukrainian = "uk",
578
+ Urdu = "ur",
579
+ Uzbek = "uz",
580
+ Venda = "ve",
581
+ Vietnamese = "vi",
582
+ Volapuk = "vo",
583
+ Walloon = "wa",
584
+ Welsh = "cy",
585
+ Wolof = "wo",
586
+ Xhosa = "xh",
587
+ Yiddish = "yi",
588
+ Yoruba = "yo",
589
+ Zhuang = "za",
590
+ Zulu = "zu"
591
+ }
592
+ /** Type guard: primary language must be one of the enum values. */
593
+ declare function isIsoLanguageCode(value: unknown): value is IsoLanguageCode;
594
+ /**
595
+ * Region validator per BCP 47:
596
+ * - ISO 3166-1 alpha-2: 2 uppercase letters (e.g., GB, US)
597
+ * - UN M.49 numeric: 3 digits (e.g., 419 for Latin America)
598
+ *
599
+ * NOTE: This validates *shape* not membership against the 3166 list.
600
+ * If you want hard membership, we can add a Set of all alpha-2 regions.
601
+ */
602
+ declare function isRegionSubtag(value: string): boolean;
603
+ /** Script subtag per ISO 15924: one capital + three lowercase (e.g., Latn, Cyrl, Hans). */
604
+ declare function isScriptSubtag(value: string): boolean;
605
+ /** Variant subtag per BCP 47: 5–8 alnum, or 4 starting with a digit. */
606
+ declare function isVariantSubtag(value: string): boolean;
607
+ /** Extension sequence: singleton (alnum except 'x') + one or more 2–8 alnum subtags. */
608
+ declare function isExtensionSingleton(value: string): boolean;
609
+ declare function isExtensionSubtag(value: string): boolean;
610
+ /** Private-use subtag: 'x' then one or more 1–8 alnum subtags. */
611
+ declare function isPrivateUseSingleton(value: string): boolean;
612
+ declare function isPrivateUseSubtag(value: string): boolean;
613
+ /**
614
+ * Validates:
615
+ * - plain language: "en"
616
+ * - language + region: "en-GB"
617
+ * - language + script + region: "sr-Cyrl-RS"
618
+ * - language + variants: "sl-rozaj-biske", "de-CH-1996"
619
+ * - extensions: "en-GB-u-ca-gregory"
620
+ * - private-use: "en-x-klingon" or just "x-piglatin"
621
+ *
622
+ * Returns true only if the primary language is in IsoLanguageCode
623
+ * and the rest of the tag conforms to BCP 47 structure.
624
+ */
625
+ declare function validateLanguage(value: unknown): boolean;
626
+
627
+ export { type DeepReadonly, FieldBuilder, type FieldDefinition, type FieldType, type FieldTypeMap, type Infer, IsoLanguageCode, type PIIEnforcement, type RefEntityId, type Schema, type SchemaOptions, type SchemaShape, type SchemaUpgradeFunction, type SchemaUpgradeResult, type SchemaUpgradeSpec, type SchemaUpgradeStep, type ValidateCompositionOptions, type ValidationResult, createComponentSchema, createSchema, field, getAllComponentSchemas, getAllSchemas, getComponentSchema, getSchemaForType, isExtensionSingleton, isExtensionSubtag, isIsoLanguageCode, isPrivateUseSingleton, isPrivateUseSubtag, isRegionSubtag, isScriptSubtag, isVariantSubtag, isoCountryCodes, isoCurrencyCodes, registerComponentSchema, renderSchemaDescription, validateCountryCode, validateCurrencyCode, validateDateTimeISO, validateEmail, validateLanguage, validateName, validatePercentage, validatePhone, validateRichText, validateSafeText, validateSemVer, validateUUID, validateUrl, validateUserId, validateUserIdArray };