@atcute/lexicons 1.2.5 → 1.2.7

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 (61) hide show
  1. package/README.md +151 -4
  2. package/dist/interfaces/blob.d.ts +2 -2
  3. package/dist/interfaces/blob.d.ts.map +1 -1
  4. package/dist/interfaces/blob.js.map +1 -1
  5. package/dist/interfaces/bytes.d.ts.map +1 -1
  6. package/dist/interfaces/bytes.js.map +1 -1
  7. package/dist/interfaces/cid-link.d.ts.map +1 -1
  8. package/dist/interfaces/cid-link.js.map +1 -1
  9. package/dist/syntax/at-identifier.d.ts.map +1 -1
  10. package/dist/syntax/at-identifier.js.map +1 -1
  11. package/dist/syntax/at-uri.d.ts +2 -2
  12. package/dist/syntax/at-uri.d.ts.map +1 -1
  13. package/dist/syntax/at-uri.js +1 -1
  14. package/dist/syntax/at-uri.js.map +1 -1
  15. package/dist/syntax/cid.d.ts +1 -1
  16. package/dist/syntax/cid.d.ts.map +1 -1
  17. package/dist/syntax/cid.js.map +1 -1
  18. package/dist/syntax/datetime.d.ts +1 -1
  19. package/dist/syntax/datetime.d.ts.map +1 -1
  20. package/dist/syntax/datetime.js.map +1 -1
  21. package/dist/syntax/did.d.ts +1 -1
  22. package/dist/syntax/did.d.ts.map +1 -1
  23. package/dist/syntax/did.js +1 -1
  24. package/dist/syntax/did.js.map +1 -1
  25. package/dist/syntax/handle.d.ts +1 -1
  26. package/dist/syntax/handle.d.ts.map +1 -1
  27. package/dist/syntax/handle.js.map +1 -1
  28. package/dist/syntax/language.d.ts +1 -1
  29. package/dist/syntax/language.d.ts.map +1 -1
  30. package/dist/syntax/language.js.map +1 -1
  31. package/dist/syntax/nsid.d.ts +1 -1
  32. package/dist/syntax/nsid.d.ts.map +1 -1
  33. package/dist/syntax/nsid.js.map +1 -1
  34. package/dist/syntax/record-key.d.ts +1 -1
  35. package/dist/syntax/record-key.d.ts.map +1 -1
  36. package/dist/syntax/record-key.js.map +1 -1
  37. package/dist/syntax/tid.d.ts +1 -1
  38. package/dist/syntax/tid.d.ts.map +1 -1
  39. package/dist/syntax/tid.js.map +1 -1
  40. package/dist/syntax/uri.d.ts +1 -1
  41. package/dist/syntax/uri.d.ts.map +1 -1
  42. package/dist/syntax/uri.js +2 -15
  43. package/dist/syntax/uri.js.map +1 -1
  44. package/dist/types/brand.d.ts.map +1 -1
  45. package/dist/utils.d.ts +1 -1
  46. package/dist/utils.d.ts.map +1 -1
  47. package/dist/utils.js.map +1 -1
  48. package/dist/validations/index.d.ts +11 -11
  49. package/dist/validations/index.d.ts.map +1 -1
  50. package/dist/validations/index.js +6 -36
  51. package/dist/validations/index.js.map +1 -1
  52. package/dist/validations/utils.d.ts +0 -2
  53. package/dist/validations/utils.d.ts.map +1 -1
  54. package/dist/validations/utils.js +1 -59
  55. package/dist/validations/utils.js.map +1 -1
  56. package/lib/syntax/at-uri.ts +2 -2
  57. package/lib/syntax/did.ts +1 -1
  58. package/lib/syntax/uri.ts +2 -20
  59. package/lib/validations/index.ts +35 -75
  60. package/lib/validations/utils.ts +1 -73
  61. package/package.json +16 -11
@@ -1,23 +1,15 @@
1
- import type { StandardSchemaV1 } from '@standard-schema/spec';
1
+ import { isUtf8LengthInRange } from '@atcute/uint8array';
2
+ import { isGraphemeLengthInRange } from '@atcute/util-text';
2
3
 
3
- import * as syntax from '../syntax/index.js';
4
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
4
5
 
5
6
  import { _isBytesWrapper } from '../interfaces/bytes.js';
6
7
  import * as interfaces from '../interfaces/index.js';
7
-
8
+ import * as syntax from '../syntax/index.js';
8
9
  import type { $type } from '../types/brand.js';
9
-
10
10
  import { assert } from '../utils.js';
11
11
 
12
- import {
13
- allowsEval,
14
- getGraphemeLength,
15
- getUtf8Length,
16
- isArray,
17
- isObject,
18
- lazy,
19
- lazyProperty,
20
- } from './utils.js';
12
+ import { allowsEval, isArray, isObject, lazy, lazyProperty } from './utils.js';
21
13
 
22
14
  /**
23
15
  * flag indicating whether xrpc schema generation helpers are used. set to true
@@ -523,8 +515,9 @@ export const literal = <T extends Literal>(value: T): LiteralSchema<T> => {
523
515
  };
524
516
  };
525
517
 
526
- export interface LiteralEnumSchema<TEnums extends readonly Literal[] = []>
527
- extends BaseSchema<TEnums[number]> {
518
+ export interface LiteralEnumSchema<TEnums extends readonly Literal[] = []> extends BaseSchema<
519
+ TEnums[number]
520
+ > {
528
521
  readonly type: 'literal_enum';
529
522
  readonly expected: TEnums;
530
523
  }
@@ -635,8 +628,10 @@ export const integer = (): IntegerSchema => {
635
628
 
636
629
  // #region Integer constraints
637
630
 
638
- export interface IntegerRangeConstraint<TMin extends number = number, TMax extends number = number>
639
- extends BaseConstraint<number> {
631
+ export interface IntegerRangeConstraint<
632
+ TMin extends number = number,
633
+ TMax extends number = number,
634
+ > extends BaseConstraint<number> {
640
635
  readonly type: 'integer_range';
641
636
  readonly min: TMin;
642
637
  readonly max: TMax;
@@ -700,8 +695,9 @@ export interface StringSchema<T extends string = string> extends BaseSchema<T> {
700
695
  readonly format: null;
701
696
  }
702
697
 
703
- export interface FormattedStringSchema<TFormat extends keyof StringFormatMap = keyof StringFormatMap>
704
- extends BaseSchema<StringFormatMap[TFormat]> {
698
+ export interface FormattedStringSchema<
699
+ TFormat extends keyof StringFormatMap = keyof StringFormatMap,
700
+ > extends BaseSchema<StringFormatMap[TFormat]> {
705
701
  readonly type: 'string';
706
702
  readonly format: TFormat;
707
703
  }
@@ -821,29 +817,7 @@ export const stringLength: {
821
817
  minLength: minLength,
822
818
  maxLength: maxLength,
823
819
  '~run'(input, _flags) {
824
- // UTF-8 conversion can be expensive, so we're going to do some safe naive
825
- // checks where we assume an upper-bound of the UTF-16 to UTF-8 conversion
826
-
827
- const utf16Len = input.length;
828
- const maybeUtf8Len = utf16Len * 3;
829
-
830
- // fail early if estimated upper bound is too small
831
- if (maybeUtf8Len < minLength) {
832
- return issue;
833
- }
834
-
835
- // skip calculation if UTF-16 length already satisfies both constraints
836
- if (utf16Len >= minLength && maybeUtf8Len <= maxLength) {
837
- return undefined;
838
- }
839
-
840
- const utf8Len = getUtf8Length(input);
841
-
842
- if (utf8Len < minLength) {
843
- return issue;
844
- }
845
-
846
- if (utf8Len > maxLength) {
820
+ if (!isUtf8LengthInRange(input, minLength, maxLength)) {
847
821
  return issue;
848
822
  }
849
823
 
@@ -885,29 +859,7 @@ export const stringGraphemes: {
885
859
  minGraphemes: minGraphemes,
886
860
  maxGraphemes: maxGraphemes,
887
861
  '~run'(input, _flags) {
888
- // grapheme conversion is expensive, so we're going to do some safe naive
889
- // checks where we assume 1 UTF-16 character = 1 grapheme.
890
-
891
- const utf16Len = input.length;
892
-
893
- // fail early if UTF-16 length is too small
894
- if (utf16Len < minGraphemes) {
895
- return issue;
896
- }
897
-
898
- // if there is no minimum bounds, we can safely skip when UTF-16 is
899
- // within the maximum bounds.
900
- if (minGraphemes === 0 && utf16Len <= maxGraphemes) {
901
- return undefined;
902
- }
903
-
904
- const graphemeLen = getGraphemeLength(input);
905
-
906
- if (graphemeLen < minGraphemes) {
907
- return issue;
908
- }
909
-
910
- if (graphemeLen > maxGraphemes) {
862
+ if (!isGraphemeLengthInRange(input, minGraphemes, maxGraphemes)) {
911
863
  return issue;
912
864
  }
913
865
 
@@ -1002,8 +954,10 @@ export const bytes = (): BytesSchema => {
1002
954
  };
1003
955
 
1004
956
  // #region IPLD bytes constraint
1005
- export interface BytesSizeConstraint<TMinLength extends number = number, TMaxLength extends number = number>
1006
- extends BaseConstraint<interfaces.Bytes> {
957
+ export interface BytesSizeConstraint<
958
+ TMinLength extends number = number,
959
+ TMaxLength extends number = number,
960
+ > extends BaseConstraint<interfaces.Bytes> {
1007
961
  readonly type: 'bytes_size';
1008
962
  readonly minSize: TMinLength;
1009
963
  readonly maxSize: TMaxLength;
@@ -1101,8 +1055,10 @@ export const cidLink = (): CidLinkSchema => {
1101
1055
 
1102
1056
  // #region Nullable schema
1103
1057
 
1104
- export interface NullableSchema<TItem extends BaseSchema = BaseSchema>
1105
- extends BaseSchema<InferInput<TItem> | null, InferOutput<TItem> | null> {
1058
+ export interface NullableSchema<TItem extends BaseSchema = BaseSchema> extends BaseSchema<
1059
+ InferInput<TItem> | null,
1060
+ InferOutput<TItem> | null
1061
+ > {
1106
1062
  readonly type: 'nullable';
1107
1063
  readonly wrapped: TItem;
1108
1064
  }
@@ -1268,8 +1224,10 @@ export const array = <TItem extends BaseSchema>(item: TItem | (() => TItem)): Ar
1268
1224
 
1269
1225
  // #region Array constraints
1270
1226
 
1271
- export interface ArrayLengthConstraint<TMinLength extends number = number, TMaxLength extends number = number>
1272
- extends BaseConstraint<unknown[]> {
1227
+ export interface ArrayLengthConstraint<
1228
+ TMinLength extends number = number,
1229
+ TMaxLength extends number = number,
1230
+ > extends BaseConstraint<unknown[]> {
1273
1231
  readonly type: 'array_length';
1274
1232
  readonly minLength: TMinLength;
1275
1233
  readonly maxLength: TMaxLength;
@@ -1360,8 +1318,9 @@ type InferObjectOutput<TShape extends ObjectShape> = Flatten<
1360
1318
  }
1361
1319
  >;
1362
1320
 
1363
- export interface ObjectSchema<TShape extends LooseObjectShape = LooseObjectShape>
1364
- extends BaseSchema<Record<string, unknown>> {
1321
+ export interface ObjectSchema<TShape extends LooseObjectShape = LooseObjectShape> extends BaseSchema<
1322
+ Record<string, unknown>
1323
+ > {
1365
1324
  readonly type: 'object';
1366
1325
  readonly shape: Readonly<TShape>;
1367
1326
 
@@ -1594,8 +1553,9 @@ export type RecordObjectShape = {
1594
1553
  export type RecordKeySchema = StringSchema | FormattedStringSchema | LiteralSchema<string>;
1595
1554
  export type RecordObjectSchema = ObjectSchema<RecordObjectShape>;
1596
1555
 
1597
- export interface RecordSchema<TObject extends ObjectSchema, TKey extends RecordKeySchema>
1598
- extends BaseSchema<Record<string, unknown>> {
1556
+ export interface RecordSchema<TObject extends ObjectSchema, TKey extends RecordKeySchema> extends BaseSchema<
1557
+ Record<string, unknown>
1558
+ > {
1599
1559
  readonly type: 'record';
1600
1560
  readonly key: TKey;
1601
1561
  readonly object: TObject;
@@ -1,75 +1,3 @@
1
- const segmenter = new Intl.Segmenter();
2
-
3
- export const getUtf8Length = (str: string): number => {
4
- const len = str.length;
5
-
6
- let u16pos = 0;
7
- let u8pos = 0;
8
-
9
- jump: if (str.charCodeAt(0) < 0x80) {
10
- u16pos++;
11
- u8pos++;
12
-
13
- while (u16pos + 3 < len) {
14
- const a = str.charCodeAt(u16pos);
15
- const b = str.charCodeAt(u16pos + 1);
16
- const c = str.charCodeAt(u16pos + 2);
17
- const d = str.charCodeAt(u16pos + 3);
18
-
19
- if ((a | b | c | d) >= 0x80) {
20
- break jump;
21
- }
22
-
23
- u16pos += 4;
24
- u8pos += 4;
25
- }
26
-
27
- while (u16pos < len) {
28
- const x = str.charCodeAt(u16pos);
29
-
30
- if (x >= 0x80) {
31
- break jump;
32
- }
33
-
34
- u16pos++;
35
- u8pos++;
36
- }
37
-
38
- return u8pos;
39
- }
40
-
41
- while (u16pos < len) {
42
- const code = str.charCodeAt(u16pos);
43
-
44
- if (code < 0x80) {
45
- u16pos += 1;
46
- u8pos += 1;
47
- } else if (code < 0x800) {
48
- u16pos += 1;
49
- u8pos += 2;
50
- } else if (code < 0xd800 || code > 0xdbff) {
51
- u16pos += 1;
52
- u8pos += 3;
53
- } else {
54
- u16pos += 2;
55
- u8pos += 4;
56
- }
57
- }
58
-
59
- return u8pos;
60
- };
61
-
62
- export const getGraphemeLength = (text: string): number => {
63
- const iterator = segmenter.segment(text)[Symbol.iterator]();
64
- let count = 0;
65
-
66
- while (!iterator.next().done) {
67
- count++;
68
- }
69
-
70
- return count;
71
- };
72
-
73
1
  // #__NO_SIDE_EFFECTS__
74
2
  export const lazyProperty = <T>(obj: object, prop: string | number | symbol, value: T): T => {
75
3
  Object.defineProperty(obj, prop, { value });
@@ -102,7 +30,7 @@ export const allowsEval = /*#__PURE__*/ lazy((): boolean => {
102
30
  const F = Function;
103
31
  new F('');
104
32
  return true;
105
- } catch (_) {
33
+ } catch {
106
34
  return false;
107
35
  }
108
36
  });
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@atcute/lexicons",
4
- "version": "1.2.5",
3
+ "version": "1.2.7",
5
4
  "description": "AT Protocol core lexicon types and schema validations",
6
5
  "license": "0BSD",
7
6
  "repository": {
@@ -14,6 +13,8 @@
14
13
  "!lib/**/*.bench.ts",
15
14
  "!lib/**/*.test.ts"
16
15
  ],
16
+ "type": "module",
17
+ "sideEffects": false,
17
18
  "exports": {
18
19
  ".": "./dist/index.js",
19
20
  "./ambient": "./dist/ambient.js",
@@ -21,19 +22,23 @@
21
22
  "./syntax": "./dist/syntax/index.js",
22
23
  "./validations": "./dist/validations/index.js"
23
24
  },
24
- "sideEffects": false,
25
- "devDependencies": {
26
- "@vitest/coverage-v8": "^4.0.7",
27
- "vitest": "^4.0.7",
28
- "@atcute/multibase": "^1.1.6",
29
- "@atcute/cbor": "^2.2.8"
25
+ "publishConfig": {
26
+ "access": "public"
30
27
  },
31
28
  "dependencies": {
32
- "@standard-schema/spec": "^1.0.0",
33
- "esm-env": "^1.2.2"
29
+ "@standard-schema/spec": "^1.1.0",
30
+ "esm-env": "^1.2.2",
31
+ "@atcute/util-text": "^1.1.0",
32
+ "@atcute/uint8array": "^1.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@vitest/coverage-v8": "^4.0.16",
36
+ "vitest": "^4.0.16",
37
+ "@atcute/multibase": "^1.1.7",
38
+ "@atcute/cbor": "^2.3.0"
34
39
  },
35
40
  "scripts": {
36
- "build": "tsc --project tsconfig.build.json",
41
+ "build": "tsgo --project tsconfig.build.json",
37
42
  "test": "vitest --coverage",
38
43
  "prepublish": "rm -rf dist; pnpm run build"
39
44
  }