@based/schema 5.1.3 → 5.1.4

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.
@@ -11,7 +11,7 @@ export const fillEmptyMain = (vals, mainLen) => {
11
11
  const s = f.start;
12
12
  let val = f.default;
13
13
  if (t === ENUM) {
14
- mainEmpty[s] = f.default ?? 0;
14
+ mainEmpty[s] = f.default ? (f.enum?.indexOf(f.default) ?? -1) + 1 : 0;
15
15
  }
16
16
  else if (t === INT8 || t === UINT8) {
17
17
  mainEmpty[s] = val;
@@ -201,6 +201,7 @@ const createSchemaTypeDef = (typeName, type, locales, result = createEmptyDef(ty
201
201
  prop.inversePropName = schemaProp.items.prop;
202
202
  prop.inverseTypeName = schemaProp.items.ref;
203
203
  prop.dependent = schemaProp.items.dependent;
204
+ prop.referencesCapped = schemaProp.capped ?? 0;
204
205
  addEdges(prop, schemaProp.items);
205
206
  }
206
207
  else if (isPropType('reference', schemaProp)) {
@@ -23,15 +23,16 @@ export type PropDef = {
23
23
  path: string[];
24
24
  start: number;
25
25
  len: number;
26
- inverseTypeName?: string;
27
- inversePropName?: string;
28
26
  compression?: 0 | 1;
29
- inverseTypeId?: number;
30
- inversePropNumber?: number;
31
27
  enum?: any[];
32
28
  dependent?: boolean;
33
29
  validation: Validation;
34
30
  default: any;
31
+ inverseTypeName?: string;
32
+ inversePropName?: string;
33
+ inverseTypeId?: number;
34
+ inversePropNumber?: number;
35
+ referencesCapped?: number;
35
36
  vectorBaseType?: VectorBaseType;
36
37
  vectorSize?: number;
37
38
  cardinalityMode?: number;
@@ -149,12 +149,12 @@ export const isDefault = (val, prop, ctx) => {
149
149
  if (!validation(val, tmpProp)) {
150
150
  throw new Error(`Incorrect default for type "${prop.type ?? 'enum'}"`);
151
151
  }
152
- if ('enum' in prop) {
153
- if (val === undefined) {
154
- return 0;
155
- }
156
- return prop.enum.findIndex((v) => v === val) + 1;
157
- }
152
+ // if ('enum' in prop) {
153
+ // if (val === undefined) {
154
+ // return 0
155
+ // }
156
+ // return prop.enum.findIndex((v) => v === val) + 1
157
+ // }
158
158
  return val;
159
159
  };
160
160
  p.boolean = propParser(STUB, {
@@ -276,6 +276,12 @@ p.references = propParser({
276
276
  throw new Error(INVALID_VALUE);
277
277
  }
278
278
  },
279
+ capped(val) {
280
+ if (val !== undefined &&
281
+ (typeof val !== 'number' || val < 0 || !Number.isInteger(val))) {
282
+ throw Error(INVALID_VALUE);
283
+ }
284
+ },
279
285
  }, {
280
286
  default(val, prop, ctx) {
281
287
  return isDefault(val, prop, ctx);
package/dist/types.d.ts CHANGED
@@ -27,6 +27,7 @@ type NeverInItems = {
27
27
  export type SchemaReferences = Prop<{
28
28
  type?: 'references';
29
29
  default?: number[];
30
+ capped?: number;
30
31
  items: SchemaReference & NeverInItems;
31
32
  }>;
32
33
  export type SchemaReferencesOneWay = Prop<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "README.md",