@based/schema 5.0.0-alpha.0 → 5.0.0-alpha.2

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/lang.d.ts CHANGED
@@ -145,7 +145,8 @@ declare const langCodes: {
145
145
  readonly yo: 143;
146
146
  readonly zu: 144;
147
147
  };
148
- export declare const langCodesMap: Map<string, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144>;
148
+ export declare const langCodesMap: Map<string, 0 | 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144>;
149
+ export declare const inverseLangMap: Map<any, any>;
149
150
  export type LangName = keyof typeof langCodes;
150
151
  export type LangCode = (typeof langCodes)[LangName];
151
152
  export {};
package/dist/lang.js CHANGED
@@ -146,4 +146,8 @@ const langCodes = {
146
146
  zu: 144,
147
147
  };
148
148
  export const langCodesMap = new Map(Object.entries(langCodes));
149
+ export const inverseLangMap = new Map();
150
+ langCodesMap.forEach((v, k) => {
151
+ inverseLangMap.set(v, k);
152
+ });
149
153
  //# sourceMappingURL=lang.js.map
@@ -1,4 +1,5 @@
1
1
  export declare const expectObject: (obj: any, msg?: string) => void;
2
+ export declare const expectFloat32Array: (arr: any) => void;
2
3
  export declare const expectString: (obj: any) => void;
3
4
  export declare const expectBoolean: (v: any) => void;
4
5
  export declare const expectFunction: (v: any) => void;
@@ -1,9 +1,15 @@
1
- import { EXPECTED_BOOL, EXPECTED_FN, EXPECTED_NUM, EXPECTED_OBJ, EXPECTED_STR, } from './errors.js';
1
+ import { isFloat32Array } from 'util/types';
2
+ import { EXPECTED_ARR, EXPECTED_BOOL, EXPECTED_FN, EXPECTED_NUM, EXPECTED_OBJ, EXPECTED_STR, } from './errors.js';
2
3
  export const expectObject = (obj, msg) => {
3
4
  if (typeof obj !== 'object' || obj === null) {
4
5
  throw Error(msg || EXPECTED_OBJ);
5
6
  }
6
7
  };
8
+ export const expectFloat32Array = (arr) => {
9
+ if (!isFloat32Array(arr)) {
10
+ throw Error(EXPECTED_ARR);
11
+ }
12
+ };
7
13
  export const expectString = (obj) => {
8
14
  if (typeof obj !== 'string') {
9
15
  throw Error(EXPECTED_STR);
@@ -20,7 +20,7 @@ export class SchemaParser {
20
20
  expectObject(types);
21
21
  for (const type in types) {
22
22
  this.lvl++;
23
- if (type[0] === '_') {
23
+ if (type === '_root') {
24
24
  throw new Error(INVALID_KEY);
25
25
  }
26
26
  this.path[this.lvl] = type;
@@ -1,5 +1,5 @@
1
1
  import { stringFormats, dateDisplays, numberDisplays, } from '../types.js';
2
- import { expectBoolean, expectFunction, expectObject, expectString, expectNumber, } from './assert.js';
2
+ import { expectBoolean, expectFloat32Array, expectFunction, expectNumber, expectObject, expectString, } from './assert.js';
3
3
  import { EXPECTED_ARR, EXPECTED_DATE, EXPECTED_OBJ, EXPECTED_PRIMITIVE, EXPECTED_VALUE_IN_ENUM, INVALID_VALUE, MIN_MAX, MISSING_TYPE, OUT_OF_RANGE, TEXT_REQUIRES_LOCALES, TYPE_MISMATCH, UNKNOWN_PROP, NOT_ALLOWED_IN_ITEMS, } from './errors.js';
4
4
  import { getPropType } from './utils.js';
5
5
  let stringFormatsSet;
@@ -96,6 +96,15 @@ p.boolean = propParser(STUB, {
96
96
  expectBoolean(val);
97
97
  },
98
98
  }, 0);
99
+ p.vector = propParser({
100
+ size(val) {
101
+ expectNumber(val);
102
+ },
103
+ }, {
104
+ default(val) {
105
+ expectFloat32Array(val);
106
+ },
107
+ }, 0);
99
108
  p.enum = propParser({
100
109
  enum(items) {
101
110
  if (!Array.isArray(items)) {
@@ -373,10 +382,15 @@ p.alias = propParser(STUB, {
373
382
  },
374
383
  format: binaryOpts.format,
375
384
  }, 0);
376
- p.hll = propParser(STUB, {
385
+ p.cardinality = propParser(STUB, {
377
386
  default(val) {
378
387
  expectNumber(val);
379
388
  },
380
389
  }, 0);
390
+ p.json = propParser(STUB, {
391
+ default(val) {
392
+ expectObject(val);
393
+ },
394
+ }, 0);
381
395
  export default p;
382
396
  //# sourceMappingURL=props.js.map
package/dist/types.d.ts CHANGED
@@ -49,6 +49,9 @@ export type SchemaNumber = Prop<{
49
49
  max?: number;
50
50
  step?: number | 'any';
51
51
  display?: NumberDisplay;
52
+ history?: {
53
+ interval: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
54
+ };
52
55
  }>;
53
56
  export type SchemaString = Prop<{
54
57
  type: 'string';
@@ -67,13 +70,25 @@ export type SchemaBinary = Prop<{
67
70
  mime?: Mime;
68
71
  format?: StringFormat;
69
72
  }>;
73
+ export type SchemaJson = Prop<{
74
+ type: 'json';
75
+ default?: Record<string, any> | null;
76
+ }>;
70
77
  export type SchemaBoolean = Prop<{
71
78
  type: 'boolean';
72
79
  default?: boolean;
73
80
  }>;
74
- export type SchemaHll = Prop<{
75
- type: 'hll';
76
- default?: number;
81
+ export type SchemaCardinality = Prop<{
82
+ type: 'cardinality';
83
+ default?: string;
84
+ maxBytes?: number;
85
+ mime?: Mime;
86
+ format?: NumberDisplay;
87
+ }>;
88
+ export type SchemaVector = Prop<{
89
+ type: 'vector';
90
+ default?: Float32Array;
91
+ size: number;
77
92
  }>;
78
93
  export type SchemaTimestamp = Prop<{
79
94
  type: 'timestamp';
@@ -117,7 +132,7 @@ export type SchemaEnum = Prop<{
117
132
  export type SchemaAlias = Omit<SchemaString, 'type'> & {
118
133
  type: 'alias';
119
134
  };
120
- export type SchemaPropShorthand = 'timestamp' | 'binary' | 'boolean' | 'string' | 'alias' | 'text' | 'hll' | NumberType | EnumItem[];
135
+ export type SchemaPropShorthand = 'timestamp' | 'binary' | 'boolean' | 'string' | 'alias' | 'text' | 'json' | 'cardinality' | NumberType | EnumItem[];
121
136
  type SetItems<isStrict = false> = SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaEnum | (isStrict extends true ? never : 'timestamp' | 'binary' | 'boolean' | 'string' | NumberType | EnumItem[]);
122
137
  export type SchemaSet<ItemsType extends SetItems = SetItems> = Prop<{
123
138
  type?: 'set';
@@ -126,7 +141,7 @@ export type SchemaSet<ItemsType extends SetItems = SetItems> = Prop<{
126
141
  } ? ItemsType['default'][] : undefined;
127
142
  items: ItemsType & NeverInItems;
128
143
  }>;
129
- type NonRefSchemaProps<isStrict = false> = SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaAlias | SchemaText | SchemaEnum | SchemaBinary | SchemaHll | (isStrict extends true ? SchemaSet<SetItems<true>> : SchemaPropShorthand | SchemaSet);
144
+ type NonRefSchemaProps<isStrict = false> = SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaAlias | SchemaText | SchemaEnum | SchemaJson | SchemaBinary | SchemaCardinality | SchemaVector | (isStrict extends true ? SchemaSet<SetItems<true>> : SchemaPropShorthand | SchemaSet);
130
145
  export type SchemaProp<isStrict = false> = SchemaReferencesWithQuery | SchemaReferenceWithQuery | NonRefSchemaProps<isStrict> | SchemaReferences | SchemaReference | SchemaObject | SchemaBinary;
131
146
  export type SchemaPropOneWay<isStrict = false> = SchemaReferencesOneWay | SchemaReferenceOneWay | SchemaObjectOneWay | NonRefSchemaProps<isStrict>;
132
147
  export type SchemaAnyProp = SchemaPropOneWay | SchemaProp;
@@ -147,8 +162,10 @@ export type StrictSchemaType = GenericSchemaType<true>;
147
162
  export type SchemaType<isStrict = false> = isStrict extends true ? StrictSchemaType : StrictSchemaType | GenericSchemaType<false> | (SchemaProps & {
148
163
  props?: never;
149
164
  });
150
- export type SchemaTypeName = AllowedKey;
151
- export type SchemaTypes<isStrict = false> = Record<SchemaTypeName, SchemaType<isStrict>>;
165
+ export type SchemaTypeName = Exclude<string, '_root'>;
166
+ export type SchemaTypes<isStrict = false> = Record<SchemaTypeName, SchemaType<isStrict>> & {
167
+ _root?: never;
168
+ };
152
169
  export type SchemaPropsOneWay<isStrict = false> = Record<AllowedKey, SchemaPropOneWay<isStrict>> & {
153
170
  id?: never;
154
171
  };
@@ -173,9 +190,11 @@ export type SchemaPropTypeMap = {
173
190
  alias: SchemaAlias;
174
191
  enum: SchemaEnum;
175
192
  text: SchemaText;
193
+ json: SchemaJson;
176
194
  set: SchemaSet;
177
195
  binary: SchemaBinary;
178
- hll: SchemaHll;
196
+ cardinality: SchemaCardinality;
197
+ vector: SchemaVector;
179
198
  } & Record<NumberType, SchemaNumber>;
180
199
  export type SchemaPropTypes = keyof SchemaPropTypeMap;
181
200
  export declare const isPropType: <T extends SchemaPropTypes>(type: T, prop: SchemaProp) => prop is SchemaPropTypeMap[T];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "5.0.0-alpha.0",
3
+ "version": "5.0.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [