@based/schema 5.0.0-alpha.18 → 5.0.0-alpha.20

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,18 +1,31 @@
1
1
  import { ALIAS, ALIASES, BINARY, EMPTY_MICRO_BUFFER, CARDINALITY, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, } from './types.js';
2
+ const selvaFieldType = {
3
+ NULL: 0,
4
+ MICRO_BUFFER: 1,
5
+ STRING: 2,
6
+ TEXT: 3,
7
+ REFERENCE: 4,
8
+ REFERENCES: 5,
9
+ WEAK_REFERENCE: 6,
10
+ WEAK_REFERENCES: 7,
11
+ ALIAS: 8,
12
+ ALIASES: 9,
13
+ COLVEC: 10,
14
+ };
2
15
  const selvaTypeMap = new Uint8Array(32); // 1.2x faster than JS array
3
- selvaTypeMap[MICRO_BUFFER] = 1;
4
- selvaTypeMap[VECTOR] = 1;
5
- selvaTypeMap[BINARY] = 2;
6
- selvaTypeMap[CARDINALITY] = 2;
7
- selvaTypeMap[JSON] = 2;
8
- selvaTypeMap[STRING] = 2;
9
- selvaTypeMap[TEXT] = 3;
10
- selvaTypeMap[REFERENCE] = 4;
11
- selvaTypeMap[REFERENCES] = 5;
12
- selvaTypeMap[WEAK_REFERENCE] = 6;
13
- selvaTypeMap[WEAK_REFERENCES] = 7;
14
- selvaTypeMap[ALIAS] = 8;
15
- selvaTypeMap[ALIASES] = 9;
16
+ selvaTypeMap[MICRO_BUFFER] = selvaFieldType.MICRO_BUFFER;
17
+ selvaTypeMap[VECTOR] = selvaFieldType.MICRO_BUFFER;
18
+ selvaTypeMap[BINARY] = selvaFieldType.STRING;
19
+ selvaTypeMap[CARDINALITY] = selvaFieldType.STRING;
20
+ selvaTypeMap[JSON] = selvaFieldType.STRING;
21
+ selvaTypeMap[STRING] = selvaFieldType.STRING;
22
+ selvaTypeMap[TEXT] = selvaFieldType.TEXT;
23
+ selvaTypeMap[REFERENCE] = selvaFieldType.REFERENCE;
24
+ selvaTypeMap[REFERENCES] = selvaFieldType.REFERENCES;
25
+ selvaTypeMap[WEAK_REFERENCE] = selvaFieldType.WEAK_REFERENCE;
26
+ selvaTypeMap[WEAK_REFERENCES] = selvaFieldType.WEAK_REFERENCES;
27
+ selvaTypeMap[ALIAS] = selvaFieldType.ALIAS;
28
+ selvaTypeMap[ALIASES] = selvaFieldType.ALIASES;
16
29
  const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
17
30
  const EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP = 0x80;
18
31
  function blockCapacity(blockCapacity) {
@@ -4,8 +4,7 @@ import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, } from './types.js';
4
4
  import { DEFAULT_MAP } from './defaultMap.js';
5
5
  import { makeSeparateTextSort } from './makeSeparateTextSort.js';
6
6
  import { makeSeparateSort } from './makeSeparateSort.js';
7
- import { getPropLen } from './getPropLen.js';
8
- import { isSeparate, parseMinMaxStep } from './utils.js';
7
+ import { getPropLen, isSeparate, parseMinMaxStep } from './utils.js';
9
8
  import { addEdges } from './addEdges.js';
10
9
  import { createEmptyDef } from './createEmptyDef.js';
11
10
  import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
@@ -64,6 +64,10 @@ export class SchemaParser {
64
64
  expectObject(locales);
65
65
  for (const locale in locales) {
66
66
  const opts = locales[locale];
67
+ if (opts === true) {
68
+ console.log(locale, opts);
69
+ continue;
70
+ }
67
71
  expectObject(opts);
68
72
  for (const key in opts) {
69
73
  const val = opts[key];
@@ -71,7 +75,7 @@ export class SchemaParser {
71
75
  expectBoolean(val);
72
76
  }
73
77
  else if (key === 'fallback') {
74
- if (!Array.isArray(val) || !val.every((v) => typeof v === 'string')) {
78
+ if (Array.isArray(val) || typeof val !== 'string') {
75
79
  throw Error(INVALID_VALUE);
76
80
  }
77
81
  }
@@ -1,5 +1,5 @@
1
1
  import { convertToTimestamp } from '@saulx/utils';
2
- import { NUMBER, TYPE_INDEX_MAP, } from '../def/types.js';
2
+ import { NUMBER, TYPE_INDEX_MAP } from '../def/types.js';
3
3
  import { VALIDATION_MAP } from '../def/validation.js';
4
4
  import { stringFormats, dateDisplays, numberDisplays, } from '../types.js';
5
5
  import { expectBoolean, expectFunction, expectNumber, expectObject, expectString, } from './assert.js';
@@ -208,7 +208,7 @@ p.uint16 = propParser(STUB, numberOpts, 0);
208
208
  p.int32 = propParser(STUB, numberOpts, 0);
209
209
  p.uint32 = propParser(STUB, numberOpts, 0);
210
210
  p.object = propParser({
211
- props(val, prop, ctx) {
211
+ props(val, _prop, ctx) {
212
212
  ctx.parseProps(val, ctx.type);
213
213
  },
214
214
  }, {});
@@ -303,8 +303,12 @@ p.text = propParser({
303
303
  throw Error(TEXT_REQUIRES_LOCALES);
304
304
  },
305
305
  }, {
306
+ compression(val) {
307
+ // return the actualy string!
308
+ return val;
309
+ },
306
310
  format: binaryOpts.format,
307
- default(val, prop) {
311
+ default(_val, _prop) {
308
312
  // console.warn('MAKE DEFAULT VALUE FOR TEXT')
309
313
  return true;
310
314
  },
package/dist/types.d.ts CHANGED
@@ -46,6 +46,7 @@ export type SchemaText = Prop<{
46
46
  type: 'text';
47
47
  default?: Record<string, string>;
48
48
  format?: StringFormat;
49
+ compression?: 'none' | 'deflate';
49
50
  }>;
50
51
  type NumberType = 'number' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32';
51
52
  export type SchemaNumber = Prop<{
@@ -184,9 +185,9 @@ type GenericSchema<isStrict = false> = {
184
185
  };
185
186
  export type StrictSchema = GenericSchema<true>;
186
187
  export type Schema = GenericSchema<false> | StrictSchema;
187
- export type SchemaLocales = Record<LangName, {
188
+ export type SchemaLocales = Record<LangName, true | {
188
189
  required?: boolean;
189
- fallback?: LangName[];
190
+ fallback?: LangName;
190
191
  }>;
191
192
  export type SchemaPropTypeMap = {
192
193
  references: SchemaReferences;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "5.0.0-alpha.18",
3
+ "version": "5.0.0-alpha.20",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -1,3 +0,0 @@
1
- import { SchemaProp } from '../types.js';
2
- export declare function getPropLen(schemaProp: SchemaProp): any;
3
- //# sourceMappingURL=getPropLen.d.ts.map
@@ -1,23 +0,0 @@
1
- import { getPropType } from '../parse/utils.js';
2
- import { isPropType } from '../types.js';
3
- import { SIZE_MAP } from './types.js';
4
- export function getPropLen(schemaProp) {
5
- let len = SIZE_MAP[getPropType(schemaProp)];
6
- if (isPropType('string', schemaProp) ||
7
- isPropType('alias', schemaProp) ||
8
- isPropType('cardinality', schemaProp)) {
9
- if (typeof schemaProp === 'object') {
10
- if (schemaProp.maxBytes < 61) {
11
- len = schemaProp.maxBytes + 1;
12
- }
13
- else if ('max' in schemaProp && schemaProp.max < 31) {
14
- len = schemaProp.max * 2 + 1;
15
- }
16
- }
17
- }
18
- else if (isPropType('vector', schemaProp)) {
19
- len = 4 * schemaProp.size;
20
- }
21
- return len;
22
- }
23
- //# sourceMappingURL=getPropLen.js.map