@delali/narsil 0.3.1-next.79 → 0.3.1-next.82
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/README.md +3 -3
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/indexeddb.mjs +1 -1
- package/dist/{capabilities-1lEYL3WK.d.ts → capabilities-CAdkp2P-.d.ts} +2 -2
- package/dist/{chunk-XSZTF4ZQ.mjs → chunk-2453RJYK.mjs} +2 -2
- package/dist/{chunk-DFW3U5UW.mjs → chunk-4CWHWOBI.mjs} +24 -195
- package/dist/{chunk-R6WBLBTC.mjs → chunk-4D6OH4EF.mjs} +10 -46
- package/dist/{chunk-RTR44V2A.mjs → chunk-4VBG6PEH.mjs} +586 -4
- package/dist/{chunk-Y3L5MDRV.mjs → chunk-5XNIRLFC.mjs} +2 -2
- package/dist/{chunk-2E35UM3G.mjs → chunk-B3UOQJD3.mjs} +1 -1
- package/dist/{chunk-PJWG547Z.mjs → chunk-GNYXCLJS.mjs} +5 -5
- package/dist/{chunk-55WEJKWT.mjs → chunk-IH3GKNDQ.mjs} +197 -93
- package/dist/{chunk-AMGDG4ZJ.mjs → chunk-IN5CH4P2.mjs} +3 -3
- package/dist/{chunk-PXDQFYD5.mjs → chunk-KJ7LB3TR.mjs} +24 -140
- package/dist/chunk-LS5IRM23.mjs +140 -0
- package/dist/{chunk-4MQ5F4IL.mjs → chunk-OLXM65YH.mjs} +1 -1
- package/dist/{chunk-IBR6634K.mjs → chunk-R6A773WK.mjs} +2 -69
- package/dist/{chunk-4344I4MR.mjs → chunk-SREPGC6O.mjs} +336 -13
- package/dist/{chunk-I64LXKO3.mjs → chunk-TPJU7NDJ.mjs} +1 -0
- package/dist/chunk-WQBCBKY3.mjs +8 -0
- package/dist/{chunk-P2BEMMOD.mjs → chunk-XYDP7CCJ.mjs} +151 -204
- package/dist/{chunk-Z3BXCZXS.mjs → chunk-XZF4LZ3X.mjs} +5 -3
- package/dist/chunk-YTJCGKM4.mjs +56 -0
- package/dist/chunk-ZCKPRCYI.mjs +30 -0
- package/dist/{client-ZXcbSViH.d.ts → client-CKUtkLz3.d.ts} +2 -2
- package/dist/client.d.ts +7 -7
- package/dist/client.mjs +1 -0
- package/dist/{config-DHL2KsfD.d.ts → config-BuIkeM5C.d.ts} +39 -3
- package/dist/{config-DTe5EbWW.d.ts → config-CSDEPraV.d.ts} +1 -1
- package/dist/direct-executor-JVXDR5Y5.mjs +19 -0
- package/dist/distribution/coordinator/etcd.d.ts +1 -1
- package/dist/distribution/coordinator/etcd.mjs +3 -2
- package/dist/distribution/coordinator/in-memory.d.ts +1 -1
- package/dist/distribution/coordinator/in-memory.mjs +2 -1
- package/dist/distribution/transport/grpc.mjs +1 -1
- package/dist/distribution.d.ts +7 -7
- package/dist/distribution.mjs +759 -65
- package/dist/embeddings/openai.mjs +1 -1
- package/dist/{engine-BjPBzWkA.d.ts → engine-DMNZJAUq.d.ts} +1 -1
- package/dist/{types-ChrVy4lH.d.ts → index-DzONZUKE.d.ts} +79 -37
- package/dist/index.browser.mjs +138 -539
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +17 -15
- package/dist/invalidation/filesystem.mjs +2 -1
- package/dist/{memory-DW3OJ0im.d.ts → memory-BPKNx9Tl.d.ts} +1288 -1287
- package/dist/partial-words.mjs +6 -5
- package/dist/pattern.mjs +5 -2
- package/dist/persistence/durability/checkpoint-worker.d.ts +7 -7
- package/dist/persistence/durability/checkpoint-worker.mjs +17 -15
- package/dist/react.d.ts +6 -6
- package/dist/react.mjs +1 -0
- package/dist/server.d.ts +9 -9
- package/dist/server.mjs +21 -13
- package/dist/{tasks-BTbwBqar.d.ts → tasks-DGyz586z.d.ts} +1 -1
- package/dist/{thread-XBDVXKUE.mjs → thread-33M5AOEI.mjs} +13 -10
- package/dist/vector/search-worker.mjs +5 -4
- package/dist/workers/entry.mjs +5 -5
- package/package.json +13 -7
- package/dist/chunk-IOZPBNSG.mjs +0 -55
- package/dist/chunk-WFVOBZS4.mjs +0 -485
- package/dist/direct-executor-WB2HKU4N.mjs +0 -17
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
|
|
2
|
+
|
|
3
|
+
// src/schema/constants.ts
|
|
4
|
+
var MAX_NESTING_DEPTH = 4;
|
|
5
|
+
var MAX_DOCUMENT_NESTING_DEPTH = 32;
|
|
6
|
+
var DEFAULT_PATTERN_VALUE_LIMIT = 8192;
|
|
7
|
+
var MIN_PATTERN_VALUE_LIMIT = 1;
|
|
8
|
+
var MAX_PATTERN_VALUE_LIMIT = 65536;
|
|
9
|
+
var MAX_VECTOR_DIMENSION = 4096;
|
|
10
|
+
var MAX_STORED_VECTOR_DIMENSION = 65535;
|
|
11
|
+
var MAX_TEXT_FIELDS = 65536;
|
|
12
|
+
var MAX_DOCUMENT_BYTES = 16777216;
|
|
13
|
+
var PARSED_FIELD_TYPE_CACHE_ENTRIES = 1024;
|
|
14
|
+
|
|
15
|
+
// src/schema/validator/shared.ts
|
|
16
|
+
var VECTOR_PATTERN = /^vector\[(\d+)]$/;
|
|
17
|
+
function isGeopointOrVectorType(fieldType) {
|
|
18
|
+
return fieldType === "geopoint" || fieldType !== void 0 && VECTOR_PATTERN.test(fieldType);
|
|
19
|
+
}
|
|
20
|
+
var FIELD_NAME_PATTERN = /^[A-Za-z0-9_]+$/;
|
|
21
|
+
var RESERVED_ROOT_FIELDS = /* @__PURE__ */ new Set(["id"]);
|
|
22
|
+
var PROTOTYPE_POLLUTION_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/schema/validator/field-type.ts
|
|
28
|
+
var FIELD_OPTION_ORDER = ["sortable", "pattern", "partial"];
|
|
29
|
+
var OPTIONS_BY_BASE = {
|
|
30
|
+
string: FIELD_OPTION_ORDER,
|
|
31
|
+
"string[]": FIELD_OPTION_ORDER,
|
|
32
|
+
verbatim: ["sortable"],
|
|
33
|
+
"verbatim[]": ["sortable"],
|
|
34
|
+
number: [],
|
|
35
|
+
"number[]": [],
|
|
36
|
+
boolean: [],
|
|
37
|
+
"boolean[]": [],
|
|
38
|
+
enum: [],
|
|
39
|
+
"enum[]": [],
|
|
40
|
+
geopoint: [],
|
|
41
|
+
vector: []
|
|
42
|
+
};
|
|
43
|
+
var TYPE_SEPARATOR = ":";
|
|
44
|
+
function isNamedBase(name) {
|
|
45
|
+
return name !== "vector" && Object.hasOwn(OPTIONS_BY_BASE, name);
|
|
46
|
+
}
|
|
47
|
+
function describeAllowedOptions(baseName, allowed) {
|
|
48
|
+
if (allowed.length === 0) return `the "${baseName}" type has no options`;
|
|
49
|
+
const quoted = allowed.map((option) => `"${option}"`);
|
|
50
|
+
if (quoted.length === 1) return `the only option of the "${baseName}" type is ${quoted[0]}`;
|
|
51
|
+
return `the options of the "${baseName}" type are ${quoted.slice(0, -1).join(", ")}, and ${quoted[quoted.length - 1]}`;
|
|
52
|
+
}
|
|
53
|
+
function invalidType(path, type, message) {
|
|
54
|
+
throw new NarsilError(ErrorCodes.SCHEMA_INVALID_TYPE, message, { field: path, type });
|
|
55
|
+
}
|
|
56
|
+
function parseBase(baseName, path, type) {
|
|
57
|
+
if (isNamedBase(baseName)) return { base: baseName, dimension: 0 };
|
|
58
|
+
const vectorMatch = VECTOR_PATTERN.exec(baseName);
|
|
59
|
+
if (vectorMatch === null) {
|
|
60
|
+
invalidType(path, type, `Field "${path}" has an unsupported type: "${type}"`);
|
|
61
|
+
}
|
|
62
|
+
const dimension = Number.parseInt(vectorMatch[1], 10);
|
|
63
|
+
if (dimension <= 0 || dimension > MAX_STORED_VECTOR_DIMENSION) {
|
|
64
|
+
throw new NarsilError(
|
|
65
|
+
ErrorCodes.SCHEMA_INVALID_VECTOR_DIMENSION,
|
|
66
|
+
`Vector field "${path}" has ${dimension} dimensions, but a vector field holds from 1 to ${MAX_STORED_VECTOR_DIMENSION}`,
|
|
67
|
+
{ field: path, dimension, maximum: MAX_STORED_VECTOR_DIMENSION }
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return { base: "vector", dimension };
|
|
71
|
+
}
|
|
72
|
+
function parseFieldType(type, path) {
|
|
73
|
+
const separatorIndex = type.indexOf(TYPE_SEPARATOR);
|
|
74
|
+
const baseName = separatorIndex === -1 ? type : type.slice(0, separatorIndex);
|
|
75
|
+
const { base, dimension } = parseBase(baseName, path, type);
|
|
76
|
+
const allowed = OPTIONS_BY_BASE[base];
|
|
77
|
+
const options = /* @__PURE__ */ new Set();
|
|
78
|
+
if (separatorIndex !== -1) {
|
|
79
|
+
for (const option of type.slice(separatorIndex + 1).split(TYPE_SEPARATOR)) {
|
|
80
|
+
if (!allowed.includes(option)) {
|
|
81
|
+
invalidType(
|
|
82
|
+
path,
|
|
83
|
+
type,
|
|
84
|
+
`Field "${path}" has type "${type}" with the option "${option}", but ${describeAllowedOptions(baseName, allowed)}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (options.has(option)) {
|
|
88
|
+
invalidType(path, type, `Field "${path}" has the "${option}" option twice in type "${type}"`);
|
|
89
|
+
}
|
|
90
|
+
options.add(option);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const ordered = FIELD_OPTION_ORDER.filter((option) => options.has(option));
|
|
94
|
+
const verbatim = base === "verbatim" || base === "verbatim[]";
|
|
95
|
+
return {
|
|
96
|
+
type: [baseName, ...ordered].join(TYPE_SEPARATOR),
|
|
97
|
+
base,
|
|
98
|
+
sortable: options.has("sortable"),
|
|
99
|
+
pattern: verbatim || options.has("pattern"),
|
|
100
|
+
partial: options.has("partial"),
|
|
101
|
+
dimension
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
var parsedTypesByName = /* @__PURE__ */ new Map();
|
|
105
|
+
function parsedTypeOf(type) {
|
|
106
|
+
if (type === void 0) return void 0;
|
|
107
|
+
const known = parsedTypesByName.get(type);
|
|
108
|
+
if (known !== void 0) return known;
|
|
109
|
+
try {
|
|
110
|
+
const parsed = Object.freeze(parseFieldType(type, ""));
|
|
111
|
+
if (parsedTypesByName.size < PARSED_FIELD_TYPE_CACHE_ENTRIES) parsedTypesByName.set(type, parsed);
|
|
112
|
+
return parsed;
|
|
113
|
+
} catch {
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function withSortableOption(parsed) {
|
|
118
|
+
if (parsed.sortable) return parsed.type;
|
|
119
|
+
const separatorIndex = parsed.type.indexOf(TYPE_SEPARATOR);
|
|
120
|
+
const baseName = separatorIndex === -1 ? parsed.type : parsed.type.slice(0, separatorIndex);
|
|
121
|
+
return parseFieldType(`${baseName}${TYPE_SEPARATOR}sortable${parsed.type.slice(baseName.length)}`, "").type;
|
|
122
|
+
}
|
|
123
|
+
function isListBase(base) {
|
|
124
|
+
return base.endsWith("[]");
|
|
125
|
+
}
|
|
126
|
+
function isWordIndexedBase(base) {
|
|
127
|
+
return base === "string" || base === "string[]";
|
|
128
|
+
}
|
|
129
|
+
function isSingleStringFieldType(fieldType) {
|
|
130
|
+
return parsedTypeOf(fieldType)?.base === "string";
|
|
131
|
+
}
|
|
132
|
+
function isWordIndexedFieldType(fieldType) {
|
|
133
|
+
const parsed = parsedTypeOf(fieldType);
|
|
134
|
+
return parsed !== void 0 && isWordIndexedBase(parsed.base);
|
|
135
|
+
}
|
|
136
|
+
function isStringValuedBase(base) {
|
|
137
|
+
return base === "string" || base === "string[]" || base === "verbatim" || base === "verbatim[]";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { DEFAULT_PATTERN_VALUE_LIMIT, FIELD_NAME_PATTERN, MAX_DOCUMENT_BYTES, MAX_DOCUMENT_NESTING_DEPTH, MAX_NESTING_DEPTH, MAX_PATTERN_VALUE_LIMIT, MAX_STORED_VECTOR_DIMENSION, MAX_TEXT_FIELDS, MAX_VECTOR_DIMENSION, MIN_PATTERN_VALUE_LIMIT, PROTOTYPE_POLLUTION_KEYS, RESERVED_ROOT_FIELDS, VECTOR_PATTERN, isGeopointOrVectorType, isListBase, isPlainObject, isSingleStringFieldType, isStringValuedBase, isWordIndexedBase, isWordIndexedFieldType, parseFieldType, parsedTypeOf, withSortableOption };
|
|
@@ -1,57 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function exceedsCodePoints(value, maximum) {
|
|
3
|
-
if (value.length <= maximum) return false;
|
|
4
|
-
let counted = 0;
|
|
5
|
-
let i = 0;
|
|
6
|
-
while (i < value.length) {
|
|
7
|
-
const unit = value.charCodeAt(i);
|
|
8
|
-
if (unit >= 55296 && unit < 56320 && i + 1 < value.length) {
|
|
9
|
-
const low = value.charCodeAt(i + 1);
|
|
10
|
-
if (low >= 56320 && low < 57344) i++;
|
|
11
|
-
}
|
|
12
|
-
i++;
|
|
13
|
-
counted++;
|
|
14
|
-
if (counted > maximum) return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
var SURROGATE_UNIT = /[\ud800-\udfff]/;
|
|
19
|
-
function holdsUnpairedSurrogate(value) {
|
|
20
|
-
if (!SURROGATE_UNIT.test(value)) return false;
|
|
21
|
-
for (let i = 0; i < value.length; i++) {
|
|
22
|
-
const unit = value.charCodeAt(i);
|
|
23
|
-
if (unit < 55296 || unit >= 57344) continue;
|
|
24
|
-
if (unit >= 56320) return true;
|
|
25
|
-
const low = value.charCodeAt(i + 1);
|
|
26
|
-
if (!(low >= 56320 && low < 57344)) return true;
|
|
27
|
-
i++;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
function codePointCount(value) {
|
|
32
|
-
let counted = 0;
|
|
33
|
-
for (let i = 0; i < value.length; i++) {
|
|
34
|
-
const unit = value.charCodeAt(i);
|
|
35
|
-
if (unit >= 55296 && unit < 56320 && i + 1 < value.length) {
|
|
36
|
-
const low = value.charCodeAt(i + 1);
|
|
37
|
-
if (low >= 56320 && low < 57344) i++;
|
|
38
|
-
}
|
|
39
|
-
counted++;
|
|
40
|
-
}
|
|
41
|
-
return counted;
|
|
42
|
-
}
|
|
43
|
-
function adjustUtf16Unit(unit) {
|
|
44
|
-
if (unit < 55296) return unit;
|
|
45
|
-
if (unit < 57344) return unit + 8192;
|
|
46
|
-
return unit - 2048;
|
|
47
|
-
}
|
|
48
|
-
function compareCodePoints(a, b) {
|
|
49
|
-
const shorter = a.length < b.length ? a.length : b.length;
|
|
50
|
-
let i = 0;
|
|
51
|
-
while (i < shorter && a.charCodeAt(i) === b.charCodeAt(i)) i++;
|
|
52
|
-
if (i === shorter) return a.length - b.length;
|
|
53
|
-
return adjustUtf16Unit(a.charCodeAt(i)) - adjustUtf16Unit(b.charCodeAt(i));
|
|
54
|
-
}
|
|
1
|
+
import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
|
|
55
2
|
|
|
56
3
|
// src/core/ordering/fold-table.ts
|
|
57
4
|
var SINGLE_FOLDS = "1t,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;2j,lj;b,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;1,w;2,w;1,w;1,w;1,w;1,w;1,w;1,w;y,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;4,1;2,1;2,1;3,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;3,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,1;2,-3d;1,1;2,1;2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;1,r;1,r;1,r;1,r;1,r;1,r;1,r;1,r;o5k,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;1,y;";
|
|
@@ -155,20 +102,6 @@ function appendFoldedCodePoint(codePoint, out) {
|
|
|
155
102
|
}
|
|
156
103
|
for (const foldedCodePoint of folded) out.push(foldedCodePoint);
|
|
157
104
|
}
|
|
158
|
-
function appendFoldedCodePoints(text, out) {
|
|
159
|
-
const single = singleFoldTable();
|
|
160
|
-
const multi = multiFoldTable();
|
|
161
|
-
const cursor = { index: 0, pending: null, pendingIndex: 0 };
|
|
162
|
-
for (let codePoint = nextFoldedCodePoint(text, cursor, single, multi); codePoint !== EXHAUSTED; ) {
|
|
163
|
-
out.push(codePoint);
|
|
164
|
-
codePoint = nextFoldedCodePoint(text, cursor, single, multi);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function foldedCodePointCount(text) {
|
|
168
|
-
const folded = [];
|
|
169
|
-
appendFoldedCodePoints(text, folded);
|
|
170
|
-
return folded.length;
|
|
171
|
-
}
|
|
172
105
|
|
|
173
106
|
// src/core/ordering/constants.ts
|
|
174
107
|
var SORT_VALUE_MAX_CODE_POINTS = 512;
|
|
@@ -290,4 +223,4 @@ function compareSortValues(aValues, bValues, directions) {
|
|
|
290
223
|
return 0;
|
|
291
224
|
}
|
|
292
225
|
|
|
293
|
-
export { SORT_MODES, SORT_VALUE_MAX_CODE_POINTS, appendFoldedCodePoint,
|
|
226
|
+
export { SORT_MODES, SORT_VALUE_MAX_CODE_POINTS, appendFoldedCodePoint, compareComparableKeys, compareComparableValues, compareSortValues, defaultSortMode, isSortMode, readSortField, singleFoldTable, sortModeOf, toComparableSortValue, toReducedSortValue, truncateSortString };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { MAX_FILTER_ARRAY_SIZE } from './chunk-WQBCBKY3.mjs';
|
|
1
2
|
import { tabulatedLevenshtein } from './chunk-GES7U2PM.mjs';
|
|
2
|
-
import {
|
|
3
|
+
import { parsedTypeOf } from './chunk-LS5IRM23.mjs';
|
|
4
|
+
import { codePointCount, exceedsCodePoints } from './chunk-YTJCGKM4.mjs';
|
|
5
|
+
import { NarsilError, ErrorCodes } from './chunk-TPJU7NDJ.mjs';
|
|
3
6
|
|
|
4
7
|
// src/core/bitset.ts
|
|
5
8
|
function createBitSet(capacity) {
|
|
@@ -76,6 +79,7 @@ var PATTERN_RUN_CODE_POINTS = 3;
|
|
|
76
79
|
var MAX_PATTERN_TOLERANCE = 2;
|
|
77
80
|
var PATTERN_TEST_OPERATORS = ["eq", "ne", "in", "nin", "startsWith", "endsWith", "contains"];
|
|
78
81
|
var PATTERN_EXPRESSION_OPERATORS = ["wildcard", "regex"];
|
|
82
|
+
var PATTERN_ELEMENT_OPERATORS = ["matchesAny", "containsAll"];
|
|
79
83
|
|
|
80
84
|
// src/pattern/constants.ts
|
|
81
85
|
var MATCHER_TRANSITION_BYTES = 48;
|
|
@@ -503,6 +507,26 @@ function compileProgram(plan) {
|
|
|
503
507
|
return { ...draft, anchoredStart: startsOnlyAtStart(draft) };
|
|
504
508
|
}
|
|
505
509
|
|
|
510
|
+
// src/pattern/fold-sources.ts
|
|
511
|
+
var NO_SOURCES = [];
|
|
512
|
+
var sourcesByTable = /* @__PURE__ */ new WeakMap();
|
|
513
|
+
function sourcesByFold(table) {
|
|
514
|
+
const known = sourcesByTable.get(table);
|
|
515
|
+
if (known !== void 0) return known;
|
|
516
|
+
const sources = /* @__PURE__ */ new Map();
|
|
517
|
+
for (const [source, folded] of table) {
|
|
518
|
+
const listed = sources.get(folded);
|
|
519
|
+
if (listed === void 0) sources.set(folded, [source]);
|
|
520
|
+
else listed.push(source);
|
|
521
|
+
}
|
|
522
|
+
sourcesByTable.set(table, sources);
|
|
523
|
+
return sources;
|
|
524
|
+
}
|
|
525
|
+
function singleFoldSourcesOf(host) {
|
|
526
|
+
const sources = sourcesByFold(host.singleFolds());
|
|
527
|
+
return (folded) => sources.get(folded) ?? NO_SOURCES;
|
|
528
|
+
}
|
|
529
|
+
|
|
506
530
|
// src/pattern/expression/code-point-tests.ts
|
|
507
531
|
var CLASS_RANGES = {
|
|
508
532
|
digit: [48, 57],
|
|
@@ -550,15 +574,16 @@ function rangeTest(ranges, negated) {
|
|
|
550
574
|
};
|
|
551
575
|
}
|
|
552
576
|
function foldedRangeTest(ranges, negated, host) {
|
|
577
|
+
const singleFoldSources = singleFoldSourcesOf(host);
|
|
553
578
|
const holdsFold = (folded) => {
|
|
554
579
|
if (inRanges(ranges, folded)) return true;
|
|
555
|
-
for (const source of
|
|
580
|
+
for (const source of singleFoldSources(folded)) if (inRanges(ranges, source)) return true;
|
|
556
581
|
return false;
|
|
557
582
|
};
|
|
558
583
|
return {
|
|
559
584
|
bytes: ranges.byteLength + CODE_POINT_TEST_ENTRY_BYTES,
|
|
560
585
|
ranges,
|
|
561
|
-
isFoldTarget: (folded) =>
|
|
586
|
+
isFoldTarget: (folded) => singleFoldSources(folded).length > 0,
|
|
562
587
|
has: (folded) => holdsFold(folded) !== negated
|
|
563
588
|
};
|
|
564
589
|
}
|
|
@@ -1086,6 +1111,11 @@ function appendTextCodePoints(text, caseFold, host, out) {
|
|
|
1086
1111
|
else out.push(codePoint);
|
|
1087
1112
|
}
|
|
1088
1113
|
}
|
|
1114
|
+
function foldedCodePointCount(text, host) {
|
|
1115
|
+
const folded = [];
|
|
1116
|
+
appendTextCodePoints(text, true, host, folded);
|
|
1117
|
+
return folded.length;
|
|
1118
|
+
}
|
|
1089
1119
|
function runKey(first, second, third) {
|
|
1090
1120
|
return String.fromCodePoint(first, second, third);
|
|
1091
1121
|
}
|
|
@@ -1600,18 +1630,13 @@ function shortlist(index, query, tally) {
|
|
|
1600
1630
|
return candidates;
|
|
1601
1631
|
}
|
|
1602
1632
|
|
|
1603
|
-
// src/
|
|
1604
|
-
var BASIC_PLANE_LAST2 = 65535;
|
|
1605
|
-
function isPatternTolerance(value) {
|
|
1606
|
-
if (value === "auto") return true;
|
|
1607
|
-
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= MAX_PATTERN_TOLERANCE;
|
|
1608
|
-
}
|
|
1633
|
+
// src/pattern/typo-text.ts
|
|
1609
1634
|
function foldTypoText(text, host) {
|
|
1610
1635
|
const folded = [];
|
|
1611
1636
|
let longestFold = 0;
|
|
1612
1637
|
for (let at = 0; at < text.length; at++) {
|
|
1613
1638
|
const codePoint = text.codePointAt(at) ?? 0;
|
|
1614
|
-
if (codePoint >
|
|
1639
|
+
if (codePoint > BASIC_PLANE_LAST) at++;
|
|
1615
1640
|
const before = folded.length;
|
|
1616
1641
|
host.appendFoldedCodePoint(codePoint, folded);
|
|
1617
1642
|
longestFold = Math.max(longestFold, folded.length - before);
|
|
@@ -1623,7 +1648,7 @@ function distinctTypoRuns(text, limit) {
|
|
|
1623
1648
|
const seen = /* @__PURE__ */ new Set();
|
|
1624
1649
|
const runs = [];
|
|
1625
1650
|
for (let at = 0; at + PATTERN_RUN_CODE_POINTS <= folded.length && seen.size < limit; at++) {
|
|
1626
|
-
const key =
|
|
1651
|
+
const key = runKey(folded[at], folded[at + 1], folded[at + 2]);
|
|
1627
1652
|
if (seen.has(key)) continue;
|
|
1628
1653
|
seen.add(key);
|
|
1629
1654
|
runs.push(folded[at], folded[at + 1], folded[at + 2]);
|
|
@@ -1866,6 +1891,91 @@ function matchPattern(request) {
|
|
|
1866
1891
|
tally.flush();
|
|
1867
1892
|
}
|
|
1868
1893
|
|
|
1894
|
+
// src/core/pattern-index/tolerance.ts
|
|
1895
|
+
function isPatternTolerance(value) {
|
|
1896
|
+
if (value === "auto") return true;
|
|
1897
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= MAX_PATTERN_TOLERANCE;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// src/pattern/filter-tests.ts
|
|
1901
|
+
function excluding(context, fieldPath, excluded) {
|
|
1902
|
+
const universe = bitsetAnd(context.presentBitset(fieldPath), context.allDocIdsBitset);
|
|
1903
|
+
return bitsetAnd(universe, bitsetNot(excluded, context.capacity));
|
|
1904
|
+
}
|
|
1905
|
+
function textsOf(operand) {
|
|
1906
|
+
const texts = /* @__PURE__ */ new Set();
|
|
1907
|
+
if (!Array.isArray(operand)) return texts;
|
|
1908
|
+
for (const text of operand) if (typeof text === "string") texts.add(text);
|
|
1909
|
+
return texts;
|
|
1910
|
+
}
|
|
1911
|
+
function evaluatePatternTests(fieldPath, filter, context, bitsets) {
|
|
1912
|
+
const caseFold = filter.caseFold === true;
|
|
1913
|
+
const matching = (operator, texts, tolerance = 0) => {
|
|
1914
|
+
const into = createBitSet(context.capacity);
|
|
1915
|
+
for (const text of texts) context.matchPattern(fieldPath, operator, text, caseFold, tolerance, into);
|
|
1916
|
+
return into;
|
|
1917
|
+
};
|
|
1918
|
+
const eqTolerance = isPatternTolerance(filter.tolerance) ? filter.tolerance : 0;
|
|
1919
|
+
if (typeof filter.eq === "string") bitsets.push(matching("eq", [filter.eq], eqTolerance));
|
|
1920
|
+
if (typeof filter.ne === "string") bitsets.push(excluding(context, fieldPath, matching("eq", [filter.ne])));
|
|
1921
|
+
if (filter.in !== void 0) bitsets.push(matching("eq", textsOf(filter.in)));
|
|
1922
|
+
if (filter.nin !== void 0) bitsets.push(excluding(context, fieldPath, matching("eq", textsOf(filter.nin))));
|
|
1923
|
+
if (typeof filter.startsWith === "string") bitsets.push(matching("startsWith", [filter.startsWith]));
|
|
1924
|
+
if (typeof filter.endsWith === "string") bitsets.push(matching("endsWith", [filter.endsWith]));
|
|
1925
|
+
if (typeof filter.contains === "string") bitsets.push(matching("contains", [filter.contains]));
|
|
1926
|
+
if (typeof filter.wildcard === "string") bitsets.push(matching("wildcard", [filter.wildcard]));
|
|
1927
|
+
if (typeof filter.regex === "string") bitsets.push(matching("regex", [filter.regex]));
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
// src/pattern/footprint.ts
|
|
1931
|
+
var POSITIONS_PER_WORD = 32;
|
|
1932
|
+
function positionWords(positions) {
|
|
1933
|
+
return Math.max(1, Math.ceil(positions / POSITIONS_PER_WORD));
|
|
1934
|
+
}
|
|
1935
|
+
function smallestMatcherBytes(positions) {
|
|
1936
|
+
return 2 * positionWords(positions) * Uint32Array.BYTES_PER_ELEMENT + positions * MATCHER_CODE_POINT_BYTES + positions * MATCHER_SIMULATION_BYTES_PER_POSITION + MATCHER_STATE_OVERHEAD_BYTES + positions * Uint32Array.BYTES_PER_ELEMENT;
|
|
1937
|
+
}
|
|
1938
|
+
function isRecord(value) {
|
|
1939
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1940
|
+
}
|
|
1941
|
+
function literalFootprint(text, caseFold, host) {
|
|
1942
|
+
if (typeof text !== "string") return null;
|
|
1943
|
+
return smallestMatcherBytes(caseFold ? foldedCodePointCount(text, host) : codePointCount(text));
|
|
1944
|
+
}
|
|
1945
|
+
function larger(left, right) {
|
|
1946
|
+
if (left === null) return right;
|
|
1947
|
+
if (right === null) return left;
|
|
1948
|
+
return Math.max(left, right);
|
|
1949
|
+
}
|
|
1950
|
+
function largestTestOf(filter, host) {
|
|
1951
|
+
const caseFold = filter.caseFold === true;
|
|
1952
|
+
let largest = null;
|
|
1953
|
+
for (const operator of PATTERN_TEST_OPERATORS) {
|
|
1954
|
+
const operand = filter[operator];
|
|
1955
|
+
if (operand === void 0) continue;
|
|
1956
|
+
const texts = Array.isArray(operand) ? operand : [operand];
|
|
1957
|
+
for (const text of texts) largest = larger(largest, literalFootprint(text, caseFold, host));
|
|
1958
|
+
}
|
|
1959
|
+
for (const operator of PATTERN_EXPRESSION_OPERATORS) {
|
|
1960
|
+
const pattern = filter[operator];
|
|
1961
|
+
if (typeof pattern !== "string") continue;
|
|
1962
|
+
largest = larger(largest, expressionFootprint(operator, pattern, caseFold, host));
|
|
1963
|
+
}
|
|
1964
|
+
return largest;
|
|
1965
|
+
}
|
|
1966
|
+
function largestPatternFootprintIn(expression, patternFields, host) {
|
|
1967
|
+
let largest = null;
|
|
1968
|
+
if (isRecord(expression.fields)) {
|
|
1969
|
+
for (const [fieldPath, filter] of Object.entries(expression.fields)) {
|
|
1970
|
+
if (patternFields.has(fieldPath) && isRecord(filter)) largest = larger(largest, largestTestOf(filter, host));
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
const nested = [...expression.and ?? [], ...expression.or ?? []];
|
|
1974
|
+
if (expression.not !== void 0) nested.push(expression.not);
|
|
1975
|
+
for (const child of nested) largest = larger(largest, largestPatternFootprintIn(child, patternFields, host));
|
|
1976
|
+
return largest;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1869
1979
|
// src/core/partition/growable-uint32.ts
|
|
1870
1980
|
var GrowableUint32 = class {
|
|
1871
1981
|
values;
|
|
@@ -2203,6 +2313,214 @@ function mergePatternArrays(fieldPath, inputs) {
|
|
|
2203
2313
|
return trimmedArrays(fieldPath, docIds, runs, offsets, postings);
|
|
2204
2314
|
}
|
|
2205
2315
|
|
|
2316
|
+
// src/filters/operands/checks.ts
|
|
2317
|
+
function operandKindOf(type) {
|
|
2318
|
+
if (type === void 0) return void 0;
|
|
2319
|
+
if (type === "number" || type === "number[]") return "number";
|
|
2320
|
+
if (type === "boolean" || type === "boolean[]") return "boolean";
|
|
2321
|
+
if (type === "geopoint") return "geopoint";
|
|
2322
|
+
if (type.startsWith("vector[")) return "vector";
|
|
2323
|
+
return "text";
|
|
2324
|
+
}
|
|
2325
|
+
function isFiniteNumber(value) {
|
|
2326
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
2327
|
+
}
|
|
2328
|
+
function kindOfValue(value) {
|
|
2329
|
+
if (isFiniteNumber(value)) return "number";
|
|
2330
|
+
if (typeof value === "boolean") return "boolean";
|
|
2331
|
+
if (typeof value === "string") return "text";
|
|
2332
|
+
return void 0;
|
|
2333
|
+
}
|
|
2334
|
+
function isObjectRecord(value) {
|
|
2335
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2336
|
+
}
|
|
2337
|
+
function invalid(message, fieldPath, operator) {
|
|
2338
|
+
throw new NarsilError(ErrorCodes.SEARCH_INVALID_FILTER, message, { fieldPath, operator });
|
|
2339
|
+
}
|
|
2340
|
+
function requireFieldKind(fieldPath, operator, type, accepted) {
|
|
2341
|
+
const kind = operandKindOf(type);
|
|
2342
|
+
if (kind === void 0 || accepted.includes(kind)) return;
|
|
2343
|
+
invalid(
|
|
2344
|
+
`The engine applies "${operator}" to ${accepted.join(" or ")} fields alone, and the schema declares field "${fieldPath}" as "${type}"`,
|
|
2345
|
+
fieldPath,
|
|
2346
|
+
operator
|
|
2347
|
+
);
|
|
2348
|
+
}
|
|
2349
|
+
function requireTextRangeField(fieldPath, operator, type) {
|
|
2350
|
+
const parsed = parsedTypeOf(type);
|
|
2351
|
+
if (parsed?.sortable && (parsed.base === "string" || parsed.base === "verbatim")) return;
|
|
2352
|
+
const declared = type === void 0 ? `the schema has no field "${fieldPath}"` : `field "${fieldPath}" has type "${type}"`;
|
|
2353
|
+
invalid(
|
|
2354
|
+
`The engine applies "${operator}" with a text bound to a "string" or "verbatim" field whose type includes "sortable", but ${declared}`,
|
|
2355
|
+
fieldPath,
|
|
2356
|
+
operator
|
|
2357
|
+
);
|
|
2358
|
+
}
|
|
2359
|
+
function requireListLength(fieldPath, operator, values) {
|
|
2360
|
+
if (values.length <= MAX_FILTER_ARRAY_SIZE) return;
|
|
2361
|
+
invalid(
|
|
2362
|
+
`"${operator}" on field "${fieldPath}" holds ${values.length} values, while a filter list holds at most ${MAX_FILTER_ARRAY_SIZE}`,
|
|
2363
|
+
fieldPath,
|
|
2364
|
+
operator
|
|
2365
|
+
);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
// src/pattern/operands.ts
|
|
2369
|
+
function requireTextLength(fieldPath, operator, text) {
|
|
2370
|
+
if (!exceedsCodePoints(text, MAX_PATTERN_TEXT_CODE_POINTS)) return;
|
|
2371
|
+
invalid(
|
|
2372
|
+
`The text of "${operator}" on pattern field "${fieldPath}" holds more than ${MAX_PATTERN_TEXT_CODE_POINTS} code points`,
|
|
2373
|
+
fieldPath,
|
|
2374
|
+
operator
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
function requirePatternText(fieldPath, operator, text, caseFold, host) {
|
|
2378
|
+
requireTextLength(fieldPath, operator, text);
|
|
2379
|
+
if (caseFold && foldedCodePointCount(text, host) > MAX_PATTERN_POSITIONS) {
|
|
2380
|
+
invalid(
|
|
2381
|
+
`The text of "${operator}" on pattern field "${fieldPath}" has a case fold of more than ${MAX_PATTERN_POSITIONS} code points, while a pattern holds at most ${MAX_PATTERN_POSITIONS} positions`,
|
|
2382
|
+
fieldPath,
|
|
2383
|
+
operator
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
function requireExpressions(fieldPath, filter, host) {
|
|
2388
|
+
for (const operator of PATTERN_EXPRESSION_OPERATORS) {
|
|
2389
|
+
const pattern = filter[operator];
|
|
2390
|
+
if (typeof pattern !== "string") continue;
|
|
2391
|
+
requireTextLength(fieldPath, operator, pattern);
|
|
2392
|
+
checkExpression(operator, pattern, filter.caseFold === true, fieldPath, host);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
function requireTolerance(fieldPath, filter, host) {
|
|
2396
|
+
const { tolerance, eq } = filter;
|
|
2397
|
+
if (tolerance === void 0) return;
|
|
2398
|
+
if (!isPatternTolerance(tolerance)) {
|
|
2399
|
+
invalid(`"tolerance" on field "${fieldPath}" must be 0, 1, 2, or "auto"`, fieldPath, "tolerance");
|
|
2400
|
+
}
|
|
2401
|
+
if (typeof eq !== "string") {
|
|
2402
|
+
invalid(
|
|
2403
|
+
`"tolerance" applies only to an "eq" test, while the filter on field "${fieldPath}" sets no "eq" with text`,
|
|
2404
|
+
fieldPath,
|
|
2405
|
+
"tolerance"
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
if (tolerance === 0 || tolerance === "auto") return;
|
|
2409
|
+
const text = foldTypoText(eq, host);
|
|
2410
|
+
const requiredRuns2 = typoRunsNeeded(tolerance, text.longestFold);
|
|
2411
|
+
const distinctRuns = distinctTypoRunCount(text, requiredRuns2);
|
|
2412
|
+
if (distinctRuns >= requiredRuns2) return;
|
|
2413
|
+
throw new NarsilError(
|
|
2414
|
+
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
2415
|
+
`A tolerance of ${tolerance} on "eq" of pattern field "${fieldPath}" needs ${requiredRuns2} distinct runs of three code points in the case fold of the text, while the text holds ${distinctRuns}. Lengthen the text, lower the tolerance, or set it to "auto"`,
|
|
2416
|
+
{ fieldPath, operator: "tolerance", requiredRuns: requiredRuns2, distinctRuns }
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
function checkPatternOperands(fieldPath, filter, host) {
|
|
2420
|
+
requireExpressions(fieldPath, filter, host);
|
|
2421
|
+
const caseFold = filter.caseFold === true;
|
|
2422
|
+
for (const operator of PATTERN_TEST_OPERATORS) {
|
|
2423
|
+
const operand = filter[operator];
|
|
2424
|
+
if (typeof operand === "string") requirePatternText(fieldPath, operator, operand, caseFold, host);
|
|
2425
|
+
if (!Array.isArray(operand)) continue;
|
|
2426
|
+
for (const text of operand) {
|
|
2427
|
+
if (typeof text === "string") requirePatternText(fieldPath, operator, text, caseFold, host);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
for (const operator of PATTERN_ELEMENT_OPERATORS) {
|
|
2431
|
+
const operand = filter[operator];
|
|
2432
|
+
if (!Array.isArray(operand)) continue;
|
|
2433
|
+
for (const text of operand) {
|
|
2434
|
+
if (typeof text === "string") requirePatternText(fieldPath, operator, text, false, host);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
requireTolerance(fieldPath, filter, host);
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
// src/pattern/snapshot.ts
|
|
2441
|
+
function loadFailed(fieldPath, problem) {
|
|
2442
|
+
return new NarsilError(
|
|
2443
|
+
ErrorCodes.PERSISTENCE_LOAD_FAILED,
|
|
2444
|
+
`The pattern index of field "${fieldPath}" in this partition is corrupt: ${problem}`,
|
|
2445
|
+
{ field: fieldPath }
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
function serializePatternIndex(fieldPath, index, toExternal) {
|
|
2449
|
+
const arrays = index.toArrays(fieldPath, null);
|
|
2450
|
+
const positionOf = /* @__PURE__ */ new Map();
|
|
2451
|
+
const docIds = [];
|
|
2452
|
+
for (const ordinal of arrays.docIds) {
|
|
2453
|
+
const externalId = toExternal(ordinal);
|
|
2454
|
+
if (externalId === void 0) continue;
|
|
2455
|
+
positionOf.set(ordinal, docIds.length);
|
|
2456
|
+
docIds.push(externalId);
|
|
2457
|
+
}
|
|
2458
|
+
const runs = /* @__PURE__ */ Object.create(null);
|
|
2459
|
+
for (let run = 0; run + 1 < arrays.offsets.length; run++) {
|
|
2460
|
+
const positions = [];
|
|
2461
|
+
for (let at = arrays.offsets[run]; at < arrays.offsets[run + 1]; at++) {
|
|
2462
|
+
const position = positionOf.get(arrays.postings[at]);
|
|
2463
|
+
if (position !== void 0) positions.push(position);
|
|
2464
|
+
}
|
|
2465
|
+
if (positions.length === 0) continue;
|
|
2466
|
+
const base = run * PATTERN_RUN_CODE_POINTS;
|
|
2467
|
+
runs[String.fromCodePoint(arrays.runs[base], arrays.runs[base + 1], arrays.runs[base + 2])] = positions;
|
|
2468
|
+
}
|
|
2469
|
+
return { docIds, runs };
|
|
2470
|
+
}
|
|
2471
|
+
function appendRunCodePoints(fieldPath, key, out) {
|
|
2472
|
+
const start = out.length;
|
|
2473
|
+
for (const character of key) out.push(character.codePointAt(0) ?? 0);
|
|
2474
|
+
const count = out.length - start;
|
|
2475
|
+
if (count !== PATTERN_RUN_CODE_POINTS) {
|
|
2476
|
+
throw loadFailed(
|
|
2477
|
+
fieldPath,
|
|
2478
|
+
`the key "${key}" holds ${count} code points, while each key must hold ${PATTERN_RUN_CODE_POINTS}`
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
function requirePositions(fieldPath, key, list, documentCount) {
|
|
2483
|
+
if (!Array.isArray(list)) throw loadFailed(fieldPath, `the run "${key}" must map to a list of positions`);
|
|
2484
|
+
let previous = -1;
|
|
2485
|
+
for (const position of list) {
|
|
2486
|
+
if (!Number.isInteger(position) || position < 0 || position >= documentCount) {
|
|
2487
|
+
throw loadFailed(fieldPath, `the run "${key}" names position ${String(position)} outside its document list`);
|
|
2488
|
+
}
|
|
2489
|
+
if (position <= previous) {
|
|
2490
|
+
throw loadFailed(fieldPath, `the positions of the run "${key}" are out of ascending order`);
|
|
2491
|
+
}
|
|
2492
|
+
previous = position;
|
|
2493
|
+
}
|
|
2494
|
+
return list;
|
|
2495
|
+
}
|
|
2496
|
+
function requireDistinctDocuments(fieldPath, docIds) {
|
|
2497
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2498
|
+
for (const docId of docIds) {
|
|
2499
|
+
if (seen.has(docId)) throw loadFailed(fieldPath, `the document list names "${docId}" twice`);
|
|
2500
|
+
seen.add(docId);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
function decodePatternIndex(fieldPath, entry) {
|
|
2504
|
+
requireDistinctDocuments(fieldPath, entry.docIds);
|
|
2505
|
+
const runs = [];
|
|
2506
|
+
const offsets = [0];
|
|
2507
|
+
const postings = [];
|
|
2508
|
+
for (const [key, list] of Object.entries(entry.runs)) {
|
|
2509
|
+
appendRunCodePoints(fieldPath, key, runs);
|
|
2510
|
+
for (const position of requirePositions(fieldPath, key, list, entry.docIds.length)) postings.push(position);
|
|
2511
|
+
offsets.push(postings.length);
|
|
2512
|
+
}
|
|
2513
|
+
const positions = new Uint32Array(entry.docIds.length);
|
|
2514
|
+
for (let position = 0; position < positions.length; position++) positions[position] = position;
|
|
2515
|
+
return {
|
|
2516
|
+
fieldPath,
|
|
2517
|
+
docIds: positions,
|
|
2518
|
+
runs: Uint32Array.from(runs),
|
|
2519
|
+
offsets: Uint32Array.from(offsets),
|
|
2520
|
+
postings: Uint32Array.from(postings)
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2206
2524
|
// src/pattern/module.ts
|
|
2207
2525
|
var patternSearchModule = {
|
|
2208
2526
|
name: "pattern",
|
|
@@ -2211,7 +2529,12 @@ var patternSearchModule = {
|
|
|
2211
2529
|
mergeArrays: mergePatternArrays,
|
|
2212
2530
|
matchInto: matchPattern,
|
|
2213
2531
|
checkExpression,
|
|
2214
|
-
expressionFootprint
|
|
2532
|
+
expressionFootprint,
|
|
2533
|
+
largestFootprint: largestPatternFootprintIn,
|
|
2534
|
+
checkOperands: checkPatternOperands,
|
|
2535
|
+
evaluateTests: evaluatePatternTests,
|
|
2536
|
+
serializeIndex: serializePatternIndex,
|
|
2537
|
+
decodeIndex: decodePatternIndex
|
|
2215
2538
|
};
|
|
2216
2539
|
|
|
2217
|
-
export { DEFAULT_PATTERN_WORK_CAP, GrowableUint32,
|
|
2540
|
+
export { DEFAULT_PATTERN_WORK_CAP, GrowableUint32, MATCHER_STATE_BUDGET_BYTES, PATTERN_ELEMENT_OPERATORS, PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_WORK_FLUSH_UNITS, bitsetAndInto, bitsetAndNotInto, bitsetFromSet, bitsetHas, bitsetIsEmpty, bitsetOrInto, bitsetSet, createBitSet, invalid, isFiniteNumber, isObjectRecord, isPatternTolerance, kindOfValue, patternSearchModule, requireFieldKind, requireListLength, requireTextRangeField };
|
|
@@ -47,6 +47,7 @@ var ErrorCodes = {
|
|
|
47
47
|
QUERY_NODE_TIMEOUT: "QUERY_NODE_TIMEOUT",
|
|
48
48
|
QUERY_NO_ACTIVE_REPLICA: "QUERY_NO_ACTIVE_REPLICA",
|
|
49
49
|
CLUSTER_OPERATION_UNSUPPORTED: "CLUSTER_OPERATION_UNSUPPORTED",
|
|
50
|
+
CLUSTER_WRITE_BLOCKED: "CLUSTER_WRITE_BLOCKED",
|
|
50
51
|
ALLOCATION_NO_DATA_NODES: "ALLOCATION_NO_DATA_NODES",
|
|
51
52
|
ALLOCATION_INVALID_CONFIG: "ALLOCATION_INVALID_CONFIG",
|
|
52
53
|
ALLOCATION_FAILED: "ALLOCATION_FAILED",
|