@ember-lattice/protocol 0.0.0-stage → 1.1.0
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/CHANGELOG.md +15 -0
- package/LICENSE.md +21 -0
- package/NOTICE +30 -0
- package/README.md +82 -2
- package/conformance/cases.v1.json +7433 -0
- package/dist/ag-grid/index.d.ts +42 -0
- package/dist/ag-grid/types.d.ts +126 -0
- package/dist/conformance/dataset.d.ts +11 -0
- package/dist/conformance/index.d.ts +54 -0
- package/dist/evaluate.d.ts +21 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2557 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +31 -0
- package/dist/parse.d.ts +24 -0
- package/dist/schema.d.ts +91 -0
- package/dist/types.d.ts +207 -0
- package/package.json +48 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2557 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var PROTOCOL_VERSION = 1;
|
|
3
|
+
var FILTER_OPS = [
|
|
4
|
+
"eq",
|
|
5
|
+
"ne",
|
|
6
|
+
"lt",
|
|
7
|
+
"lte",
|
|
8
|
+
"gt",
|
|
9
|
+
"gte",
|
|
10
|
+
"in",
|
|
11
|
+
"notIn",
|
|
12
|
+
"contains",
|
|
13
|
+
"startsWith",
|
|
14
|
+
"endsWith",
|
|
15
|
+
"blank",
|
|
16
|
+
"notBlank",
|
|
17
|
+
"between",
|
|
18
|
+
"inRange"
|
|
19
|
+
];
|
|
20
|
+
var AGGREGATE_FNS = ["sum", "avg", "min", "max", "count", "first", "last"];
|
|
21
|
+
var GROUP_COUNT_KEY = "$count";
|
|
22
|
+
var TREE_PATH_SEPARATOR = "/";
|
|
23
|
+
|
|
24
|
+
// src/limits.ts
|
|
25
|
+
var LIMITS = {
|
|
26
|
+
/** Nesting of `and`, `or` and `not`. A leaf at the root has depth 1. */
|
|
27
|
+
maxFilterDepth: 16,
|
|
28
|
+
/** All nodes in one filter tree. */
|
|
29
|
+
maxFilterNodes: 256,
|
|
30
|
+
/** All `in`, `notIn` and range values in one filter tree. Each one is a SQL bind parameter. */
|
|
31
|
+
maxFilterValues: 1e3,
|
|
32
|
+
/** Items in one list: `in` values, `and`/`or` nodes, `columns`, aggregates. */
|
|
33
|
+
maxList: 1e3,
|
|
34
|
+
maxSort: 16,
|
|
35
|
+
/** `group.by` and `pivot.by`. */
|
|
36
|
+
maxGroupBy: 16,
|
|
37
|
+
/** Keys in `tree.keys`: the depth of the parent row. */
|
|
38
|
+
maxTreeDepth: 16,
|
|
39
|
+
/** Rows in one page: `end - start`, or `limit`. */
|
|
40
|
+
maxPage: 1e4,
|
|
41
|
+
maxString: 1024,
|
|
42
|
+
maxSearch: 256,
|
|
43
|
+
maxCursor: 4096,
|
|
44
|
+
/**
|
|
45
|
+
* Distinct `pivot.by` value tuples in the scope of a request. The values come from the data, so
|
|
46
|
+
* `evaluate` checks this at run time. A server counts them before it builds the pivot SQL.
|
|
47
|
+
*/
|
|
48
|
+
maxPivotValues: 200,
|
|
49
|
+
/** `parseRowsRequest` stops after this many errors. */
|
|
50
|
+
maxErrors: 50
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// ../../node_modules/.pnpm/@sindresorhus+is@8.1.0/node_modules/@sindresorhus/is/distribution/index.js
|
|
54
|
+
var typedArrayTypeNames = [
|
|
55
|
+
"Int8Array",
|
|
56
|
+
"Uint8Array",
|
|
57
|
+
"Uint8ClampedArray",
|
|
58
|
+
"Int16Array",
|
|
59
|
+
"Uint16Array",
|
|
60
|
+
"Int32Array",
|
|
61
|
+
"Uint32Array",
|
|
62
|
+
"Float32Array",
|
|
63
|
+
"Float64Array",
|
|
64
|
+
"BigInt64Array",
|
|
65
|
+
"BigUint64Array"
|
|
66
|
+
];
|
|
67
|
+
function isTypedArrayName(name) {
|
|
68
|
+
return typedArrayTypeNames.includes(name);
|
|
69
|
+
}
|
|
70
|
+
var objectTypeNames = [
|
|
71
|
+
"Function",
|
|
72
|
+
"Generator",
|
|
73
|
+
"AsyncGenerator",
|
|
74
|
+
"GeneratorFunction",
|
|
75
|
+
"AsyncGeneratorFunction",
|
|
76
|
+
"AsyncFunction",
|
|
77
|
+
"Observable",
|
|
78
|
+
"Array",
|
|
79
|
+
"Buffer",
|
|
80
|
+
"Blob",
|
|
81
|
+
"Object",
|
|
82
|
+
"RegExp",
|
|
83
|
+
"Date",
|
|
84
|
+
"Error",
|
|
85
|
+
"Map",
|
|
86
|
+
"Set",
|
|
87
|
+
"WeakMap",
|
|
88
|
+
"WeakSet",
|
|
89
|
+
"WeakRef",
|
|
90
|
+
"ArrayBuffer",
|
|
91
|
+
"SharedArrayBuffer",
|
|
92
|
+
"DataView",
|
|
93
|
+
"Promise",
|
|
94
|
+
"URL",
|
|
95
|
+
"FormData",
|
|
96
|
+
"URLSearchParams",
|
|
97
|
+
"HTMLElement",
|
|
98
|
+
"NaN",
|
|
99
|
+
...typedArrayTypeNames
|
|
100
|
+
];
|
|
101
|
+
function isObjectTypeName(name) {
|
|
102
|
+
return objectTypeNames.includes(name);
|
|
103
|
+
}
|
|
104
|
+
var primitiveTypeNames = [
|
|
105
|
+
"null",
|
|
106
|
+
"undefined",
|
|
107
|
+
"string",
|
|
108
|
+
"number",
|
|
109
|
+
"bigint",
|
|
110
|
+
"boolean",
|
|
111
|
+
"symbol"
|
|
112
|
+
];
|
|
113
|
+
function isPrimitiveTypeName(name) {
|
|
114
|
+
return primitiveTypeNames.includes(name);
|
|
115
|
+
}
|
|
116
|
+
var getObjectType = (value) => {
|
|
117
|
+
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
118
|
+
if (new RegExp("HTML\\w+Element", "v").test(objectTypeName) && isHtmlElement(value)) {
|
|
119
|
+
return "HTMLElement";
|
|
120
|
+
}
|
|
121
|
+
if (isObjectTypeName(objectTypeName)) {
|
|
122
|
+
return objectTypeName;
|
|
123
|
+
}
|
|
124
|
+
return void 0;
|
|
125
|
+
};
|
|
126
|
+
function detect(value) {
|
|
127
|
+
if (value === null) {
|
|
128
|
+
return "null";
|
|
129
|
+
}
|
|
130
|
+
switch (typeof value) {
|
|
131
|
+
case "undefined": {
|
|
132
|
+
return "undefined";
|
|
133
|
+
}
|
|
134
|
+
case "string": {
|
|
135
|
+
return "string";
|
|
136
|
+
}
|
|
137
|
+
case "number": {
|
|
138
|
+
return Number.isNaN(value) ? "NaN" : "number";
|
|
139
|
+
}
|
|
140
|
+
case "boolean": {
|
|
141
|
+
return "boolean";
|
|
142
|
+
}
|
|
143
|
+
case "function": {
|
|
144
|
+
return "Function";
|
|
145
|
+
}
|
|
146
|
+
case "bigint": {
|
|
147
|
+
return "bigint";
|
|
148
|
+
}
|
|
149
|
+
case "symbol": {
|
|
150
|
+
return "symbol";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (isObservable(value)) {
|
|
154
|
+
return "Observable";
|
|
155
|
+
}
|
|
156
|
+
if (isArray(value)) {
|
|
157
|
+
return "Array";
|
|
158
|
+
}
|
|
159
|
+
if (isBuffer(value)) {
|
|
160
|
+
return "Buffer";
|
|
161
|
+
}
|
|
162
|
+
const tagType = getObjectType(value);
|
|
163
|
+
if (tagType !== void 0 && tagType !== "Object") {
|
|
164
|
+
return tagType;
|
|
165
|
+
}
|
|
166
|
+
if (hasPromiseApi(value)) {
|
|
167
|
+
return "Promise";
|
|
168
|
+
}
|
|
169
|
+
if (isBoxedPrimitiveObject(value)) {
|
|
170
|
+
throw new TypeError("Please don't use object wrappers for primitive types");
|
|
171
|
+
}
|
|
172
|
+
return "Object";
|
|
173
|
+
}
|
|
174
|
+
function hasPromiseApi(value) {
|
|
175
|
+
return isFunction(value?.then) && isFunction(value?.catch);
|
|
176
|
+
}
|
|
177
|
+
function hasBoxedPrimitiveBrand(value, valueOf) {
|
|
178
|
+
try {
|
|
179
|
+
Reflect.apply(valueOf, value, []);
|
|
180
|
+
return true;
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function isBoxedPrimitiveObject(value) {
|
|
186
|
+
return hasBoxedPrimitiveBrand(value, String.prototype.valueOf) || hasBoxedPrimitiveBrand(value, Boolean.prototype.valueOf) || hasBoxedPrimitiveBrand(value, Number.prototype.valueOf);
|
|
187
|
+
}
|
|
188
|
+
Object.assign(detect, {
|
|
189
|
+
all: isAll,
|
|
190
|
+
any: isAny,
|
|
191
|
+
array: isArray,
|
|
192
|
+
arrayBuffer: isArrayBuffer,
|
|
193
|
+
arrayLike: isArrayLike,
|
|
194
|
+
arrayOf: isArrayOf,
|
|
195
|
+
asyncFunction: isAsyncFunction,
|
|
196
|
+
asyncGenerator: isAsyncGenerator,
|
|
197
|
+
asyncGeneratorFunction: isAsyncGeneratorFunction,
|
|
198
|
+
asyncIterable: isAsyncIterable,
|
|
199
|
+
bigint: isBigint,
|
|
200
|
+
bigInt64Array: isBigInt64Array,
|
|
201
|
+
bigUint64Array: isBigUint64Array,
|
|
202
|
+
blob: isBlob,
|
|
203
|
+
boolean: isBoolean,
|
|
204
|
+
boundFunction: isBoundFunction,
|
|
205
|
+
buffer: isBuffer,
|
|
206
|
+
class: isClass,
|
|
207
|
+
dataView: isDataView,
|
|
208
|
+
date: isDate,
|
|
209
|
+
detect,
|
|
210
|
+
directInstanceOf: isDirectInstanceOf,
|
|
211
|
+
emptyArray: isEmptyArray,
|
|
212
|
+
emptyMap: isEmptyMap,
|
|
213
|
+
emptyObject: isEmptyObject,
|
|
214
|
+
emptySet: isEmptySet,
|
|
215
|
+
emptyString: isEmptyString,
|
|
216
|
+
emptyStringOrWhitespace: isEmptyStringOrWhitespace,
|
|
217
|
+
enumCase: isEnumCase,
|
|
218
|
+
error: isError,
|
|
219
|
+
evenInteger: isEvenInteger,
|
|
220
|
+
falsy: isFalsy,
|
|
221
|
+
finiteNumber: isFiniteNumber,
|
|
222
|
+
float32Array: isFloat32Array,
|
|
223
|
+
float64Array: isFloat64Array,
|
|
224
|
+
formData: isFormData,
|
|
225
|
+
function: isFunction,
|
|
226
|
+
generator: isGenerator,
|
|
227
|
+
generatorFunction: isGeneratorFunction,
|
|
228
|
+
htmlElement: isHtmlElement,
|
|
229
|
+
infinite: isInfinite,
|
|
230
|
+
inRange: isInRange,
|
|
231
|
+
int16Array: isInt16Array,
|
|
232
|
+
int32Array: isInt32Array,
|
|
233
|
+
int8Array: isInt8Array,
|
|
234
|
+
integer: isInteger,
|
|
235
|
+
iterable: isIterable,
|
|
236
|
+
map: isMap,
|
|
237
|
+
nan: isNan,
|
|
238
|
+
nativePromise: isNativePromise,
|
|
239
|
+
negativeInteger: isNegativeInteger,
|
|
240
|
+
negativeNumber: isNegativeNumber,
|
|
241
|
+
nodeStream: isNodeStream,
|
|
242
|
+
nonEmptyArray: isNonEmptyArray,
|
|
243
|
+
nonEmptyMap: isNonEmptyMap,
|
|
244
|
+
nonEmptyObject: isNonEmptyObject,
|
|
245
|
+
nonEmptySet: isNonEmptySet,
|
|
246
|
+
nonEmptyString: isNonEmptyString,
|
|
247
|
+
nonEmptyStringAndNotWhitespace: isNonEmptyStringAndNotWhitespace,
|
|
248
|
+
nonNegativeInteger: isNonNegativeInteger,
|
|
249
|
+
nonNegativeNumber: isNonNegativeNumber,
|
|
250
|
+
null: isNull,
|
|
251
|
+
nullOrUndefined: isNullOrUndefined,
|
|
252
|
+
number: isNumber,
|
|
253
|
+
numericString: isNumericString,
|
|
254
|
+
object: isObject,
|
|
255
|
+
observable: isObservable,
|
|
256
|
+
oddInteger: isOddInteger,
|
|
257
|
+
oneOf: isOneOf,
|
|
258
|
+
plainObject: isPlainObject,
|
|
259
|
+
positiveInteger: isPositiveInteger,
|
|
260
|
+
positiveNumber: isPositiveNumber,
|
|
261
|
+
primitive: isPrimitive,
|
|
262
|
+
promise: isPromise,
|
|
263
|
+
propertyKey: isPropertyKey,
|
|
264
|
+
regExp: isRegExp,
|
|
265
|
+
safeInteger: isSafeInteger,
|
|
266
|
+
set: isSet,
|
|
267
|
+
sharedArrayBuffer: isSharedArrayBuffer,
|
|
268
|
+
string: isString,
|
|
269
|
+
symbol: isSymbol,
|
|
270
|
+
truthy: isTruthy,
|
|
271
|
+
tupleLike: isTupleLike,
|
|
272
|
+
typedArray: isTypedArray,
|
|
273
|
+
uint16Array: isUint16Array,
|
|
274
|
+
uint32Array: isUint32Array,
|
|
275
|
+
uint8Array: isUint8Array,
|
|
276
|
+
uint8ClampedArray: isUint8ClampedArray,
|
|
277
|
+
undefined: isUndefined,
|
|
278
|
+
urlInstance: isUrlInstance,
|
|
279
|
+
urlSearchParams: isUrlSearchParams,
|
|
280
|
+
urlString: isUrlString,
|
|
281
|
+
optional: isOptional,
|
|
282
|
+
validDate: isValidDate,
|
|
283
|
+
validLength: isValidLength,
|
|
284
|
+
weakMap: isWeakMap,
|
|
285
|
+
weakRef: isWeakRef,
|
|
286
|
+
weakSet: isWeakSet,
|
|
287
|
+
whitespaceString: isWhitespaceString
|
|
288
|
+
});
|
|
289
|
+
function isAbsoluteModule2(remainder) {
|
|
290
|
+
return (value) => isInteger(value) && Math.abs(value % 2) === remainder;
|
|
291
|
+
}
|
|
292
|
+
function validatePredicateArray(predicateArray, allowEmpty) {
|
|
293
|
+
if (predicateArray.length === 0) {
|
|
294
|
+
if (allowEmpty) ; else {
|
|
295
|
+
throw new TypeError("Invalid predicate array");
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
for (const predicate of predicateArray) {
|
|
300
|
+
validatePredicate(predicate);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function validatePredicate(predicate) {
|
|
304
|
+
if (!isFunction(predicate)) {
|
|
305
|
+
throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function isAll(predicate, ...values) {
|
|
309
|
+
if (Array.isArray(predicate)) {
|
|
310
|
+
const predicateArray = predicate;
|
|
311
|
+
validatePredicateArray(predicateArray, values.length === 0);
|
|
312
|
+
const combinedPredicate = (value) => predicateArray.every((singlePredicate) => singlePredicate(value));
|
|
313
|
+
if (values.length === 0) {
|
|
314
|
+
return combinedPredicate;
|
|
315
|
+
}
|
|
316
|
+
return predicateOnArray(Array.prototype.every, combinedPredicate, values);
|
|
317
|
+
}
|
|
318
|
+
return predicateOnArray(Array.prototype.every, predicate, values);
|
|
319
|
+
}
|
|
320
|
+
function isAny(predicate, ...values) {
|
|
321
|
+
if (Array.isArray(predicate)) {
|
|
322
|
+
const predicateArray = predicate;
|
|
323
|
+
validatePredicateArray(predicateArray, values.length === 0);
|
|
324
|
+
const combinedPredicate = (value) => predicateArray.some((singlePredicate) => singlePredicate(value));
|
|
325
|
+
if (values.length === 0) {
|
|
326
|
+
return combinedPredicate;
|
|
327
|
+
}
|
|
328
|
+
return predicateOnArray(Array.prototype.some, combinedPredicate, values);
|
|
329
|
+
}
|
|
330
|
+
return predicateOnArray(Array.prototype.some, predicate, values);
|
|
331
|
+
}
|
|
332
|
+
function isOptional(value, predicate) {
|
|
333
|
+
return isUndefined(value) || predicate(value);
|
|
334
|
+
}
|
|
335
|
+
function isArray(value, assertion) {
|
|
336
|
+
if (!Array.isArray(value)) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
if (!isFunction(assertion)) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
return value.every((element) => assertion(element));
|
|
343
|
+
}
|
|
344
|
+
function isArrayBuffer(value) {
|
|
345
|
+
return getObjectType(value) === "ArrayBuffer";
|
|
346
|
+
}
|
|
347
|
+
function isArrayLike(value) {
|
|
348
|
+
return !isNullOrUndefined(value) && !isFunction(value) && isValidLength(value.length);
|
|
349
|
+
}
|
|
350
|
+
function isArrayOf(predicate) {
|
|
351
|
+
return (value) => isArray(value) && value.every((element) => predicate(element));
|
|
352
|
+
}
|
|
353
|
+
function isAsyncFunction(value) {
|
|
354
|
+
return getObjectType(value) === "AsyncFunction";
|
|
355
|
+
}
|
|
356
|
+
function isAsyncGenerator(value) {
|
|
357
|
+
return isAsyncIterable(value) && isFunction(value.next) && isFunction(value.throw);
|
|
358
|
+
}
|
|
359
|
+
function isAsyncGeneratorFunction(value) {
|
|
360
|
+
return getObjectType(value) === "AsyncGeneratorFunction";
|
|
361
|
+
}
|
|
362
|
+
function isAsyncIterable(value) {
|
|
363
|
+
return isFunction(value?.[Symbol.asyncIterator]);
|
|
364
|
+
}
|
|
365
|
+
function isBigint(value) {
|
|
366
|
+
return typeof value === "bigint";
|
|
367
|
+
}
|
|
368
|
+
function isBigInt64Array(value) {
|
|
369
|
+
return getObjectType(value) === "BigInt64Array";
|
|
370
|
+
}
|
|
371
|
+
function isBigUint64Array(value) {
|
|
372
|
+
return getObjectType(value) === "BigUint64Array";
|
|
373
|
+
}
|
|
374
|
+
function isBlob(value) {
|
|
375
|
+
return getObjectType(value) === "Blob";
|
|
376
|
+
}
|
|
377
|
+
function isBoolean(value) {
|
|
378
|
+
return value === true || value === false;
|
|
379
|
+
}
|
|
380
|
+
function isBoundFunction(value) {
|
|
381
|
+
return isFunction(value) && !Object.hasOwn(value, "prototype");
|
|
382
|
+
}
|
|
383
|
+
function isBuffer(value) {
|
|
384
|
+
return value?.constructor?.isBuffer?.(value) ?? false;
|
|
385
|
+
}
|
|
386
|
+
function isClass(value) {
|
|
387
|
+
return isFunction(value) && new RegExp("^class(?:\\s+|\\{)", "v").test(value.toString());
|
|
388
|
+
}
|
|
389
|
+
function isDataView(value) {
|
|
390
|
+
return getObjectType(value) === "DataView";
|
|
391
|
+
}
|
|
392
|
+
function isDate(value) {
|
|
393
|
+
return getObjectType(value) === "Date";
|
|
394
|
+
}
|
|
395
|
+
function isDirectInstanceOf(instance, class_) {
|
|
396
|
+
if (instance === void 0 || instance === null) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
return Object.getPrototypeOf(instance) === class_.prototype;
|
|
400
|
+
}
|
|
401
|
+
function isEmptyArray(value) {
|
|
402
|
+
return isArray(value) && value.length === 0;
|
|
403
|
+
}
|
|
404
|
+
function isEmptyMap(value) {
|
|
405
|
+
return isMap(value) && value.size === 0;
|
|
406
|
+
}
|
|
407
|
+
function isEmptyObject(value) {
|
|
408
|
+
return isObject(value) && !isFunction(value) && !isArray(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
|
|
409
|
+
}
|
|
410
|
+
function isEmptySet(value) {
|
|
411
|
+
return isSet(value) && value.size === 0;
|
|
412
|
+
}
|
|
413
|
+
function isEmptyString(value) {
|
|
414
|
+
return isString(value) && value.length === 0;
|
|
415
|
+
}
|
|
416
|
+
function isEmptyStringOrWhitespace(value) {
|
|
417
|
+
return isEmptyString(value) || isWhitespaceString(value);
|
|
418
|
+
}
|
|
419
|
+
function isEnumCase(value, targetEnum) {
|
|
420
|
+
const enumObject = targetEnum;
|
|
421
|
+
return Object.entries(enumObject).some(([key, enumValue]) => {
|
|
422
|
+
if (!isString(enumValue)) {
|
|
423
|
+
return enumValue === value;
|
|
424
|
+
}
|
|
425
|
+
const numericKey = Number(key);
|
|
426
|
+
if (Number.isNaN(numericKey) || String(numericKey) !== key) {
|
|
427
|
+
return enumValue === value;
|
|
428
|
+
}
|
|
429
|
+
return enumValue === value && !(Object.hasOwn(enumObject, enumValue) && enumObject[enumValue] === numericKey);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
function isError(value) {
|
|
433
|
+
return getObjectType(value) === "Error";
|
|
434
|
+
}
|
|
435
|
+
function isEvenInteger(value) {
|
|
436
|
+
return isAbsoluteModule2(0)(value);
|
|
437
|
+
}
|
|
438
|
+
function isFalsy(value) {
|
|
439
|
+
return !value;
|
|
440
|
+
}
|
|
441
|
+
function isFiniteNumber(value) {
|
|
442
|
+
return Number.isFinite(value);
|
|
443
|
+
}
|
|
444
|
+
function isFloat32Array(value) {
|
|
445
|
+
return getObjectType(value) === "Float32Array";
|
|
446
|
+
}
|
|
447
|
+
function isFloat64Array(value) {
|
|
448
|
+
return getObjectType(value) === "Float64Array";
|
|
449
|
+
}
|
|
450
|
+
function isFormData(value) {
|
|
451
|
+
return getObjectType(value) === "FormData";
|
|
452
|
+
}
|
|
453
|
+
function isFunction(value) {
|
|
454
|
+
return typeof value === "function";
|
|
455
|
+
}
|
|
456
|
+
function isGenerator(value) {
|
|
457
|
+
return isIterable(value) && isFunction(value?.next) && isFunction(value?.throw);
|
|
458
|
+
}
|
|
459
|
+
function isGeneratorFunction(value) {
|
|
460
|
+
return getObjectType(value) === "GeneratorFunction";
|
|
461
|
+
}
|
|
462
|
+
var NODE_TYPE_ELEMENT = 1;
|
|
463
|
+
var DOM_PROPERTIES_TO_CHECK = [
|
|
464
|
+
"innerHTML",
|
|
465
|
+
"ownerDocument",
|
|
466
|
+
"style",
|
|
467
|
+
"attributes",
|
|
468
|
+
"nodeValue"
|
|
469
|
+
];
|
|
470
|
+
function isHtmlElement(value) {
|
|
471
|
+
return isObject(value) && value.nodeType === NODE_TYPE_ELEMENT && isString(value.nodeName) && !isPlainObject(value) && DOM_PROPERTIES_TO_CHECK.every((property) => property in value);
|
|
472
|
+
}
|
|
473
|
+
function isInfinite(value) {
|
|
474
|
+
return value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY;
|
|
475
|
+
}
|
|
476
|
+
function isInRange(value, range) {
|
|
477
|
+
if (isNumber(range)) {
|
|
478
|
+
return value >= Math.min(0, range) && value <= Math.max(range, 0);
|
|
479
|
+
}
|
|
480
|
+
if (isArray(range) && range.length === 2) {
|
|
481
|
+
if (Number.isNaN(range[0]) || Number.isNaN(range[1])) {
|
|
482
|
+
throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
|
|
483
|
+
}
|
|
484
|
+
return value >= Math.min(...range) && value <= Math.max(...range);
|
|
485
|
+
}
|
|
486
|
+
throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
|
|
487
|
+
}
|
|
488
|
+
function isInt16Array(value) {
|
|
489
|
+
return getObjectType(value) === "Int16Array";
|
|
490
|
+
}
|
|
491
|
+
function isInt32Array(value) {
|
|
492
|
+
return getObjectType(value) === "Int32Array";
|
|
493
|
+
}
|
|
494
|
+
function isInt8Array(value) {
|
|
495
|
+
return getObjectType(value) === "Int8Array";
|
|
496
|
+
}
|
|
497
|
+
function isInteger(value) {
|
|
498
|
+
return Number.isInteger(value);
|
|
499
|
+
}
|
|
500
|
+
function isIterable(value) {
|
|
501
|
+
return isFunction(value?.[Symbol.iterator]);
|
|
502
|
+
}
|
|
503
|
+
function isMap(value) {
|
|
504
|
+
return getObjectType(value) === "Map";
|
|
505
|
+
}
|
|
506
|
+
function isNan(value) {
|
|
507
|
+
return Number.isNaN(value);
|
|
508
|
+
}
|
|
509
|
+
function isNativePromise(value) {
|
|
510
|
+
return getObjectType(value) === "Promise";
|
|
511
|
+
}
|
|
512
|
+
function isNegativeInteger(value) {
|
|
513
|
+
return isInteger(value) && value < 0;
|
|
514
|
+
}
|
|
515
|
+
function isNegativeNumber(value) {
|
|
516
|
+
return isNumber(value) && value < 0;
|
|
517
|
+
}
|
|
518
|
+
function isNodeStream(value) {
|
|
519
|
+
return isObject(value) && isFunction(value.pipe) && !isObservable(value);
|
|
520
|
+
}
|
|
521
|
+
function isNonEmptyArray(value) {
|
|
522
|
+
return isArray(value) && value.length > 0;
|
|
523
|
+
}
|
|
524
|
+
function isNonEmptyMap(value) {
|
|
525
|
+
return isMap(value) && value.size > 0;
|
|
526
|
+
}
|
|
527
|
+
function isNonEmptyObject(value) {
|
|
528
|
+
return isObject(value) && !isFunction(value) && !isArray(value) && !isMap(value) && !isSet(value) && Object.keys(value).length > 0;
|
|
529
|
+
}
|
|
530
|
+
function isNonEmptySet(value) {
|
|
531
|
+
return isSet(value) && value.size > 0;
|
|
532
|
+
}
|
|
533
|
+
function isNonEmptyString(value) {
|
|
534
|
+
return isString(value) && value.length > 0;
|
|
535
|
+
}
|
|
536
|
+
function isNonEmptyStringAndNotWhitespace(value) {
|
|
537
|
+
return isString(value) && !isEmptyStringOrWhitespace(value);
|
|
538
|
+
}
|
|
539
|
+
function isNonNegativeInteger(value) {
|
|
540
|
+
return isInteger(value) && value >= 0;
|
|
541
|
+
}
|
|
542
|
+
function isNonNegativeNumber(value) {
|
|
543
|
+
return isNumber(value) && value >= 0;
|
|
544
|
+
}
|
|
545
|
+
function isNull(value) {
|
|
546
|
+
return value === null;
|
|
547
|
+
}
|
|
548
|
+
function isNullOrUndefined(value) {
|
|
549
|
+
return isNull(value) || isUndefined(value);
|
|
550
|
+
}
|
|
551
|
+
function isNumber(value) {
|
|
552
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
553
|
+
}
|
|
554
|
+
function isNumericString(value) {
|
|
555
|
+
return isString(value) && !isEmptyStringOrWhitespace(value) && value === value.trim() && !Number.isNaN(Number(value));
|
|
556
|
+
}
|
|
557
|
+
function isObject(value) {
|
|
558
|
+
return !isNull(value) && (typeof value === "object" || isFunction(value));
|
|
559
|
+
}
|
|
560
|
+
function isObservable(value) {
|
|
561
|
+
if (!value) {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
if (Symbol.observable !== void 0 && value === value[Symbol.observable]?.()) {
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
if (value === value["@@observable"]?.()) {
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
function isOddInteger(value) {
|
|
573
|
+
return isAbsoluteModule2(1)(value);
|
|
574
|
+
}
|
|
575
|
+
function isOneOf(values) {
|
|
576
|
+
return (value) => values.includes(value);
|
|
577
|
+
}
|
|
578
|
+
function isPlainObject(value) {
|
|
579
|
+
if (typeof value !== "object" || value === null) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
const prototype = Object.getPrototypeOf(value);
|
|
583
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
584
|
+
}
|
|
585
|
+
function isPositiveInteger(value) {
|
|
586
|
+
return isInteger(value) && value > 0;
|
|
587
|
+
}
|
|
588
|
+
function isPositiveNumber(value) {
|
|
589
|
+
return isNumber(value) && value > 0;
|
|
590
|
+
}
|
|
591
|
+
function isPrimitive(value) {
|
|
592
|
+
return isNull(value) || isPrimitiveTypeName(typeof value);
|
|
593
|
+
}
|
|
594
|
+
function isPromise(value) {
|
|
595
|
+
return isNativePromise(value) || hasPromiseApi(value);
|
|
596
|
+
}
|
|
597
|
+
function isPropertyKey(value) {
|
|
598
|
+
return isAny([isString, isNumber, isSymbol], value);
|
|
599
|
+
}
|
|
600
|
+
function isRegExp(value) {
|
|
601
|
+
return getObjectType(value) === "RegExp";
|
|
602
|
+
}
|
|
603
|
+
function isSafeInteger(value) {
|
|
604
|
+
return Number.isSafeInteger(value);
|
|
605
|
+
}
|
|
606
|
+
function isSet(value) {
|
|
607
|
+
return getObjectType(value) === "Set";
|
|
608
|
+
}
|
|
609
|
+
function isSharedArrayBuffer(value) {
|
|
610
|
+
return getObjectType(value) === "SharedArrayBuffer";
|
|
611
|
+
}
|
|
612
|
+
function isString(value) {
|
|
613
|
+
return typeof value === "string";
|
|
614
|
+
}
|
|
615
|
+
function isSymbol(value) {
|
|
616
|
+
return typeof value === "symbol";
|
|
617
|
+
}
|
|
618
|
+
function isTruthy(value) {
|
|
619
|
+
return Boolean(value);
|
|
620
|
+
}
|
|
621
|
+
function isTupleLike(value, guards) {
|
|
622
|
+
if (isArray(guards) && isArray(value) && guards.length === value.length) {
|
|
623
|
+
return guards.every((guard, index) => guard(value[index]));
|
|
624
|
+
}
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
function isTypedArray(value) {
|
|
628
|
+
return isTypedArrayName(getObjectType(value));
|
|
629
|
+
}
|
|
630
|
+
function isUint16Array(value) {
|
|
631
|
+
return getObjectType(value) === "Uint16Array";
|
|
632
|
+
}
|
|
633
|
+
function isUint32Array(value) {
|
|
634
|
+
return getObjectType(value) === "Uint32Array";
|
|
635
|
+
}
|
|
636
|
+
function isUint8Array(value) {
|
|
637
|
+
return getObjectType(value) === "Uint8Array";
|
|
638
|
+
}
|
|
639
|
+
function isUint8ClampedArray(value) {
|
|
640
|
+
return getObjectType(value) === "Uint8ClampedArray";
|
|
641
|
+
}
|
|
642
|
+
function isUndefined(value) {
|
|
643
|
+
return value === void 0;
|
|
644
|
+
}
|
|
645
|
+
function isUrlInstance(value) {
|
|
646
|
+
return getObjectType(value) === "URL";
|
|
647
|
+
}
|
|
648
|
+
function isUrlSearchParams(value) {
|
|
649
|
+
return getObjectType(value) === "URLSearchParams";
|
|
650
|
+
}
|
|
651
|
+
function isUrlString(value) {
|
|
652
|
+
if (!isString(value)) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
new URL(value);
|
|
657
|
+
return true;
|
|
658
|
+
} catch {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function isValidDate(value) {
|
|
663
|
+
return isDate(value) && !isNan(Number(value));
|
|
664
|
+
}
|
|
665
|
+
function isValidLength(value) {
|
|
666
|
+
return isSafeInteger(value) && value >= 0;
|
|
667
|
+
}
|
|
668
|
+
function isWeakMap(value) {
|
|
669
|
+
return getObjectType(value) === "WeakMap";
|
|
670
|
+
}
|
|
671
|
+
function isWeakRef(value) {
|
|
672
|
+
return getObjectType(value) === "WeakRef";
|
|
673
|
+
}
|
|
674
|
+
function isWeakSet(value) {
|
|
675
|
+
return getObjectType(value) === "WeakSet";
|
|
676
|
+
}
|
|
677
|
+
function isWhitespaceString(value) {
|
|
678
|
+
return isString(value) && new RegExp("^\\s+$", "v").test(value);
|
|
679
|
+
}
|
|
680
|
+
function predicateOnArray(method, predicate, values) {
|
|
681
|
+
validatePredicate(predicate);
|
|
682
|
+
if (values.length === 0) {
|
|
683
|
+
throw new TypeError("Invalid number of values");
|
|
684
|
+
}
|
|
685
|
+
return method.call(values, predicate);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/parse.ts
|
|
689
|
+
var RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
690
|
+
"__proto__",
|
|
691
|
+
"constructor",
|
|
692
|
+
"prototype"
|
|
693
|
+
]);
|
|
694
|
+
var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
695
|
+
var badString = (s) => s.includes("\0") || /\p{Cs}/u.test(s);
|
|
696
|
+
var BAD_STRING = "must not contain U+0000 or a lone surrogate";
|
|
697
|
+
var ISO_DATE = /^(?!0000)(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(\.\d{1,9})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/;
|
|
698
|
+
var SCALAR_OPS = /* @__PURE__ */ new Set([
|
|
699
|
+
"eq",
|
|
700
|
+
"ne",
|
|
701
|
+
"lt",
|
|
702
|
+
"lte",
|
|
703
|
+
"gt",
|
|
704
|
+
"gte",
|
|
705
|
+
"contains",
|
|
706
|
+
"startsWith",
|
|
707
|
+
"endsWith"
|
|
708
|
+
]);
|
|
709
|
+
var TEXT_OPS = /* @__PURE__ */ new Set(["contains", "startsWith", "endsWith"]);
|
|
710
|
+
var ORDER_OPS = /* @__PURE__ */ new Set(["lt", "lte", "gt", "gte", "between"]);
|
|
711
|
+
function aggregateKey(a) {
|
|
712
|
+
return a.as ?? `${a.fn}(${a.column})`;
|
|
713
|
+
}
|
|
714
|
+
function opFitsType(op, type) {
|
|
715
|
+
if (TEXT_OPS.has(op)) return type === "string";
|
|
716
|
+
if (op === "inRange") return type === "date";
|
|
717
|
+
if (ORDER_OPS.has(op)) return type !== "boolean";
|
|
718
|
+
return true;
|
|
719
|
+
}
|
|
720
|
+
function aggregateFitsType(fn, type) {
|
|
721
|
+
return fn === "sum" || fn === "avg" ? type === "number" : true;
|
|
722
|
+
}
|
|
723
|
+
function isDateString(value) {
|
|
724
|
+
const m = isString(value) ? ISO_DATE.exec(value) : null;
|
|
725
|
+
if (!m) return false;
|
|
726
|
+
const [y, mo, d, h, mi, s, frac, oh, om] = m.slice(1).map((x) => Number(x ?? 0));
|
|
727
|
+
const leap = y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
|
|
728
|
+
const days = mo === 2 ? leap ? 29 : 28 : [4, 6, 9, 11].includes(mo) ? 30 : 31;
|
|
729
|
+
const endOfDay = h === 24 && mi === 0 && s === 0 && frac === 0;
|
|
730
|
+
return mo >= 1 && mo <= 12 && d >= 1 && d <= days && (h < 24 || endOfDay) && mi < 60 && s < 60 && oh < 24 && om < 60;
|
|
731
|
+
}
|
|
732
|
+
var Issues = class {
|
|
733
|
+
list = [];
|
|
734
|
+
add(path, code, message) {
|
|
735
|
+
if (this.list.length < LIMITS.maxErrors) this.list.push({ path, code, message });
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
function parseRowsRequest(input, allowList) {
|
|
739
|
+
const columns = new Map(allowList.map((c) => [c.name, c]));
|
|
740
|
+
const issues = new Issues();
|
|
741
|
+
const p = new Parser(
|
|
742
|
+
columns,
|
|
743
|
+
allowList.some((c) => c.key === true),
|
|
744
|
+
issues
|
|
745
|
+
);
|
|
746
|
+
const value = p.request(input);
|
|
747
|
+
return issues.list.length === 0 && value ? { ok: true, value } : { ok: false, errors: issues.list };
|
|
748
|
+
}
|
|
749
|
+
var Parser = class {
|
|
750
|
+
constructor(columns, hasKey, issues) {
|
|
751
|
+
this.columns = columns;
|
|
752
|
+
this.hasKey = hasKey;
|
|
753
|
+
this.issues = issues;
|
|
754
|
+
}
|
|
755
|
+
columns;
|
|
756
|
+
hasKey;
|
|
757
|
+
issues;
|
|
758
|
+
nodes = 0;
|
|
759
|
+
values = 0;
|
|
760
|
+
stopped = false;
|
|
761
|
+
err(path, code, message) {
|
|
762
|
+
this.issues.add(path, code, message);
|
|
763
|
+
}
|
|
764
|
+
/** A plain object with only the given keys, or undefined. */
|
|
765
|
+
obj(input, path, keys) {
|
|
766
|
+
if (!isPlainObject(input)) {
|
|
767
|
+
this.err(path, "invalid", "must be an object");
|
|
768
|
+
return void 0;
|
|
769
|
+
}
|
|
770
|
+
for (const k of Object.keys(input)) {
|
|
771
|
+
if (!keys.includes(k))
|
|
772
|
+
this.err(path ? `${path}.${k}` : k, "unknown_key", `unknown key "${k}"`);
|
|
773
|
+
}
|
|
774
|
+
return input;
|
|
775
|
+
}
|
|
776
|
+
get(o, k) {
|
|
777
|
+
return Object.hasOwn(o, k) ? o[k] : void 0;
|
|
778
|
+
}
|
|
779
|
+
list(input, path, max, min = 0) {
|
|
780
|
+
if (!isArray(input)) {
|
|
781
|
+
this.err(path, "invalid", "must be an array");
|
|
782
|
+
return void 0;
|
|
783
|
+
}
|
|
784
|
+
if (input.length > max) {
|
|
785
|
+
this.err(path, "too_long", `at most ${max} items`);
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
if (input.length < min) {
|
|
789
|
+
this.err(path, "invalid", `at least ${min} items`);
|
|
790
|
+
return void 0;
|
|
791
|
+
}
|
|
792
|
+
return input;
|
|
793
|
+
}
|
|
794
|
+
str(input, path, max) {
|
|
795
|
+
if (!isString(input)) {
|
|
796
|
+
this.err(path, "invalid", "must be a string");
|
|
797
|
+
return void 0;
|
|
798
|
+
}
|
|
799
|
+
if (input.length > max) {
|
|
800
|
+
this.err(path, "too_long", `at most ${max} characters`);
|
|
801
|
+
return void 0;
|
|
802
|
+
}
|
|
803
|
+
if (badString(input)) {
|
|
804
|
+
this.err(path, "bad_string", BAD_STRING);
|
|
805
|
+
return void 0;
|
|
806
|
+
}
|
|
807
|
+
return input;
|
|
808
|
+
}
|
|
809
|
+
column(input, path) {
|
|
810
|
+
const name = this.str(input, path, LIMITS.maxString);
|
|
811
|
+
if (name === void 0) return void 0;
|
|
812
|
+
const col = this.columns.get(name);
|
|
813
|
+
if (!col) this.err(path, "unknown_column", `unknown column "${name}"`);
|
|
814
|
+
return col;
|
|
815
|
+
}
|
|
816
|
+
/** A value of the column type. `null` only when `nullable`. */
|
|
817
|
+
scalar(input, type, path, nullable = false) {
|
|
818
|
+
if (nullable && isNull(input)) return null;
|
|
819
|
+
const ok = type === "string" ? isString(input) : type === "number" ? isNumber(input) && Number.isFinite(input) : type === "boolean" ? isBoolean(input) : isDateString(input);
|
|
820
|
+
if (!ok) {
|
|
821
|
+
this.err(path, "invalid", `must be a ${type}`);
|
|
822
|
+
return void 0;
|
|
823
|
+
}
|
|
824
|
+
if (isString(input) && input.length > LIMITS.maxString) {
|
|
825
|
+
this.err(path, "too_long", `at most ${LIMITS.maxString} characters`);
|
|
826
|
+
return void 0;
|
|
827
|
+
}
|
|
828
|
+
if (isString(input) && badString(input)) {
|
|
829
|
+
this.err(path, "bad_string", BAD_STRING);
|
|
830
|
+
return void 0;
|
|
831
|
+
}
|
|
832
|
+
return input;
|
|
833
|
+
}
|
|
834
|
+
request(input) {
|
|
835
|
+
const keys = [
|
|
836
|
+
"v",
|
|
837
|
+
"range",
|
|
838
|
+
"sort",
|
|
839
|
+
"filter",
|
|
840
|
+
"search",
|
|
841
|
+
"group",
|
|
842
|
+
"aggregate",
|
|
843
|
+
"pivot",
|
|
844
|
+
"columns",
|
|
845
|
+
"count",
|
|
846
|
+
"tree"
|
|
847
|
+
];
|
|
848
|
+
const o = this.obj(input, "", keys);
|
|
849
|
+
if (!o) return void 0;
|
|
850
|
+
if (this.get(o, "v") !== 1) this.err("v", "invalid", "must be 1");
|
|
851
|
+
const range = this.range(this.get(o, "range"));
|
|
852
|
+
const sort = this.sort(this.get(o, "sort"));
|
|
853
|
+
const rawFilter = this.get(o, "filter");
|
|
854
|
+
const filter = isNull(rawFilter) ? null : this.filter(rawFilter, "filter", 1);
|
|
855
|
+
const group = this.group(this.get(o, "group"));
|
|
856
|
+
const aggregate3 = this.aggregates(this.get(o, "aggregate"), "aggregate", group?.by ?? []);
|
|
857
|
+
const out = {
|
|
858
|
+
v: 1,
|
|
859
|
+
range,
|
|
860
|
+
sort,
|
|
861
|
+
filter: filter ?? null,
|
|
862
|
+
group,
|
|
863
|
+
aggregate: aggregate3
|
|
864
|
+
};
|
|
865
|
+
if (Object.hasOwn(o, "search")) {
|
|
866
|
+
const s = this.str(o["search"], "search", LIMITS.maxSearch);
|
|
867
|
+
if (s !== void 0) out.search = s;
|
|
868
|
+
}
|
|
869
|
+
if (Object.hasOwn(o, "pivot")) {
|
|
870
|
+
const pivot = this.pivot(o["pivot"]);
|
|
871
|
+
if (pivot) out.pivot = pivot;
|
|
872
|
+
}
|
|
873
|
+
if (Object.hasOwn(o, "columns")) {
|
|
874
|
+
const cols = this.list(o["columns"], "columns", LIMITS.maxList);
|
|
875
|
+
if (cols) {
|
|
876
|
+
const names = cols.map((c, i) => this.column(c, `columns[${i}]`)?.name);
|
|
877
|
+
out.columns = names.filter(isString);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (Object.hasOwn(o, "count")) {
|
|
881
|
+
if (isBoolean(o["count"])) out.count = o["count"];
|
|
882
|
+
else this.err("count", "invalid", "must be a boolean");
|
|
883
|
+
}
|
|
884
|
+
if (Object.hasOwn(o, "tree")) {
|
|
885
|
+
const tree2 = this.tree(o["tree"], out);
|
|
886
|
+
if (tree2) out.tree = tree2;
|
|
887
|
+
}
|
|
888
|
+
return range && sort && group && aggregate3 && filter !== void 0 ? out : void 0;
|
|
889
|
+
}
|
|
890
|
+
range(input) {
|
|
891
|
+
const isOffset = isPlainObject(input) && (Object.hasOwn(input, "start") || Object.hasOwn(input, "end"));
|
|
892
|
+
if (isOffset) {
|
|
893
|
+
const o2 = this.obj(input, "range", ["start", "end"]);
|
|
894
|
+
const { start, end } = o2;
|
|
895
|
+
if (!isSafeInteger(start) || start < 0 || !isSafeInteger(end) || end < start) {
|
|
896
|
+
this.err("range", "bad_range", "needs integers with 0 <= start <= end");
|
|
897
|
+
return void 0;
|
|
898
|
+
}
|
|
899
|
+
if (end - start > LIMITS.maxPage) {
|
|
900
|
+
this.err("range", "bad_range", `at most ${LIMITS.maxPage} rows`);
|
|
901
|
+
return void 0;
|
|
902
|
+
}
|
|
903
|
+
return { start, end };
|
|
904
|
+
}
|
|
905
|
+
const o = this.obj(input, "range", ["after", "before", "limit"]);
|
|
906
|
+
if (!o) return void 0;
|
|
907
|
+
const limit = this.get(o, "limit");
|
|
908
|
+
if (!isSafeInteger(limit) || limit < 1 || limit > LIMITS.maxPage) {
|
|
909
|
+
this.err("range.limit", "bad_range", `needs an integer from 1 to ${LIMITS.maxPage}`);
|
|
910
|
+
return void 0;
|
|
911
|
+
}
|
|
912
|
+
if (Object.hasOwn(o, "after") && Object.hasOwn(o, "before")) {
|
|
913
|
+
this.err("range", "bad_range", "use after or before, not both");
|
|
914
|
+
return void 0;
|
|
915
|
+
}
|
|
916
|
+
if (!this.hasKey) {
|
|
917
|
+
this.err("range", "bad_range", "cursor paging needs a key column");
|
|
918
|
+
return void 0;
|
|
919
|
+
}
|
|
920
|
+
const out = { limit };
|
|
921
|
+
for (const k of ["after", "before"]) {
|
|
922
|
+
if (!Object.hasOwn(o, k)) continue;
|
|
923
|
+
const s = this.str(o[k], `range.${k}`, LIMITS.maxCursor);
|
|
924
|
+
if (s === void 0) return void 0;
|
|
925
|
+
out[k] = s;
|
|
926
|
+
}
|
|
927
|
+
return out;
|
|
928
|
+
}
|
|
929
|
+
sort(input) {
|
|
930
|
+
const items = this.list(input, "sort", LIMITS.maxSort);
|
|
931
|
+
if (!items) return void 0;
|
|
932
|
+
const out = [];
|
|
933
|
+
items.forEach((item, i) => {
|
|
934
|
+
const path = `sort[${i}]`;
|
|
935
|
+
const o = this.obj(item, path, ["column", "dir", "nulls"]);
|
|
936
|
+
if (!o) return;
|
|
937
|
+
const col = this.column(this.get(o, "column"), `${path}.column`);
|
|
938
|
+
if (col && col.sort !== true)
|
|
939
|
+
this.err(`${path}.column`, "not_sortable", `cannot sort by "${col.name}"`);
|
|
940
|
+
const dir = this.get(o, "dir");
|
|
941
|
+
if (dir !== "asc" && dir !== "desc")
|
|
942
|
+
this.err(`${path}.dir`, "invalid", 'must be "asc" or "desc"');
|
|
943
|
+
const nulls = this.get(o, "nulls");
|
|
944
|
+
if (Object.hasOwn(o, "nulls") && nulls !== "first" && nulls !== "last") {
|
|
945
|
+
this.err(`${path}.nulls`, "invalid", 'must be "first" or "last"');
|
|
946
|
+
}
|
|
947
|
+
if (!col || dir !== "asc" && dir !== "desc") return;
|
|
948
|
+
const s = { column: col.name, dir };
|
|
949
|
+
if (nulls === "first" || nulls === "last") s.nulls = nulls;
|
|
950
|
+
out.push(s);
|
|
951
|
+
});
|
|
952
|
+
return out;
|
|
953
|
+
}
|
|
954
|
+
filter(input, path, depth) {
|
|
955
|
+
if (this.stopped) return void 0;
|
|
956
|
+
if (depth > LIMITS.maxFilterDepth) {
|
|
957
|
+
this.err(path, "too_deep", `filter depth is at most ${LIMITS.maxFilterDepth}`);
|
|
958
|
+
this.stopped = true;
|
|
959
|
+
return void 0;
|
|
960
|
+
}
|
|
961
|
+
if (++this.nodes > LIMITS.maxFilterNodes) {
|
|
962
|
+
this.err("filter", "too_long", `at most ${LIMITS.maxFilterNodes} filter nodes`);
|
|
963
|
+
this.stopped = true;
|
|
964
|
+
return void 0;
|
|
965
|
+
}
|
|
966
|
+
if (!isPlainObject(input)) {
|
|
967
|
+
this.err(path, "invalid", "must be an object");
|
|
968
|
+
return void 0;
|
|
969
|
+
}
|
|
970
|
+
const op = Object.hasOwn(input, "op") ? input["op"] : void 0;
|
|
971
|
+
if (op === "and" || op === "or") {
|
|
972
|
+
const o = this.obj(input, path, ["op", "nodes"]);
|
|
973
|
+
const nodes = this.list(this.get(o, "nodes"), `${path}.nodes`, LIMITS.maxList, 1);
|
|
974
|
+
if (!nodes) return void 0;
|
|
975
|
+
const out = [];
|
|
976
|
+
for (let i = 0; i < nodes.length && !this.stopped; i++) {
|
|
977
|
+
const n = this.filter(nodes[i], `${path}.nodes[${i}]`, depth + 1);
|
|
978
|
+
if (n) out.push(n);
|
|
979
|
+
}
|
|
980
|
+
return out.length === nodes.length ? { op, nodes: out } : void 0;
|
|
981
|
+
}
|
|
982
|
+
if (op === "not") {
|
|
983
|
+
const o = this.obj(input, path, ["op", "node"]);
|
|
984
|
+
const node = this.filter(this.get(o, "node"), `${path}.node`, depth + 1);
|
|
985
|
+
return node ? { op, node } : void 0;
|
|
986
|
+
}
|
|
987
|
+
return this.leaf(input, path);
|
|
988
|
+
}
|
|
989
|
+
leaf(input, path) {
|
|
990
|
+
const op = this.get(input, "op");
|
|
991
|
+
if (!isString(op) || !FILTER_OPS.includes(op)) {
|
|
992
|
+
this.obj(input, path, ["column", "op", "value"]);
|
|
993
|
+
this.err(`${path}.op`, "invalid", "unknown op");
|
|
994
|
+
return void 0;
|
|
995
|
+
}
|
|
996
|
+
const fop = op;
|
|
997
|
+
const noValue = fop === "blank" || fop === "notBlank";
|
|
998
|
+
this.obj(input, path, noValue ? ["column", "op"] : ["column", "op", "value"]);
|
|
999
|
+
const col = this.column(this.get(input, "column"), `${path}.column`);
|
|
1000
|
+
if (!col) return void 0;
|
|
1001
|
+
if (!col.filter?.includes(fop) || !opFitsType(fop, col.type)) {
|
|
1002
|
+
this.err(`${path}.op`, "op_not_allowed", `op "${fop}" is not allowed on "${col.name}"`);
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
1005
|
+
if (noValue) return { column: col.name, op: fop };
|
|
1006
|
+
const raw = this.get(input, "value");
|
|
1007
|
+
const vpath = `${path}.value`;
|
|
1008
|
+
if (SCALAR_OPS.has(fop)) {
|
|
1009
|
+
const v = this.scalar(raw, col.type, vpath);
|
|
1010
|
+
return v === void 0 || v === null ? void 0 : { column: col.name, op: fop, value: v };
|
|
1011
|
+
}
|
|
1012
|
+
const min = fop === "in" || fop === "notIn" ? 1 : 2;
|
|
1013
|
+
const max = min === 1 ? LIMITS.maxList : 2;
|
|
1014
|
+
const items = this.list(raw, vpath, max, min);
|
|
1015
|
+
if (!items) return void 0;
|
|
1016
|
+
this.values += items.length;
|
|
1017
|
+
if (this.values > LIMITS.maxFilterValues) {
|
|
1018
|
+
this.err(vpath, "too_long", `at most ${LIMITS.maxFilterValues} values in one filter`);
|
|
1019
|
+
this.stopped = true;
|
|
1020
|
+
return void 0;
|
|
1021
|
+
}
|
|
1022
|
+
const values = items.map((v, i) => this.scalar(v, col.type, `${vpath}[${i}]`));
|
|
1023
|
+
if (!values.every((v) => v !== void 0 && v !== null)) return void 0;
|
|
1024
|
+
return { column: col.name, op: fop, value: values };
|
|
1025
|
+
}
|
|
1026
|
+
group(input) {
|
|
1027
|
+
const o = this.obj(input, "group", ["by", "keys"]);
|
|
1028
|
+
if (!o) return void 0;
|
|
1029
|
+
const by = this.groupColumns(this.get(o, "by"), "group.by");
|
|
1030
|
+
const keys = this.list(this.get(o, "keys"), "group.keys", LIMITS.maxGroupBy);
|
|
1031
|
+
if (!by || !keys) return void 0;
|
|
1032
|
+
if (keys.length > by.length) {
|
|
1033
|
+
this.err("group.keys", "too_many_keys", "keys.length must be at most by.length");
|
|
1034
|
+
return void 0;
|
|
1035
|
+
}
|
|
1036
|
+
const out = [];
|
|
1037
|
+
keys.forEach((k, i) => {
|
|
1038
|
+
const v = this.scalar(k, this.columns.get(by[i]).type, `group.keys[${i}]`, true);
|
|
1039
|
+
if (v !== void 0) out.push(v);
|
|
1040
|
+
});
|
|
1041
|
+
return out.length === keys.length ? { by, keys: out } : void 0;
|
|
1042
|
+
}
|
|
1043
|
+
groupColumns(input, path) {
|
|
1044
|
+
const items = this.list(input, path, LIMITS.maxGroupBy);
|
|
1045
|
+
if (!items) return void 0;
|
|
1046
|
+
const out = [];
|
|
1047
|
+
items.forEach((item, i) => {
|
|
1048
|
+
const col = this.column(item, `${path}[${i}]`);
|
|
1049
|
+
if (col && col.group !== true)
|
|
1050
|
+
this.err(`${path}[${i}]`, "not_groupable", `cannot group by "${col.name}"`);
|
|
1051
|
+
else if (col) out.push(col.name);
|
|
1052
|
+
});
|
|
1053
|
+
return out.length === items.length ? out : void 0;
|
|
1054
|
+
}
|
|
1055
|
+
aggregates(input, path, taken) {
|
|
1056
|
+
const items = this.list(input, path, LIMITS.maxList);
|
|
1057
|
+
if (!items) return void 0;
|
|
1058
|
+
const out = [];
|
|
1059
|
+
const used = /* @__PURE__ */ new Set([...taken, GROUP_COUNT_KEY]);
|
|
1060
|
+
items.forEach((item, i) => {
|
|
1061
|
+
const p = `${path}[${i}]`;
|
|
1062
|
+
const o = this.obj(item, p, ["column", "fn", "as"]);
|
|
1063
|
+
if (!o) return;
|
|
1064
|
+
const col = this.column(this.get(o, "column"), `${p}.column`);
|
|
1065
|
+
const fn = this.get(o, "fn");
|
|
1066
|
+
if (!isString(fn) || !AGGREGATE_FNS.includes(fn)) {
|
|
1067
|
+
this.err(`${p}.fn`, "invalid", "unknown aggregate fn");
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const afn = fn;
|
|
1071
|
+
if (!col) return;
|
|
1072
|
+
if (!col.aggregate?.includes(afn) || !aggregateFitsType(afn, col.type)) {
|
|
1073
|
+
this.err(`${p}.fn`, "aggregate_not_allowed", `"${afn}" is not allowed on "${col.name}"`);
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
const a = { column: col.name, fn: afn };
|
|
1077
|
+
if (Object.hasOwn(o, "as")) {
|
|
1078
|
+
const as = o["as"];
|
|
1079
|
+
if (isString(as) && badString(as)) {
|
|
1080
|
+
this.err(`${p}.as`, "bad_string", BAD_STRING);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (!isString(as) || as.length > 64 || !IDENTIFIER.test(as) || RESERVED_NAMES.has(as)) {
|
|
1084
|
+
this.err(`${p}.as`, "invalid", "must be an identifier of at most 64 characters");
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
a.as = as;
|
|
1088
|
+
}
|
|
1089
|
+
const key = aggregateKey(a);
|
|
1090
|
+
if (used.has(key)) {
|
|
1091
|
+
this.err(`${p}.as`, "invalid", `duplicate output key "${key}"`);
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
used.add(key);
|
|
1095
|
+
out.push(a);
|
|
1096
|
+
});
|
|
1097
|
+
return out.length === items.length ? out : void 0;
|
|
1098
|
+
}
|
|
1099
|
+
/** Tree data: the path of row keys to the parent row. Not with group, pivot or aggregate. */
|
|
1100
|
+
tree(input, req2) {
|
|
1101
|
+
const o = this.obj(input, "tree", ["keys"]);
|
|
1102
|
+
if (!o) return void 0;
|
|
1103
|
+
const all2 = [...this.columns.values()];
|
|
1104
|
+
const key = all2.find((c) => c.key === true);
|
|
1105
|
+
const treeColumn2 = all2.find((c) => c.parent === true || c.path === true);
|
|
1106
|
+
if (!key || !treeColumn2) {
|
|
1107
|
+
this.err("tree", "invalid", "tree data needs a key column and a parent or path column");
|
|
1108
|
+
return void 0;
|
|
1109
|
+
}
|
|
1110
|
+
if (req2.group?.by.length || req2.pivot || req2.aggregate?.length) {
|
|
1111
|
+
this.err("tree", "invalid", "tree data cannot have group, pivot or aggregate");
|
|
1112
|
+
return void 0;
|
|
1113
|
+
}
|
|
1114
|
+
const keys = this.get(o, "keys");
|
|
1115
|
+
if (isArray(keys) && keys.length > LIMITS.maxTreeDepth) {
|
|
1116
|
+
this.err("tree.keys", "too_deep", `tree depth is at most ${LIMITS.maxTreeDepth}`);
|
|
1117
|
+
return void 0;
|
|
1118
|
+
}
|
|
1119
|
+
const items = this.list(keys, "tree.keys", LIMITS.maxTreeDepth);
|
|
1120
|
+
if (!items) return void 0;
|
|
1121
|
+
const out = [];
|
|
1122
|
+
items.forEach((k, i) => {
|
|
1123
|
+
const path = `tree.keys[${i}]`;
|
|
1124
|
+
const v = this.scalar(k, key.type, path);
|
|
1125
|
+
if (v === void 0 || v === null) return;
|
|
1126
|
+
if (isNumber(v) && !isSafeInteger(v)) this.err(path, "invalid", "must be an integer");
|
|
1127
|
+
else if (treeColumn2.path === true && isString(v) && v.includes(TREE_PATH_SEPARATOR))
|
|
1128
|
+
this.err(path, "invalid", `must not contain "${TREE_PATH_SEPARATOR}"`);
|
|
1129
|
+
else out.push(v);
|
|
1130
|
+
});
|
|
1131
|
+
return out.length === items.length ? { keys: out } : void 0;
|
|
1132
|
+
}
|
|
1133
|
+
pivot(input) {
|
|
1134
|
+
const o = this.obj(input, "pivot", ["by", "values"]);
|
|
1135
|
+
if (!o) return void 0;
|
|
1136
|
+
const by = this.groupColumns(this.get(o, "by"), "pivot.by");
|
|
1137
|
+
const values = this.aggregates(this.get(o, "values"), "pivot.values", []);
|
|
1138
|
+
return by && values ? { by, values } : void 0;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
// src/evaluate.ts
|
|
1143
|
+
var ProtocolValidationError = class extends Error {
|
|
1144
|
+
constructor(errors) {
|
|
1145
|
+
super(errors.map((e) => `${e.path}: ${e.code}: ${e.message}`).join("; "));
|
|
1146
|
+
this.errors = errors;
|
|
1147
|
+
this.name = "ProtocolValidationError";
|
|
1148
|
+
}
|
|
1149
|
+
errors;
|
|
1150
|
+
};
|
|
1151
|
+
function cell(row, column2) {
|
|
1152
|
+
return Object.hasOwn(row, column2) ? row[column2] ?? null : null;
|
|
1153
|
+
}
|
|
1154
|
+
function dateMs(v) {
|
|
1155
|
+
return Date.parse(/T[^Z+-]*$/.test(v) ? `${v}Z` : v);
|
|
1156
|
+
}
|
|
1157
|
+
function compareValues(a, b, type) {
|
|
1158
|
+
if (type === "date" && isString(a) && isString(b)) return Math.sign(dateMs(a) - dateMs(b));
|
|
1159
|
+
if (isNumber(a) && isNumber(b)) return Math.sign(a - b);
|
|
1160
|
+
if (isBoolean(a) && isBoolean(b)) return Number(a) - Number(b);
|
|
1161
|
+
const sa = String(a);
|
|
1162
|
+
const sb = String(b);
|
|
1163
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
1164
|
+
}
|
|
1165
|
+
function compareTuples(a, b, keys) {
|
|
1166
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1167
|
+
const k = keys[i];
|
|
1168
|
+
const x = a[i] ?? null;
|
|
1169
|
+
const y = b[i] ?? null;
|
|
1170
|
+
if (x === null && y === null) continue;
|
|
1171
|
+
if (x === null || y === null) return x === null === (k.nulls === "first") ? -1 : 1;
|
|
1172
|
+
const c = compareValues(x, y, k.type);
|
|
1173
|
+
if (c !== 0) return k.dir === "asc" ? c : -c;
|
|
1174
|
+
}
|
|
1175
|
+
return 0;
|
|
1176
|
+
}
|
|
1177
|
+
function test(node, row, cols) {
|
|
1178
|
+
switch (node.op) {
|
|
1179
|
+
case "and": {
|
|
1180
|
+
let r = true;
|
|
1181
|
+
for (const n of node.nodes) {
|
|
1182
|
+
const t = test(n, row, cols);
|
|
1183
|
+
if (t === false) return false;
|
|
1184
|
+
if (t === null) r = null;
|
|
1185
|
+
}
|
|
1186
|
+
return r;
|
|
1187
|
+
}
|
|
1188
|
+
case "or": {
|
|
1189
|
+
let r = false;
|
|
1190
|
+
for (const n of node.nodes) {
|
|
1191
|
+
const t = test(n, row, cols);
|
|
1192
|
+
if (t === true) return true;
|
|
1193
|
+
if (t === null) r = null;
|
|
1194
|
+
}
|
|
1195
|
+
return r;
|
|
1196
|
+
}
|
|
1197
|
+
case "not": {
|
|
1198
|
+
const t = test(node.node, row, cols);
|
|
1199
|
+
return t === null ? null : !t;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
const v = cell(row, node.column);
|
|
1203
|
+
const blank = v === null || v === "";
|
|
1204
|
+
if (node.op === "blank") return blank;
|
|
1205
|
+
if (node.op === "notBlank") return !blank;
|
|
1206
|
+
if (v === null) return null;
|
|
1207
|
+
const type = cols.get(node.column)?.type ?? "string";
|
|
1208
|
+
const cmp = (x) => compareValues(v, x, type);
|
|
1209
|
+
const lower = String(v).toLowerCase();
|
|
1210
|
+
switch (node.op) {
|
|
1211
|
+
case "eq":
|
|
1212
|
+
return cmp(node.value) === 0;
|
|
1213
|
+
case "ne":
|
|
1214
|
+
return cmp(node.value) !== 0;
|
|
1215
|
+
case "lt":
|
|
1216
|
+
return cmp(node.value) < 0;
|
|
1217
|
+
case "lte":
|
|
1218
|
+
return cmp(node.value) <= 0;
|
|
1219
|
+
case "gt":
|
|
1220
|
+
return cmp(node.value) > 0;
|
|
1221
|
+
case "gte":
|
|
1222
|
+
return cmp(node.value) >= 0;
|
|
1223
|
+
case "in":
|
|
1224
|
+
return node.value.some((x) => cmp(x) === 0);
|
|
1225
|
+
case "notIn":
|
|
1226
|
+
return !node.value.some((x) => cmp(x) === 0);
|
|
1227
|
+
case "contains":
|
|
1228
|
+
return lower.includes(String(node.value).toLowerCase());
|
|
1229
|
+
case "startsWith":
|
|
1230
|
+
return lower.startsWith(String(node.value).toLowerCase());
|
|
1231
|
+
case "endsWith":
|
|
1232
|
+
return lower.endsWith(String(node.value).toLowerCase());
|
|
1233
|
+
case "between":
|
|
1234
|
+
return cmp(node.value[0]) >= 0 && cmp(node.value[1]) <= 0;
|
|
1235
|
+
case "inRange":
|
|
1236
|
+
return cmp(node.value[0]) >= 0 && cmp(node.value[1]) < 0;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
var columnMaps = /* @__PURE__ */ new WeakMap();
|
|
1240
|
+
function matchesFilter(node, row, allowList) {
|
|
1241
|
+
let cols = columnMaps.get(allowList);
|
|
1242
|
+
if (!cols) {
|
|
1243
|
+
cols = new Map(allowList.map((c) => [c.name, c]));
|
|
1244
|
+
columnMaps.set(allowList, cols);
|
|
1245
|
+
}
|
|
1246
|
+
return test(node, row, cols) === true;
|
|
1247
|
+
}
|
|
1248
|
+
function aggregate(a, rows, type) {
|
|
1249
|
+
if (a.fn === "first") return rows.length ? cell(rows[0], a.column) : null;
|
|
1250
|
+
if (a.fn === "last") return rows.length ? cell(rows[rows.length - 1], a.column) : null;
|
|
1251
|
+
const values = rows.map((r) => cell(r, a.column)).filter((v) => v !== null);
|
|
1252
|
+
if (a.fn === "count") return values.length;
|
|
1253
|
+
if (values.length === 0) return null;
|
|
1254
|
+
if (a.fn === "sum" || a.fn === "avg") {
|
|
1255
|
+
const sum = values.reduce((s, v) => s + v, 0);
|
|
1256
|
+
return a.fn === "sum" ? sum : sum / values.length;
|
|
1257
|
+
}
|
|
1258
|
+
const sign = a.fn === "min" ? -1 : 1;
|
|
1259
|
+
return values.reduce((best, v) => compareValues(v, best, type) * sign > 0 ? v : best);
|
|
1260
|
+
}
|
|
1261
|
+
function groupRows(rows, columns) {
|
|
1262
|
+
const map = /* @__PURE__ */ new Map();
|
|
1263
|
+
for (const row of rows) {
|
|
1264
|
+
const keys = columns.map((c) => cell(row, c));
|
|
1265
|
+
const id = JSON.stringify(keys);
|
|
1266
|
+
let g = map.get(id);
|
|
1267
|
+
if (!g) map.set(id, g = { keys, rows: [] });
|
|
1268
|
+
g.rows.push(row);
|
|
1269
|
+
}
|
|
1270
|
+
return [...map.values()];
|
|
1271
|
+
}
|
|
1272
|
+
function sameKey(a, b, type) {
|
|
1273
|
+
return a === null || b === null ? a === b : compareValues(a, b, type) === 0;
|
|
1274
|
+
}
|
|
1275
|
+
function evaluate(request, rows, allowList) {
|
|
1276
|
+
const parsed = parseRowsRequest(request, allowList);
|
|
1277
|
+
if (!parsed.ok) throw new ProtocolValidationError(parsed.errors);
|
|
1278
|
+
const req2 = parsed.value;
|
|
1279
|
+
const cols = new Map(allowList.map((c) => [c.name, c]));
|
|
1280
|
+
const type = (c) => cols.get(c).type;
|
|
1281
|
+
const keyCol = allowList.find((c) => c.key === true)?.name;
|
|
1282
|
+
const search = req2.search?.toLowerCase();
|
|
1283
|
+
const searchCols = allowList.filter((c) => c.search === true && c.type === "string").map((c) => c.name);
|
|
1284
|
+
const { by, keys } = req2.group;
|
|
1285
|
+
const matches = (row) => (req2.filter === null || matchesFilter(req2.filter, row, allowList)) && (!search || searchCols.some((c) => isString(row[c]) && row[c].toLowerCase().includes(search)));
|
|
1286
|
+
const tree2 = req2.tree && treeLevel(req2.tree.keys, rows, allowList);
|
|
1287
|
+
let scope = rows.filter(
|
|
1288
|
+
(row) => matches(row) && keys.every((k, i) => sameKey(cell(row, by[i]), k, type(by[i]))) && (!tree2 || tree2.inLevel(row))
|
|
1289
|
+
);
|
|
1290
|
+
const leafSort = [...req2.sort];
|
|
1291
|
+
if (keyCol) leafSort.push({ column: keyCol, dir: "asc" });
|
|
1292
|
+
const leafKeys = leafSort.map((s) => ({
|
|
1293
|
+
type: type(s.column),
|
|
1294
|
+
dir: s.dir,
|
|
1295
|
+
nulls: s.nulls ?? "last"
|
|
1296
|
+
}));
|
|
1297
|
+
const leafTuple = (r) => leafSort.map((s) => cell(r, s.column));
|
|
1298
|
+
scope = scope.map((row) => ({ row, t: leafTuple(row) })).sort((a, b) => compareTuples(a.t, b.t, leafKeys)).map((x) => x.row);
|
|
1299
|
+
const aggs = (rs, list2) => list2.map((a) => [aggregateKey(a), aggregate(a, rs, type(a.column))]);
|
|
1300
|
+
let pivotColumns;
|
|
1301
|
+
let pivotCells = () => [];
|
|
1302
|
+
if (req2.pivot) {
|
|
1303
|
+
const pivot = req2.pivot;
|
|
1304
|
+
const pkeys = pivot.by.map((c) => ({
|
|
1305
|
+
type: type(c),
|
|
1306
|
+
dir: "asc",
|
|
1307
|
+
nulls: "last"
|
|
1308
|
+
}));
|
|
1309
|
+
const combos = groupRows(scope, pivot.by).map((g) => g.keys).sort((a, b) => compareTuples(a, b, pkeys));
|
|
1310
|
+
if (combos.length > LIMITS.maxPivotValues) {
|
|
1311
|
+
const message = `${combos.length} distinct pivot values; at most ${LIMITS.maxPivotValues}`;
|
|
1312
|
+
throw new ProtocolValidationError([{ path: "pivot", code: "pivot_too_wide", message }]);
|
|
1313
|
+
}
|
|
1314
|
+
pivotColumns = combos.flatMap(
|
|
1315
|
+
(k) => pivot.values.map((v) => ({
|
|
1316
|
+
field: JSON.stringify([...k, aggregateKey(v)]),
|
|
1317
|
+
keys: k,
|
|
1318
|
+
value: aggregateKey(v)
|
|
1319
|
+
}))
|
|
1320
|
+
);
|
|
1321
|
+
pivotCells = (rs) => combos.flatMap((k) => {
|
|
1322
|
+
const sub = rs.filter((r) => pivot.by.every((c, i) => sameKey(cell(r, c), k[i], type(c))));
|
|
1323
|
+
return pivot.values.map(
|
|
1324
|
+
(v) => [JSON.stringify([...k, aggregateKey(v)]), aggregate(v, sub, type(v.column))]
|
|
1325
|
+
);
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
let out;
|
|
1329
|
+
let project = (r) => r;
|
|
1330
|
+
let tuple;
|
|
1331
|
+
let outKeys;
|
|
1332
|
+
if (keys.length < by.length) {
|
|
1333
|
+
const col = by[keys.length];
|
|
1334
|
+
const s = req2.sort.find((x) => x.column === col);
|
|
1335
|
+
outKeys = [{ type: type(col), dir: s?.dir ?? "asc", nulls: s?.nulls ?? "last" }];
|
|
1336
|
+
tuple = (r) => [r[col]];
|
|
1337
|
+
out = groupRows(scope, [col]).map(
|
|
1338
|
+
(g) => Object.fromEntries([
|
|
1339
|
+
[col, g.keys[0]],
|
|
1340
|
+
...aggs(g.rows, req2.aggregate),
|
|
1341
|
+
[GROUP_COUNT_KEY, g.rows.length],
|
|
1342
|
+
...pivotCells(g.rows)
|
|
1343
|
+
])
|
|
1344
|
+
).sort((a, b) => compareTuples(tuple(a), tuple(b), outKeys));
|
|
1345
|
+
} else if (req2.pivot) {
|
|
1346
|
+
outKeys = [];
|
|
1347
|
+
tuple = () => [];
|
|
1348
|
+
out = [
|
|
1349
|
+
Object.fromEntries([
|
|
1350
|
+
...aggs(scope, req2.aggregate),
|
|
1351
|
+
[GROUP_COUNT_KEY, scope.length],
|
|
1352
|
+
...pivotCells(scope)
|
|
1353
|
+
])
|
|
1354
|
+
];
|
|
1355
|
+
} else {
|
|
1356
|
+
const names = req2.columns ? [.../* @__PURE__ */ new Set([...keyCol ? [keyCol] : [], ...req2.columns])] : allowList.map((c) => c.name);
|
|
1357
|
+
outKeys = leafKeys;
|
|
1358
|
+
tuple = leafTuple;
|
|
1359
|
+
out = scope;
|
|
1360
|
+
const children = tree2 && tree2.childCounts(rows.filter(matches));
|
|
1361
|
+
project = (r) => Object.fromEntries([
|
|
1362
|
+
...names.map((n) => [n, cell(r, n)]),
|
|
1363
|
+
...children ? [[GROUP_COUNT_KEY, children(r)]] : []
|
|
1364
|
+
]);
|
|
1365
|
+
}
|
|
1366
|
+
const res = { rows: [] };
|
|
1367
|
+
const range = req2.range;
|
|
1368
|
+
let from;
|
|
1369
|
+
let to;
|
|
1370
|
+
if ("start" in range) {
|
|
1371
|
+
from = Math.min(range.start, out.length);
|
|
1372
|
+
to = Math.min(range.end, out.length);
|
|
1373
|
+
} else {
|
|
1374
|
+
const cursor2 = range.after ?? range.before;
|
|
1375
|
+
const at = cursor2 === void 0 ? void 0 : decodeCursor(cursor2, outKeys.length, range.after ? "after" : "before");
|
|
1376
|
+
if (at === void 0) [from, to] = [0, Math.min(range.limit, out.length)];
|
|
1377
|
+
else if (range.after !== void 0) {
|
|
1378
|
+
from = out.findIndex((r) => compareTuples(tuple(r), at, outKeys) > 0);
|
|
1379
|
+
if (from < 0) from = out.length;
|
|
1380
|
+
to = Math.min(from + range.limit, out.length);
|
|
1381
|
+
} else {
|
|
1382
|
+
to = out.findIndex((r) => compareTuples(tuple(r), at, outKeys) >= 0);
|
|
1383
|
+
if (to < 0) to = out.length;
|
|
1384
|
+
from = Math.max(0, to - range.limit);
|
|
1385
|
+
}
|
|
1386
|
+
const c = {};
|
|
1387
|
+
if (to < out.length && to > from) c.next = JSON.stringify(tuple(out[to - 1]));
|
|
1388
|
+
if (from > 0 && to > from) c.prev = JSON.stringify(tuple(out[from]));
|
|
1389
|
+
res.cursor = c;
|
|
1390
|
+
}
|
|
1391
|
+
res.rows = out.slice(from, to).map(project);
|
|
1392
|
+
if (req2.count === true || to >= out.length) res.count = out.length;
|
|
1393
|
+
if (pivotColumns) res.pivotColumns = pivotColumns;
|
|
1394
|
+
if (req2.aggregate.length > 0) res.total = Object.fromEntries(aggs(scope, req2.aggregate));
|
|
1395
|
+
return res;
|
|
1396
|
+
}
|
|
1397
|
+
function treeLevel(keys, rows, allowList) {
|
|
1398
|
+
const key = allowList.find((c) => c.key === true);
|
|
1399
|
+
const parent = allowList.find((c) => c.parent === true);
|
|
1400
|
+
const same = (a, b) => sameKey(a, b, key.type);
|
|
1401
|
+
if (parent) {
|
|
1402
|
+
const last = keys.length ? keys[keys.length - 1] : null;
|
|
1403
|
+
const chain = keys.every(
|
|
1404
|
+
(k, i) => rows.some(
|
|
1405
|
+
(r) => same(cell(r, key.name), k) && same(cell(r, parent.name), i ? keys[i - 1] : null)
|
|
1406
|
+
)
|
|
1407
|
+
);
|
|
1408
|
+
return {
|
|
1409
|
+
inLevel: (row) => chain && same(cell(row, parent.name), last),
|
|
1410
|
+
childCounts: (matched) => (row) => matched.filter((c) => same(cell(c, parent.name), cell(row, key.name))).length
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
const path = allowList.find((c) => c.path === true).name;
|
|
1414
|
+
const prefix = keys.map((k) => `${String(k)}${TREE_PATH_SEPARATOR}`).join("");
|
|
1415
|
+
return {
|
|
1416
|
+
inLevel: (row) => cell(row, path) === prefix.slice(0, -1),
|
|
1417
|
+
childCounts: (matched) => (row) => matched.filter((c) => cell(c, path) === `${prefix}${String(cell(row, key.name))}`).length
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function decodeCursor(cursor2, length, k) {
|
|
1421
|
+
const bad = () => new ProtocolValidationError([{ path: `range.${k}`, code: "bad_cursor", message: "bad cursor" }]);
|
|
1422
|
+
let v;
|
|
1423
|
+
try {
|
|
1424
|
+
v = JSON.parse(cursor2);
|
|
1425
|
+
} catch {
|
|
1426
|
+
throw bad();
|
|
1427
|
+
}
|
|
1428
|
+
if (!isArray(v) || v.length !== length || !v.every((x) => isNull(x) || isString(x) || isNumber(x) || isBoolean(x))) {
|
|
1429
|
+
throw bad();
|
|
1430
|
+
}
|
|
1431
|
+
return v;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// src/schema.ts
|
|
1435
|
+
var DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
1436
|
+
var ID = "https://joegaudet.com/ember-lattice/schema/v1/";
|
|
1437
|
+
var NO_NUL = "^[^\\u0000]*$";
|
|
1438
|
+
var str = (max) => ({ type: "string", maxLength: max, pattern: NO_NUL });
|
|
1439
|
+
var scalar = { anyOf: [str(LIMITS.maxString), { type: "number" }, { type: "boolean" }] };
|
|
1440
|
+
var groupKey = { anyOf: [...scalar.anyOf, { type: "null" }] };
|
|
1441
|
+
var columnName = { type: "string", minLength: 1, maxLength: LIMITS.maxString, pattern: NO_NUL };
|
|
1442
|
+
var column = { $ref: "#/$defs/columnName" };
|
|
1443
|
+
var obj = (properties, required) => ({
|
|
1444
|
+
type: "object",
|
|
1445
|
+
additionalProperties: false,
|
|
1446
|
+
required,
|
|
1447
|
+
properties
|
|
1448
|
+
});
|
|
1449
|
+
var list = (items, max, min = 0) => ({
|
|
1450
|
+
type: "array",
|
|
1451
|
+
items,
|
|
1452
|
+
maxItems: max,
|
|
1453
|
+
...min ? { minItems: min } : {}
|
|
1454
|
+
});
|
|
1455
|
+
var aggregate2 = obj(
|
|
1456
|
+
{
|
|
1457
|
+
column,
|
|
1458
|
+
fn: { enum: [...AGGREGATE_FNS] },
|
|
1459
|
+
as: {
|
|
1460
|
+
type: "string",
|
|
1461
|
+
pattern: "^[A-Za-z_][A-Za-z0-9_]*$",
|
|
1462
|
+
maxLength: 64,
|
|
1463
|
+
not: { enum: ["__proto__", "constructor", "prototype"] }
|
|
1464
|
+
}
|
|
1465
|
+
},
|
|
1466
|
+
["column", "fn"]
|
|
1467
|
+
);
|
|
1468
|
+
var filterNode = {
|
|
1469
|
+
oneOf: [
|
|
1470
|
+
obj(
|
|
1471
|
+
{
|
|
1472
|
+
op: { enum: ["and", "or"] },
|
|
1473
|
+
nodes: list({ $ref: "#/$defs/filterNode" }, LIMITS.maxList, 1)
|
|
1474
|
+
},
|
|
1475
|
+
["op", "nodes"]
|
|
1476
|
+
),
|
|
1477
|
+
obj({ op: { const: "not" }, node: { $ref: "#/$defs/filterNode" } }, ["op", "node"]),
|
|
1478
|
+
obj(
|
|
1479
|
+
{
|
|
1480
|
+
column,
|
|
1481
|
+
op: { enum: ["eq", "ne", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith"] },
|
|
1482
|
+
value: { $ref: "#/$defs/scalar" }
|
|
1483
|
+
},
|
|
1484
|
+
["column", "op", "value"]
|
|
1485
|
+
),
|
|
1486
|
+
obj(
|
|
1487
|
+
{
|
|
1488
|
+
column,
|
|
1489
|
+
op: { enum: ["in", "notIn"] },
|
|
1490
|
+
value: list({ $ref: "#/$defs/scalar" }, LIMITS.maxList, 1)
|
|
1491
|
+
},
|
|
1492
|
+
["column", "op", "value"]
|
|
1493
|
+
),
|
|
1494
|
+
obj(
|
|
1495
|
+
{
|
|
1496
|
+
column,
|
|
1497
|
+
op: { enum: ["between", "inRange"] },
|
|
1498
|
+
value: list({ $ref: "#/$defs/scalar" }, 2, 2)
|
|
1499
|
+
},
|
|
1500
|
+
["column", "op", "value"]
|
|
1501
|
+
),
|
|
1502
|
+
obj({ column, op: { enum: ["blank", "notBlank"] } }, ["column", "op"])
|
|
1503
|
+
]
|
|
1504
|
+
};
|
|
1505
|
+
var page = { type: "integer", minimum: 1, maximum: LIMITS.maxPage };
|
|
1506
|
+
var cursor = str(LIMITS.maxCursor);
|
|
1507
|
+
var rowsRequestSchema = {
|
|
1508
|
+
$schema: DRAFT,
|
|
1509
|
+
$id: `${ID}rows-request.json`,
|
|
1510
|
+
title: "Lattice RowsRequest v1",
|
|
1511
|
+
...obj(
|
|
1512
|
+
{
|
|
1513
|
+
v: { const: 1 },
|
|
1514
|
+
range: {
|
|
1515
|
+
oneOf: [
|
|
1516
|
+
obj({ start: { type: "integer", minimum: 0 }, end: { type: "integer", minimum: 0 } }, [
|
|
1517
|
+
"start",
|
|
1518
|
+
"end"
|
|
1519
|
+
]),
|
|
1520
|
+
{
|
|
1521
|
+
...obj({ after: cursor, before: cursor, limit: page }, ["limit"]),
|
|
1522
|
+
not: { required: ["after", "before"] }
|
|
1523
|
+
}
|
|
1524
|
+
]
|
|
1525
|
+
},
|
|
1526
|
+
sort: list(
|
|
1527
|
+
obj({ column, dir: { enum: ["asc", "desc"] }, nulls: { enum: ["first", "last"] } }, [
|
|
1528
|
+
"column",
|
|
1529
|
+
"dir"
|
|
1530
|
+
]),
|
|
1531
|
+
LIMITS.maxSort
|
|
1532
|
+
),
|
|
1533
|
+
filter: { anyOf: [{ type: "null" }, { $ref: "#/$defs/filterNode" }] },
|
|
1534
|
+
search: str(LIMITS.maxSearch),
|
|
1535
|
+
group: obj(
|
|
1536
|
+
{
|
|
1537
|
+
by: list(column, LIMITS.maxGroupBy),
|
|
1538
|
+
keys: list({ $ref: "#/$defs/groupKey" }, LIMITS.maxGroupBy)
|
|
1539
|
+
},
|
|
1540
|
+
["by", "keys"]
|
|
1541
|
+
),
|
|
1542
|
+
aggregate: list({ $ref: "#/$defs/aggregate" }, LIMITS.maxList),
|
|
1543
|
+
pivot: obj(
|
|
1544
|
+
{
|
|
1545
|
+
by: list(column, LIMITS.maxGroupBy),
|
|
1546
|
+
values: list({ $ref: "#/$defs/aggregate" }, LIMITS.maxList)
|
|
1547
|
+
},
|
|
1548
|
+
["by", "values"]
|
|
1549
|
+
),
|
|
1550
|
+
columns: list(column, LIMITS.maxList),
|
|
1551
|
+
count: { type: "boolean" },
|
|
1552
|
+
tree: obj({ keys: list({ $ref: "#/$defs/scalar" }, LIMITS.maxTreeDepth) }, ["keys"])
|
|
1553
|
+
},
|
|
1554
|
+
["v", "range", "sort", "filter", "group", "aggregate"]
|
|
1555
|
+
),
|
|
1556
|
+
$defs: { columnName, scalar, groupKey, aggregate: aggregate2, filterNode }
|
|
1557
|
+
};
|
|
1558
|
+
var rowObject = { type: "object" };
|
|
1559
|
+
var rowsResponseSchema = {
|
|
1560
|
+
$schema: DRAFT,
|
|
1561
|
+
$id: `${ID}rows-response.json`,
|
|
1562
|
+
title: "Lattice RowsResponse v1",
|
|
1563
|
+
...obj(
|
|
1564
|
+
{
|
|
1565
|
+
rows: { type: "array", items: rowObject },
|
|
1566
|
+
count: { type: "integer", minimum: 0 },
|
|
1567
|
+
cursor: obj({ next: { type: "string" }, prev: { type: "string" } }, []),
|
|
1568
|
+
pivotColumns: {
|
|
1569
|
+
type: "array",
|
|
1570
|
+
items: obj(
|
|
1571
|
+
{
|
|
1572
|
+
field: { type: "string" },
|
|
1573
|
+
keys: { type: "array", items: groupKey },
|
|
1574
|
+
value: { type: "string" }
|
|
1575
|
+
},
|
|
1576
|
+
["field", "keys", "value"]
|
|
1577
|
+
)
|
|
1578
|
+
},
|
|
1579
|
+
total: rowObject
|
|
1580
|
+
},
|
|
1581
|
+
["rows"]
|
|
1582
|
+
)
|
|
1583
|
+
};
|
|
1584
|
+
var route = { type: "array", items: groupKey };
|
|
1585
|
+
var transaction = obj(
|
|
1586
|
+
{
|
|
1587
|
+
v: { const: 1 },
|
|
1588
|
+
route,
|
|
1589
|
+
add: { type: "array", items: rowObject },
|
|
1590
|
+
addIndex: { type: "integer", minimum: 0 },
|
|
1591
|
+
update: { type: "array", items: rowObject },
|
|
1592
|
+
remove: { type: "array", items: { type: "string" } }
|
|
1593
|
+
},
|
|
1594
|
+
["v"]
|
|
1595
|
+
);
|
|
1596
|
+
var transactionSchema = {
|
|
1597
|
+
$schema: DRAFT,
|
|
1598
|
+
$id: `${ID}transaction.json`,
|
|
1599
|
+
title: "Lattice Transaction v1",
|
|
1600
|
+
...transaction
|
|
1601
|
+
};
|
|
1602
|
+
var rowOpSchema = {
|
|
1603
|
+
$schema: DRAFT,
|
|
1604
|
+
$id: `${ID}row-op.json`,
|
|
1605
|
+
title: "Lattice RowOp v1",
|
|
1606
|
+
oneOf: [
|
|
1607
|
+
obj({ type: { const: "add" }, row: rowObject, route, index: { type: "integer", minimum: 0 } }, [
|
|
1608
|
+
"type",
|
|
1609
|
+
"row"
|
|
1610
|
+
]),
|
|
1611
|
+
obj({ type: { const: "update" }, id: { type: "string" }, changes: rowObject }, [
|
|
1612
|
+
"type",
|
|
1613
|
+
"id",
|
|
1614
|
+
"changes"
|
|
1615
|
+
]),
|
|
1616
|
+
obj({ type: { const: "remove" }, id: { type: "string" } }, ["type", "id"])
|
|
1617
|
+
]
|
|
1618
|
+
};
|
|
1619
|
+
var mutateResultSchema = {
|
|
1620
|
+
$schema: DRAFT,
|
|
1621
|
+
$id: `${ID}mutate-result.json`,
|
|
1622
|
+
title: "Lattice MutateResult v1",
|
|
1623
|
+
...obj(
|
|
1624
|
+
{
|
|
1625
|
+
results: {
|
|
1626
|
+
type: "array",
|
|
1627
|
+
items: {
|
|
1628
|
+
oneOf: [
|
|
1629
|
+
obj({ status: { const: "ok" }, id: { type: "string" }, row: rowObject }, [
|
|
1630
|
+
"status",
|
|
1631
|
+
"id"
|
|
1632
|
+
]),
|
|
1633
|
+
obj(
|
|
1634
|
+
{ status: { const: "error" }, id: { type: "string" }, message: { type: "string" } },
|
|
1635
|
+
["status", "message"]
|
|
1636
|
+
)
|
|
1637
|
+
]
|
|
1638
|
+
}
|
|
1639
|
+
},
|
|
1640
|
+
transaction: { $ref: "#/$defs/transaction" }
|
|
1641
|
+
},
|
|
1642
|
+
["results"]
|
|
1643
|
+
),
|
|
1644
|
+
$defs: { transaction }
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
// src/conformance/dataset.ts
|
|
1648
|
+
var peopleColumns = [
|
|
1649
|
+
{
|
|
1650
|
+
name: "id",
|
|
1651
|
+
type: "number",
|
|
1652
|
+
key: true,
|
|
1653
|
+
filter: ["eq", "ne", "in", "notIn", "lt", "gt", "between"],
|
|
1654
|
+
sort: true
|
|
1655
|
+
},
|
|
1656
|
+
{
|
|
1657
|
+
name: "name",
|
|
1658
|
+
type: "string",
|
|
1659
|
+
filter: ["eq", "ne", "in", "contains", "startsWith", "endsWith", "blank", "notBlank"],
|
|
1660
|
+
sort: true,
|
|
1661
|
+
search: true,
|
|
1662
|
+
aggregate: ["count", "first", "last", "min", "max"]
|
|
1663
|
+
},
|
|
1664
|
+
{
|
|
1665
|
+
name: "dept",
|
|
1666
|
+
type: "string",
|
|
1667
|
+
filter: ["eq", "in", "notIn", "blank", "notBlank"],
|
|
1668
|
+
sort: true,
|
|
1669
|
+
group: true,
|
|
1670
|
+
search: true,
|
|
1671
|
+
aggregate: ["count"]
|
|
1672
|
+
},
|
|
1673
|
+
{ name: "region", type: "string", filter: ["eq", "in"], sort: true, group: true },
|
|
1674
|
+
{
|
|
1675
|
+
name: "salary",
|
|
1676
|
+
type: "number",
|
|
1677
|
+
filter: ["eq", "ne", "lt", "lte", "gt", "gte", "in", "notIn", "between", "blank"],
|
|
1678
|
+
sort: true,
|
|
1679
|
+
aggregate: ["sum", "avg", "min", "max", "count", "first", "last"]
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
name: "hired",
|
|
1683
|
+
type: "date",
|
|
1684
|
+
filter: ["lt", "gt", "gte", "between", "inRange", "blank"],
|
|
1685
|
+
sort: true,
|
|
1686
|
+
aggregate: ["min", "max"]
|
|
1687
|
+
},
|
|
1688
|
+
{ name: "active", type: "boolean", filter: ["eq", "ne", "blank"], sort: true, group: true }
|
|
1689
|
+
];
|
|
1690
|
+
var peopleRows = [
|
|
1691
|
+
{
|
|
1692
|
+
id: 1,
|
|
1693
|
+
name: "Ann",
|
|
1694
|
+
dept: "eng",
|
|
1695
|
+
region: "west",
|
|
1696
|
+
salary: 120,
|
|
1697
|
+
hired: "2019-01-15",
|
|
1698
|
+
active: true
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
id: 2,
|
|
1702
|
+
name: "bob",
|
|
1703
|
+
dept: "eng",
|
|
1704
|
+
region: "east",
|
|
1705
|
+
salary: 95,
|
|
1706
|
+
hired: "2020-03-01",
|
|
1707
|
+
active: false
|
|
1708
|
+
},
|
|
1709
|
+
{
|
|
1710
|
+
id: 3,
|
|
1711
|
+
name: "Cid",
|
|
1712
|
+
dept: "eng",
|
|
1713
|
+
region: "west",
|
|
1714
|
+
salary: null,
|
|
1715
|
+
hired: "2018-07-20",
|
|
1716
|
+
active: true
|
|
1717
|
+
},
|
|
1718
|
+
{ id: 4, name: "Dee", dept: "ops", region: "east", salary: 80, hired: null, active: true },
|
|
1719
|
+
{
|
|
1720
|
+
id: 5,
|
|
1721
|
+
name: null,
|
|
1722
|
+
dept: "ops",
|
|
1723
|
+
region: "east",
|
|
1724
|
+
salary: 60,
|
|
1725
|
+
hired: "2021-11-30",
|
|
1726
|
+
active: false
|
|
1727
|
+
},
|
|
1728
|
+
{ id: 6, name: "", dept: "ops", region: "west", salary: 75, hired: "2017-05-05", active: null },
|
|
1729
|
+
{
|
|
1730
|
+
id: 7,
|
|
1731
|
+
name: "Eve",
|
|
1732
|
+
dept: "sales",
|
|
1733
|
+
region: "west",
|
|
1734
|
+
salary: 110,
|
|
1735
|
+
hired: "2020-03-01",
|
|
1736
|
+
active: true
|
|
1737
|
+
},
|
|
1738
|
+
{
|
|
1739
|
+
id: 8,
|
|
1740
|
+
name: "fay",
|
|
1741
|
+
dept: "sales",
|
|
1742
|
+
region: null,
|
|
1743
|
+
salary: 50,
|
|
1744
|
+
hired: "2022-02-14",
|
|
1745
|
+
active: false
|
|
1746
|
+
},
|
|
1747
|
+
{ id: 9, name: "Gus", dept: null, region: "east", salary: 65, hired: "2016-09-09", active: true },
|
|
1748
|
+
{
|
|
1749
|
+
id: 10,
|
|
1750
|
+
name: "hal",
|
|
1751
|
+
dept: "sales",
|
|
1752
|
+
region: "east",
|
|
1753
|
+
salary: null,
|
|
1754
|
+
hired: "2019-12-31",
|
|
1755
|
+
active: null
|
|
1756
|
+
},
|
|
1757
|
+
{
|
|
1758
|
+
id: 11,
|
|
1759
|
+
name: "Ivy",
|
|
1760
|
+
dept: "eng",
|
|
1761
|
+
region: null,
|
|
1762
|
+
salary: 130,
|
|
1763
|
+
hired: "2023-06-01",
|
|
1764
|
+
active: true
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
id: 12,
|
|
1768
|
+
name: "Jon",
|
|
1769
|
+
dept: "ops",
|
|
1770
|
+
region: "west",
|
|
1771
|
+
salary: 85,
|
|
1772
|
+
hired: "2018-01-01",
|
|
1773
|
+
active: false
|
|
1774
|
+
}
|
|
1775
|
+
];
|
|
1776
|
+
var wideColumns = [
|
|
1777
|
+
{ name: "id", type: "number", key: true, sort: true, aggregate: ["count"] },
|
|
1778
|
+
{ name: "bucket", type: "number", group: true }
|
|
1779
|
+
];
|
|
1780
|
+
var wideRows = Array.from({ length: LIMITS.maxPivotValues + 1 }, (_, i) => ({
|
|
1781
|
+
id: i + 1,
|
|
1782
|
+
bucket: i + 1
|
|
1783
|
+
}));
|
|
1784
|
+
var treeNodes = [
|
|
1785
|
+
[1, null, "docs", 10],
|
|
1786
|
+
[2, null, "src", 20],
|
|
1787
|
+
[3, null, "empty", 5],
|
|
1788
|
+
[4, 2, "api", 7],
|
|
1789
|
+
[5, 2, "ui", 3],
|
|
1790
|
+
[6, 1, "readme", 1],
|
|
1791
|
+
[7, 1, "guide", 4],
|
|
1792
|
+
[8, 4, "v1", 2],
|
|
1793
|
+
[9, 4, "v2", 6],
|
|
1794
|
+
[10, 7, "Notes", null],
|
|
1795
|
+
[11, 4, "old", null]
|
|
1796
|
+
];
|
|
1797
|
+
var treeColumn = (tree2) => [
|
|
1798
|
+
{ name: "id", type: "number", key: true, filter: ["eq", "in"], sort: true },
|
|
1799
|
+
tree2,
|
|
1800
|
+
{
|
|
1801
|
+
name: "name",
|
|
1802
|
+
type: "string",
|
|
1803
|
+
filter: ["eq", "contains"],
|
|
1804
|
+
sort: true,
|
|
1805
|
+
search: true
|
|
1806
|
+
},
|
|
1807
|
+
{ name: "size", type: "number", filter: ["gt", "blank"], sort: true, aggregate: ["sum"] }
|
|
1808
|
+
];
|
|
1809
|
+
var treeParentColumns = treeColumn({ name: "parent_id", type: "number", parent: true });
|
|
1810
|
+
var treePathColumns = treeColumn({ name: "path", type: "string", path: true });
|
|
1811
|
+
var treeParentRows = treeNodes.map(([id, parent_id, name, size]) => ({
|
|
1812
|
+
id,
|
|
1813
|
+
parent_id,
|
|
1814
|
+
name,
|
|
1815
|
+
size
|
|
1816
|
+
}));
|
|
1817
|
+
var pathOf = (id) => {
|
|
1818
|
+
const node = treeNodes.find((n) => n[0] === id);
|
|
1819
|
+
if (!node || node[1] === null) return "";
|
|
1820
|
+
const up = pathOf(node[1]);
|
|
1821
|
+
return up === "" ? String(node[1]) : `${up}/${node[1]}`;
|
|
1822
|
+
};
|
|
1823
|
+
var treePathRows = treeNodes.map(([id, , name, size]) => ({
|
|
1824
|
+
id,
|
|
1825
|
+
path: pathOf(id),
|
|
1826
|
+
name,
|
|
1827
|
+
size
|
|
1828
|
+
}));
|
|
1829
|
+
|
|
1830
|
+
// src/conformance/index.ts
|
|
1831
|
+
var base = {
|
|
1832
|
+
v: 1,
|
|
1833
|
+
range: { start: 0, end: 100 },
|
|
1834
|
+
sort: [],
|
|
1835
|
+
filter: null,
|
|
1836
|
+
group: { by: [], keys: [] },
|
|
1837
|
+
aggregate: []
|
|
1838
|
+
};
|
|
1839
|
+
var req = (r) => ({ ...base, ...r });
|
|
1840
|
+
var where = (filter) => req({ filter });
|
|
1841
|
+
var responseCases = [
|
|
1842
|
+
["all rows, key order", base],
|
|
1843
|
+
["filter eq string is case-sensitive", where({ column: "name", op: "eq", value: "ann" })],
|
|
1844
|
+
["filter eq number", where({ column: "salary", op: "eq", value: 95 })],
|
|
1845
|
+
["filter ne excludes null", where({ column: "salary", op: "ne", value: 95 })],
|
|
1846
|
+
["filter lt", where({ column: "salary", op: "lt", value: 75 })],
|
|
1847
|
+
["filter lte", where({ column: "salary", op: "lte", value: 75 })],
|
|
1848
|
+
["filter gt", where({ column: "salary", op: "gt", value: 100 })],
|
|
1849
|
+
["filter gte", where({ column: "salary", op: "gte", value: 110 })],
|
|
1850
|
+
["filter in", where({ column: "id", op: "in", value: [2, 4, 99] })],
|
|
1851
|
+
["filter notIn excludes null", where({ column: "salary", op: "notIn", value: [50, 60] })],
|
|
1852
|
+
["filter contains ignores case", where({ column: "name", op: "contains", value: "E" })],
|
|
1853
|
+
["filter startsWith ignores case", where({ column: "name", op: "startsWith", value: "f" })],
|
|
1854
|
+
["filter endsWith ignores case", where({ column: "name", op: "endsWith", value: "N" })],
|
|
1855
|
+
["filter blank matches null and empty string", where({ column: "name", op: "blank" })],
|
|
1856
|
+
["filter notBlank", where({ column: "name", op: "notBlank" })],
|
|
1857
|
+
["filter blank on a number", where({ column: "salary", op: "blank" })],
|
|
1858
|
+
["filter blank on a boolean is null only", where({ column: "active", op: "blank" })],
|
|
1859
|
+
["filter contains a literal _", where({ column: "name", op: "contains", value: "_" })],
|
|
1860
|
+
["filter startsWith a literal %", where({ column: "name", op: "startsWith", value: "%" })],
|
|
1861
|
+
["quick search with a literal %", req({ search: "%" })],
|
|
1862
|
+
["filter between is inclusive", where({ column: "salary", op: "between", value: [60, 85] })],
|
|
1863
|
+
[
|
|
1864
|
+
"filter inRange is half-open",
|
|
1865
|
+
where({ column: "hired", op: "inRange", value: ["2019-01-15", "2020-03-01"] })
|
|
1866
|
+
],
|
|
1867
|
+
[
|
|
1868
|
+
"filter between dates",
|
|
1869
|
+
where({ column: "hired", op: "between", value: ["2019-01-15", "2020-03-01"] })
|
|
1870
|
+
],
|
|
1871
|
+
["filter date-time is UTC", where({ column: "hired", op: "gte", value: "2021-11-30T00:00:00Z" })],
|
|
1872
|
+
["filter boolean eq", where({ column: "active", op: "eq", value: false })],
|
|
1873
|
+
["filter boolean ne excludes null", where({ column: "active", op: "ne", value: true })],
|
|
1874
|
+
[
|
|
1875
|
+
"filter not over null is unknown",
|
|
1876
|
+
where({ op: "not", node: { column: "salary", op: "gt", value: 90 } })
|
|
1877
|
+
],
|
|
1878
|
+
[
|
|
1879
|
+
"filter or over null is unknown",
|
|
1880
|
+
where({
|
|
1881
|
+
op: "not",
|
|
1882
|
+
node: {
|
|
1883
|
+
op: "or",
|
|
1884
|
+
nodes: [
|
|
1885
|
+
{ column: "salary", op: "lt", value: 70 },
|
|
1886
|
+
{ column: "salary", op: "gte", value: 70 }
|
|
1887
|
+
]
|
|
1888
|
+
}
|
|
1889
|
+
})
|
|
1890
|
+
],
|
|
1891
|
+
[
|
|
1892
|
+
"filter and, or, not",
|
|
1893
|
+
where({
|
|
1894
|
+
op: "and",
|
|
1895
|
+
nodes: [
|
|
1896
|
+
{
|
|
1897
|
+
op: "or",
|
|
1898
|
+
nodes: [
|
|
1899
|
+
{ column: "dept", op: "eq", value: "eng" },
|
|
1900
|
+
{ column: "dept", op: "blank" }
|
|
1901
|
+
]
|
|
1902
|
+
},
|
|
1903
|
+
{ op: "not", node: { column: "active", op: "eq", value: false } }
|
|
1904
|
+
]
|
|
1905
|
+
})
|
|
1906
|
+
],
|
|
1907
|
+
["quick search ignores case, search columns only", req({ search: "S" })],
|
|
1908
|
+
[
|
|
1909
|
+
"quick search with filter",
|
|
1910
|
+
req({ search: "e", filter: { column: "salary", op: "gt", value: 80 } })
|
|
1911
|
+
],
|
|
1912
|
+
["sort asc puts nulls last", req({ sort: [{ column: "salary", dir: "asc" }] })],
|
|
1913
|
+
["sort desc puts nulls last", req({ sort: [{ column: "salary", dir: "desc" }] })],
|
|
1914
|
+
["sort asc nulls first", req({ sort: [{ column: "salary", dir: "asc", nulls: "first" }] })],
|
|
1915
|
+
["sort desc nulls first", req({ sort: [{ column: "hired", dir: "desc", nulls: "first" }] })],
|
|
1916
|
+
["sort strings by code unit", req({ sort: [{ column: "name", dir: "asc" }] })],
|
|
1917
|
+
["sort booleans", req({ sort: [{ column: "active", dir: "desc" }] })],
|
|
1918
|
+
[
|
|
1919
|
+
"sort two columns, then the key",
|
|
1920
|
+
req({
|
|
1921
|
+
sort: [
|
|
1922
|
+
{ column: "dept", dir: "asc", nulls: "first" },
|
|
1923
|
+
{ column: "region", dir: "desc" }
|
|
1924
|
+
]
|
|
1925
|
+
})
|
|
1926
|
+
],
|
|
1927
|
+
["projection keeps the key", req({ columns: ["name", "salary"] })],
|
|
1928
|
+
["offset middle page has no count", req({ range: { start: 3, end: 6 } })],
|
|
1929
|
+
["offset page with count", req({ range: { start: 3, end: 6 }, count: true })],
|
|
1930
|
+
["offset last page has count", req({ range: { start: 10, end: 20 } })],
|
|
1931
|
+
["offset past the end", req({ range: { start: 50, end: 60 } })],
|
|
1932
|
+
["cursor first page", req({ range: { limit: 4 }, sort: [{ column: "name", dir: "desc" }] })],
|
|
1933
|
+
[
|
|
1934
|
+
"group level 0 with every aggregate",
|
|
1935
|
+
req({
|
|
1936
|
+
group: { by: ["dept"], keys: [] },
|
|
1937
|
+
aggregate: [
|
|
1938
|
+
{ column: "salary", fn: "sum" },
|
|
1939
|
+
{ column: "salary", fn: "avg" },
|
|
1940
|
+
{ column: "salary", fn: "min" },
|
|
1941
|
+
{ column: "salary", fn: "max" },
|
|
1942
|
+
{ column: "salary", fn: "count" },
|
|
1943
|
+
{ column: "name", fn: "first" },
|
|
1944
|
+
{ column: "name", fn: "last", as: "lastName" },
|
|
1945
|
+
{ column: "hired", fn: "min" }
|
|
1946
|
+
]
|
|
1947
|
+
})
|
|
1948
|
+
],
|
|
1949
|
+
[
|
|
1950
|
+
"group rows sorted desc nulls first",
|
|
1951
|
+
req({
|
|
1952
|
+
group: { by: ["dept"], keys: [] },
|
|
1953
|
+
sort: [{ column: "dept", dir: "desc", nulls: "first" }]
|
|
1954
|
+
})
|
|
1955
|
+
],
|
|
1956
|
+
[
|
|
1957
|
+
"group level 1 under a key",
|
|
1958
|
+
req({
|
|
1959
|
+
group: { by: ["dept", "region"], keys: ["eng"] },
|
|
1960
|
+
aggregate: [{ column: "salary", fn: "sum" }]
|
|
1961
|
+
})
|
|
1962
|
+
],
|
|
1963
|
+
["leaf rows under two keys", req({ group: { by: ["dept", "region"], keys: ["ops", "west"] } })],
|
|
1964
|
+
["leaf rows under a null key", req({ group: { by: ["dept"], keys: [null] } })],
|
|
1965
|
+
[
|
|
1966
|
+
"group by boolean",
|
|
1967
|
+
req({ group: { by: ["active"], keys: [] }, aggregate: [{ column: "salary", fn: "avg" }] })
|
|
1968
|
+
],
|
|
1969
|
+
[
|
|
1970
|
+
"group with filter and paging",
|
|
1971
|
+
req({
|
|
1972
|
+
group: { by: ["region"], keys: [] },
|
|
1973
|
+
filter: { column: "salary", op: "gt", value: 60 },
|
|
1974
|
+
range: { start: 0, end: 2 }
|
|
1975
|
+
})
|
|
1976
|
+
],
|
|
1977
|
+
[
|
|
1978
|
+
"first and last follow the sort",
|
|
1979
|
+
req({
|
|
1980
|
+
sort: [{ column: "salary", dir: "desc", nulls: "first" }],
|
|
1981
|
+
aggregate: [
|
|
1982
|
+
{ column: "salary", fn: "first" },
|
|
1983
|
+
{ column: "salary", fn: "last" }
|
|
1984
|
+
],
|
|
1985
|
+
range: { start: 0, end: 2 }
|
|
1986
|
+
})
|
|
1987
|
+
],
|
|
1988
|
+
[
|
|
1989
|
+
"aggregates over no values",
|
|
1990
|
+
req({
|
|
1991
|
+
filter: { column: "id", op: "eq", value: 3 },
|
|
1992
|
+
aggregate: [
|
|
1993
|
+
{ column: "salary", fn: "sum" },
|
|
1994
|
+
{ column: "salary", fn: "avg" },
|
|
1995
|
+
{ column: "salary", fn: "min" },
|
|
1996
|
+
{ column: "salary", fn: "count" }
|
|
1997
|
+
]
|
|
1998
|
+
})
|
|
1999
|
+
],
|
|
2000
|
+
[
|
|
2001
|
+
"pivot by region under dept groups",
|
|
2002
|
+
req({
|
|
2003
|
+
group: { by: ["dept"], keys: [] },
|
|
2004
|
+
aggregate: [{ column: "salary", fn: "sum" }],
|
|
2005
|
+
pivot: {
|
|
2006
|
+
by: ["region"],
|
|
2007
|
+
values: [
|
|
2008
|
+
{ column: "salary", fn: "sum" },
|
|
2009
|
+
{ column: "salary", fn: "count" }
|
|
2010
|
+
]
|
|
2011
|
+
}
|
|
2012
|
+
})
|
|
2013
|
+
],
|
|
2014
|
+
[
|
|
2015
|
+
"pivot at the leaf level gives one row",
|
|
2016
|
+
req({ pivot: { by: ["active"], values: [{ column: "salary", fn: "max" }] } })
|
|
2017
|
+
]
|
|
2018
|
+
];
|
|
2019
|
+
var walkCases = [
|
|
2020
|
+
["cursor walk by key", req({ range: { limit: 5 } })],
|
|
2021
|
+
[
|
|
2022
|
+
"cursor walk with nulls and ties",
|
|
2023
|
+
req({
|
|
2024
|
+
range: { limit: 3 },
|
|
2025
|
+
sort: [
|
|
2026
|
+
{ column: "salary", dir: "desc", nulls: "first" },
|
|
2027
|
+
{ column: "dept", dir: "asc" }
|
|
2028
|
+
]
|
|
2029
|
+
})
|
|
2030
|
+
],
|
|
2031
|
+
["cursor walk over group rows", req({ range: { limit: 2 }, group: { by: ["dept"], keys: [] } })],
|
|
2032
|
+
[
|
|
2033
|
+
"cursor walk with filter",
|
|
2034
|
+
req({ range: { limit: 2 }, filter: { column: "salary", op: "gte", value: 75 } })
|
|
2035
|
+
],
|
|
2036
|
+
[
|
|
2037
|
+
"cursor walk with a projection that leaves out a sort column",
|
|
2038
|
+
req({
|
|
2039
|
+
range: { limit: 3 },
|
|
2040
|
+
sort: [{ column: "salary", dir: "desc" }],
|
|
2041
|
+
columns: ["id", "name"]
|
|
2042
|
+
})
|
|
2043
|
+
],
|
|
2044
|
+
// The key column is always in the row, so a walk stays correct without it in `columns`.
|
|
2045
|
+
[
|
|
2046
|
+
"cursor walk with a projection that leaves out the key",
|
|
2047
|
+
req({ range: { limit: 4 }, columns: ["name"] })
|
|
2048
|
+
]
|
|
2049
|
+
];
|
|
2050
|
+
var tree = (keys, r = {}) => req({ tree: { keys }, ...r });
|
|
2051
|
+
var treeResponseCases = [
|
|
2052
|
+
["tree roots with child counts", tree([])],
|
|
2053
|
+
["tree children of a root", tree([2])],
|
|
2054
|
+
["tree children two levels down", tree([2, 4])],
|
|
2055
|
+
["tree children of a row with no children", tree([2, 5])],
|
|
2056
|
+
["tree path that is not a real chain is empty", tree([1, 4])],
|
|
2057
|
+
["tree path to a row that does not exist is empty", tree([99])],
|
|
2058
|
+
[
|
|
2059
|
+
"tree filter applies to the level and to the child counts",
|
|
2060
|
+
tree([2], { filter: { column: "size", op: "gt", value: 2 } })
|
|
2061
|
+
],
|
|
2062
|
+
["tree quick search ignores case", tree([1, 7], { search: "n" })],
|
|
2063
|
+
["tree sort desc puts nulls last", tree([2, 4], { sort: [{ column: "size", dir: "desc" }] })],
|
|
2064
|
+
["tree projection keeps the key and the child count", tree([2], { columns: ["name"] })],
|
|
2065
|
+
["tree offset page with count", tree([], { range: { start: 1, end: 2 }, count: true })],
|
|
2066
|
+
["tree cursor first page", tree([2, 4], { range: { limit: 2 } })]
|
|
2067
|
+
];
|
|
2068
|
+
var treeWalkCases = [
|
|
2069
|
+
[
|
|
2070
|
+
"tree cursor walk by name",
|
|
2071
|
+
tree([2, 4], { range: { limit: 2 }, sort: [{ column: "name", dir: "asc" }] })
|
|
2072
|
+
]
|
|
2073
|
+
];
|
|
2074
|
+
var treeErrorCases = [
|
|
2075
|
+
["reject tree with group by", tree([], { group: { by: ["size"], keys: [] } }), "not_groupable"],
|
|
2076
|
+
[
|
|
2077
|
+
"reject tree with an aggregate",
|
|
2078
|
+
tree([], { aggregate: [{ column: "size", fn: "sum" }] }),
|
|
2079
|
+
"invalid"
|
|
2080
|
+
],
|
|
2081
|
+
["reject a tree key of the wrong type", { ...tree([]), tree: { keys: ["2"] } }, "invalid"],
|
|
2082
|
+
["reject a null tree key", { ...tree([]), tree: { keys: [null] } }, "invalid"],
|
|
2083
|
+
["reject a tree key that is not an integer", tree([1.5]), "invalid"],
|
|
2084
|
+
[
|
|
2085
|
+
"reject a tree too deep",
|
|
2086
|
+
tree(Array.from({ length: LIMITS.maxTreeDepth + 1 }, (_, i) => i + 1)),
|
|
2087
|
+
"too_deep"
|
|
2088
|
+
],
|
|
2089
|
+
["reject an unknown key in tree", { ...tree([]), tree: { keys: [], depth: 2 } }, "unknown_key"]
|
|
2090
|
+
];
|
|
2091
|
+
var deep = { column: "name", op: "blank" };
|
|
2092
|
+
for (let i = 0; i < LIMITS.maxFilterDepth; i++) deep = { op: "not", node: deep };
|
|
2093
|
+
var errorCases = [
|
|
2094
|
+
["reject unknown column", where({ column: "password", op: "eq", value: "x" }), "unknown_column"],
|
|
2095
|
+
[
|
|
2096
|
+
"reject op not allowed",
|
|
2097
|
+
where({ column: "region", op: "contains", value: "x" }),
|
|
2098
|
+
"op_not_allowed"
|
|
2099
|
+
],
|
|
2100
|
+
["reject value of wrong type", where({ column: "salary", op: "gt", value: "100" }), "invalid"],
|
|
2101
|
+
[
|
|
2102
|
+
"reject aggregate not allowed",
|
|
2103
|
+
req({ aggregate: [{ column: "dept", fn: "max" }] }),
|
|
2104
|
+
"aggregate_not_allowed"
|
|
2105
|
+
],
|
|
2106
|
+
[
|
|
2107
|
+
"reject sum on a string",
|
|
2108
|
+
req({ aggregate: [{ column: "name", fn: "sum" }] }),
|
|
2109
|
+
"aggregate_not_allowed"
|
|
2110
|
+
],
|
|
2111
|
+
[
|
|
2112
|
+
"reject sort on an unknown column",
|
|
2113
|
+
req({ sort: [{ column: "nope", dir: "asc" }] }),
|
|
2114
|
+
"unknown_column"
|
|
2115
|
+
],
|
|
2116
|
+
["reject group not allowed", req({ group: { by: ["name"], keys: [] } }), "not_groupable"],
|
|
2117
|
+
[
|
|
2118
|
+
"reject too many keys",
|
|
2119
|
+
req({ group: { by: ["dept"], keys: ["eng", "west"] } }),
|
|
2120
|
+
"too_many_keys"
|
|
2121
|
+
],
|
|
2122
|
+
["reject end before start", req({ range: { start: 5, end: 1 } }), "bad_range"],
|
|
2123
|
+
["reject a page too big", req({ range: { start: 0, end: LIMITS.maxPage + 1 } }), "bad_range"],
|
|
2124
|
+
["reject a filter too deep", { ...base, filter: deep }, "too_deep"],
|
|
2125
|
+
[
|
|
2126
|
+
"reject a list too long",
|
|
2127
|
+
where({
|
|
2128
|
+
column: "id",
|
|
2129
|
+
op: "in",
|
|
2130
|
+
value: Array.from({ length: LIMITS.maxList + 1 }, (_, i) => i)
|
|
2131
|
+
}),
|
|
2132
|
+
"too_long"
|
|
2133
|
+
],
|
|
2134
|
+
["reject an unknown key", { ...base, sql: "DROP TABLE people" }, "unknown_key"],
|
|
2135
|
+
[
|
|
2136
|
+
"reject a __proto__ key",
|
|
2137
|
+
JSON.parse(`{"__proto__":{"admin":true},${JSON.stringify(base).slice(1)}`),
|
|
2138
|
+
"unknown_key"
|
|
2139
|
+
],
|
|
2140
|
+
["reject a bad cursor", req({ range: { after: "%%%", limit: 2 } }), "bad_cursor"],
|
|
2141
|
+
[
|
|
2142
|
+
"reject a NUL character in a string",
|
|
2143
|
+
where({ column: "name", op: "eq", value: "a\0b" }),
|
|
2144
|
+
"bad_string"
|
|
2145
|
+
],
|
|
2146
|
+
[
|
|
2147
|
+
"reject a date with year 0000",
|
|
2148
|
+
where({ column: "hired", op: "gt", value: "0000-01-01" }),
|
|
2149
|
+
"invalid"
|
|
2150
|
+
],
|
|
2151
|
+
["reject a lone surrogate", where({ column: "name", op: "eq", value: "a\uD800b" }), "bad_string"],
|
|
2152
|
+
[
|
|
2153
|
+
"reject a date that does not exist",
|
|
2154
|
+
where({ column: "hired", op: "gt", value: "2021-02-29" }),
|
|
2155
|
+
"invalid"
|
|
2156
|
+
],
|
|
2157
|
+
[
|
|
2158
|
+
"reject a pivot with too many distinct values",
|
|
2159
|
+
req({ pivot: { by: ["bucket"], values: [{ column: "id", fn: "count" }] } }),
|
|
2160
|
+
"pivot_too_wide",
|
|
2161
|
+
"wide"
|
|
2162
|
+
],
|
|
2163
|
+
["reject tree data on a table with no tree column", tree([]), "invalid"]
|
|
2164
|
+
];
|
|
2165
|
+
function conformanceCases() {
|
|
2166
|
+
const datasets = {
|
|
2167
|
+
people: { columns: peopleColumns, rows: peopleRows },
|
|
2168
|
+
wide: { columns: wideColumns, rows: wideRows },
|
|
2169
|
+
tree_parent: { columns: treeParentColumns, rows: treeParentRows },
|
|
2170
|
+
tree_path: { columns: treePathColumns, rows: treePathRows }
|
|
2171
|
+
};
|
|
2172
|
+
const dataset = "people";
|
|
2173
|
+
const run = (r, d = dataset) => evaluate(r, datasets[d].rows, datasets[d].columns);
|
|
2174
|
+
const response = (name, request, d = dataset) => ({
|
|
2175
|
+
name,
|
|
2176
|
+
dataset: d,
|
|
2177
|
+
request,
|
|
2178
|
+
expected: run(request, d)
|
|
2179
|
+
});
|
|
2180
|
+
const walk = (name, request, d = dataset) => {
|
|
2181
|
+
const pages = [];
|
|
2182
|
+
let res = run(request, d);
|
|
2183
|
+
pages.push(res.rows);
|
|
2184
|
+
while (res.cursor?.next) {
|
|
2185
|
+
res = run(
|
|
2186
|
+
{
|
|
2187
|
+
...request,
|
|
2188
|
+
range: { after: res.cursor.next, limit: request.range.limit }
|
|
2189
|
+
},
|
|
2190
|
+
d
|
|
2191
|
+
);
|
|
2192
|
+
pages.push(res.rows);
|
|
2193
|
+
}
|
|
2194
|
+
return { name, dataset: d, request, pages, count: res.count };
|
|
2195
|
+
};
|
|
2196
|
+
const error = (name, request, code, d = dataset) => {
|
|
2197
|
+
const codes = errorCodes(() => run(request, d));
|
|
2198
|
+
if (!codes.includes(code))
|
|
2199
|
+
throw new Error(`conformance case "${name}": evaluator gave ${codes.join(", ")}`);
|
|
2200
|
+
return { name, dataset: d, request, error: code };
|
|
2201
|
+
};
|
|
2202
|
+
const trees = ["tree_parent", "tree_path"];
|
|
2203
|
+
const cases = [
|
|
2204
|
+
...responseCases.map(([name, request]) => response(name, request)),
|
|
2205
|
+
...walkCases.map(([name, request]) => walk(name, request)),
|
|
2206
|
+
...errorCases.map(([name, request, code, d]) => error(name, request, code, d)),
|
|
2207
|
+
...trees.flatMap((d) => [
|
|
2208
|
+
...treeResponseCases.map(([name, request]) => response(`${name} (${d})`, request, d)),
|
|
2209
|
+
...treeWalkCases.map(([name, request]) => walk(`${name} (${d})`, request, d)),
|
|
2210
|
+
...treeErrorCases.map(([name, request, code]) => error(`${name} (${d})`, request, code, d))
|
|
2211
|
+
])
|
|
2212
|
+
];
|
|
2213
|
+
return JSON.parse(
|
|
2214
|
+
JSON.stringify({
|
|
2215
|
+
version: 1,
|
|
2216
|
+
datasets,
|
|
2217
|
+
cases
|
|
2218
|
+
})
|
|
2219
|
+
);
|
|
2220
|
+
}
|
|
2221
|
+
function errorCodes(f) {
|
|
2222
|
+
try {
|
|
2223
|
+
f();
|
|
2224
|
+
return [];
|
|
2225
|
+
} catch (e) {
|
|
2226
|
+
if (e instanceof ProtocolValidationError) return e.errors.map((x) => x.code);
|
|
2227
|
+
throw e;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
async function checkCase(c, handler) {
|
|
2231
|
+
const call = (r) => handler(r, c.dataset);
|
|
2232
|
+
if ("error" in c) {
|
|
2233
|
+
const res2 = await call(c.request);
|
|
2234
|
+
if (!("errors" in res2)) return [`${c.name}: the server must reject the request`];
|
|
2235
|
+
return res2.errors.some((e) => e.code === c.error) ? [] : [`${c.name}: no error with code "${c.error}"`];
|
|
2236
|
+
}
|
|
2237
|
+
if ("expected" in c) {
|
|
2238
|
+
const res2 = await call(c.request);
|
|
2239
|
+
return "errors" in res2 ? [`${c.name}: unexpected errors`] : compareResponse(res2, c.expected).map((d) => `${c.name}: ${d}`);
|
|
2240
|
+
}
|
|
2241
|
+
const out = [];
|
|
2242
|
+
const limit = c.request.range.limit;
|
|
2243
|
+
let res = await call(c.request);
|
|
2244
|
+
for (let i = 0; ; i++) {
|
|
2245
|
+
if ("errors" in res) return [`${c.name}: unexpected errors on page ${i}`];
|
|
2246
|
+
if (i >= c.pages.length) return [`${c.name}: more pages than expected`];
|
|
2247
|
+
out.push(...diff(res.rows, c.pages[i], `page ${i}`).map((d) => `${c.name}: ${d}`));
|
|
2248
|
+
const next = res.cursor?.next;
|
|
2249
|
+
if (!next) {
|
|
2250
|
+
if (i !== c.pages.length - 1)
|
|
2251
|
+
out.push(`${c.name}: ${c.pages.length} pages expected, got ${i + 1}`);
|
|
2252
|
+
if (res.count !== c.count) out.push(`${c.name}: the last page must have count ${c.count}`);
|
|
2253
|
+
return out;
|
|
2254
|
+
}
|
|
2255
|
+
res = await call({ ...c.request, range: { after: next, limit } });
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
function compareResponse(actual, expected) {
|
|
2259
|
+
const out = diff(actual.rows, expected.rows, "rows");
|
|
2260
|
+
for (const k of ["count", "total", "pivotColumns"])
|
|
2261
|
+
out.push(...diff(actual[k], expected[k], k));
|
|
2262
|
+
const presence = (r) => r.cursor === void 0 ? "none" : `next:${r.cursor.next !== void 0} prev:${r.cursor.prev !== void 0}`;
|
|
2263
|
+
if (presence(actual) !== presence(expected))
|
|
2264
|
+
out.push(`cursor: expected ${presence(expected)}, got ${presence(actual)}`);
|
|
2265
|
+
return out;
|
|
2266
|
+
}
|
|
2267
|
+
function diff(a, e, path) {
|
|
2268
|
+
if (isNumber(a) && isNumber(e)) {
|
|
2269
|
+
return Math.abs(a - e) <= 1e-9 * Math.max(1, Math.abs(a), Math.abs(e)) ? [] : [`${path}: expected ${e}, got ${a}`];
|
|
2270
|
+
}
|
|
2271
|
+
if (isArray(a) && isArray(e)) {
|
|
2272
|
+
if (a.length !== e.length) return [`${path}: expected ${e.length} items, got ${a.length}`];
|
|
2273
|
+
return a.flatMap((x, i) => diff(x, e[i], `${path}[${i}]`));
|
|
2274
|
+
}
|
|
2275
|
+
if (isPlainObject(a) && isPlainObject(e)) {
|
|
2276
|
+
const ka = Object.keys(a).sort();
|
|
2277
|
+
const ke = Object.keys(e).sort();
|
|
2278
|
+
if (ka.join("\0") !== ke.join("\0"))
|
|
2279
|
+
return [`${path}: expected keys ${ke.join(",")}, got ${ka.join(",")}`];
|
|
2280
|
+
return ke.flatMap((k) => diff(a[k], e[k], `${path}.${k}`));
|
|
2281
|
+
}
|
|
2282
|
+
return a === e ? [] : [`${path}: expected ${JSON.stringify(e)}, got ${JSON.stringify(a)}`];
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
// src/ag-grid/index.ts
|
|
2286
|
+
var AgGridTranslationError = class extends Error {
|
|
2287
|
+
constructor(message) {
|
|
2288
|
+
super(message);
|
|
2289
|
+
this.name = "AgGridTranslationError";
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
var fail = (message) => {
|
|
2293
|
+
throw new AgGridTranslationError(message);
|
|
2294
|
+
};
|
|
2295
|
+
var get = (o, k) => Object.hasOwn(o, k) ? o[k] : void 0;
|
|
2296
|
+
var rec = (v, what) => isPlainObject(v) ? v : fail(`${what} must be an object`);
|
|
2297
|
+
var arr = (v, what) => isArray(v) ? v.length <= LIMITS.maxList ? v : fail(`${what} is too long`) : fail(`${what} must be an array`);
|
|
2298
|
+
var str2 = (v, what) => isString(v) ? v : fail(`${what} must be a string`);
|
|
2299
|
+
var nothing = (column2) => ({
|
|
2300
|
+
op: "and",
|
|
2301
|
+
nodes: [
|
|
2302
|
+
{ column: column2, op: "blank" },
|
|
2303
|
+
{ column: column2, op: "notBlank" }
|
|
2304
|
+
]
|
|
2305
|
+
});
|
|
2306
|
+
function fromAgGrid(request, options = {}) {
|
|
2307
|
+
const r = rec(request, "request");
|
|
2308
|
+
const types = new Map((options.columns ?? []).map((c) => [c.name, c.type]));
|
|
2309
|
+
const t = new Translator(types, options.inRangeInclusive === true);
|
|
2310
|
+
const startRow = get(r, "startRow") ?? 0;
|
|
2311
|
+
if (!isSafeInteger(startRow)) fail("startRow must be an integer");
|
|
2312
|
+
const endRow = get(r, "endRow") ?? startRow + LIMITS.maxPage;
|
|
2313
|
+
if (!isSafeInteger(endRow)) fail("endRow must be an integer");
|
|
2314
|
+
const ids = (k) => arr(get(r, k) ?? [], k).map((c, i) => str2(rec(c, `${k}[${i}]`)["id"], `${k}[${i}].id`));
|
|
2315
|
+
const by = ids("rowGroupCols");
|
|
2316
|
+
const tree2 = options.treeData === true;
|
|
2317
|
+
if (tree2 && by.length > 0) fail("tree data has no row group columns");
|
|
2318
|
+
const keyColumn = (options.columns ?? []).find((c) => c.key === true)?.name ?? "";
|
|
2319
|
+
const keys = arr(get(r, "groupKeys") ?? [], "groupKeys").map(
|
|
2320
|
+
(k, i) => t.coerce(tree2 ? keyColumn : by[i] ?? "", str2(k, `groupKeys[${i}]`))
|
|
2321
|
+
);
|
|
2322
|
+
const values = arr(get(r, "valueCols") ?? [], "valueCols").map((c, i) => {
|
|
2323
|
+
const o = rec(c, `valueCols[${i}]`);
|
|
2324
|
+
const id = str2(get(o, "id"), `valueCols[${i}].id`);
|
|
2325
|
+
const fn = str2(
|
|
2326
|
+
get(o, "aggFunc") ?? fail(`valueCols[${i}] has no aggFunc`),
|
|
2327
|
+
`valueCols[${i}].aggFunc`
|
|
2328
|
+
);
|
|
2329
|
+
return { column: id, fn, as: id };
|
|
2330
|
+
});
|
|
2331
|
+
const sort = arr(get(r, "sortModel") ?? [], "sortModel").map((s, i) => {
|
|
2332
|
+
const o = rec(s, `sortModel[${i}]`);
|
|
2333
|
+
if (get(o, "type") === "absolute") fail('sort type "absolute" has no Lattice mapping');
|
|
2334
|
+
const dir = get(o, "sort");
|
|
2335
|
+
if (dir !== "asc" && dir !== "desc") return fail(`sortModel[${i}].sort must be "asc" or "desc"`);
|
|
2336
|
+
return { column: str2(get(o, "colId"), `sortModel[${i}].colId`), dir };
|
|
2337
|
+
});
|
|
2338
|
+
const pivotBy = ids("pivotCols");
|
|
2339
|
+
const pivot = get(r, "pivotMode") === true && pivotBy.length > 0;
|
|
2340
|
+
const out = {
|
|
2341
|
+
v: 1,
|
|
2342
|
+
range: { start: startRow, end: endRow },
|
|
2343
|
+
sort,
|
|
2344
|
+
filter: t.filterModel(get(r, "filterModel")),
|
|
2345
|
+
group: { by, keys: tree2 ? [] : keys },
|
|
2346
|
+
aggregate: pivot ? [] : values
|
|
2347
|
+
};
|
|
2348
|
+
if (pivot) out.pivot = { by: pivotBy, values };
|
|
2349
|
+
if (tree2) out.tree = { keys };
|
|
2350
|
+
return out;
|
|
2351
|
+
}
|
|
2352
|
+
var Translator = class {
|
|
2353
|
+
constructor(types, inclusive) {
|
|
2354
|
+
this.types = types;
|
|
2355
|
+
this.inclusive = inclusive;
|
|
2356
|
+
}
|
|
2357
|
+
types;
|
|
2358
|
+
inclusive;
|
|
2359
|
+
/** AG Grid sends group keys and set values as strings. */
|
|
2360
|
+
coerce(column2, v) {
|
|
2361
|
+
const type = this.types.get(column2);
|
|
2362
|
+
if (type === "number") {
|
|
2363
|
+
const n = Number(v);
|
|
2364
|
+
return v.trim() !== "" && Number.isFinite(n) ? n : fail(`"${v}" is not a number for "${column2}"`);
|
|
2365
|
+
}
|
|
2366
|
+
if (type === "boolean")
|
|
2367
|
+
return v === "true" ? true : v === "false" ? false : fail(`"${v}" is not a boolean`);
|
|
2368
|
+
return v;
|
|
2369
|
+
}
|
|
2370
|
+
filterModel(model) {
|
|
2371
|
+
if (isNull(model) || isUndefined(model)) return null;
|
|
2372
|
+
const m = rec(model, "filterModel");
|
|
2373
|
+
const ft = get(m, "filterType");
|
|
2374
|
+
if (ft === "join" || isString(ft) && isString(get(m, "colId"))) return this.advanced(m, 1);
|
|
2375
|
+
const keys = Object.keys(m);
|
|
2376
|
+
if (keys.length > LIMITS.maxList) fail("filterModel has too many columns");
|
|
2377
|
+
return all(
|
|
2378
|
+
"and",
|
|
2379
|
+
keys.map((colId) => this.column(colId, m[colId], 1))
|
|
2380
|
+
);
|
|
2381
|
+
}
|
|
2382
|
+
column(colId, model, depth) {
|
|
2383
|
+
if (depth > 3) fail("filter model is nested too deep");
|
|
2384
|
+
if (isNull(model) || isUndefined(model)) return null;
|
|
2385
|
+
const m = rec(model, `filterModel.${colId}`);
|
|
2386
|
+
const ft = get(m, "filterType");
|
|
2387
|
+
if (ft === "multi") {
|
|
2388
|
+
const children = get(m, "filterModels");
|
|
2389
|
+
if (isNull(children) || isUndefined(children)) return null;
|
|
2390
|
+
return all(
|
|
2391
|
+
"and",
|
|
2392
|
+
arr(children, "filterModels").map((c) => this.column(colId, c, depth + 1))
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
if (Object.hasOwn(m, "operator")) {
|
|
2396
|
+
const op = get(m, "operator");
|
|
2397
|
+
if (op !== "AND" && op !== "OR") fail('operator must be "AND" or "OR"');
|
|
2398
|
+
const conditions = arr(get(m, "conditions"), "conditions").map(
|
|
2399
|
+
(c) => this.column(colId, c, depth + 1)
|
|
2400
|
+
);
|
|
2401
|
+
return all(op === "AND" ? "and" : "or", conditions);
|
|
2402
|
+
}
|
|
2403
|
+
if (ft === "set") return this.set(colId, arr(get(m, "values"), "values"), "isAnyOf");
|
|
2404
|
+
if (ft === "date")
|
|
2405
|
+
return this.simple(colId, get(m, "type"), get(m, "dateFrom"), get(m, "dateTo"), "date");
|
|
2406
|
+
if (ft === "bigint") fail("bigint filters have no Lattice mapping");
|
|
2407
|
+
if (!isUndefined(ft) && ft !== "text" && ft !== "number")
|
|
2408
|
+
fail(`unknown filterType "${String(ft)}"`);
|
|
2409
|
+
return this.simple(colId, get(m, "type"), get(m, "filter"), get(m, "filterTo"), "scalar");
|
|
2410
|
+
}
|
|
2411
|
+
advanced(m, depth) {
|
|
2412
|
+
if (depth > LIMITS.maxFilterDepth)
|
|
2413
|
+
fail(`advanced filter depth is at most ${LIMITS.maxFilterDepth}`);
|
|
2414
|
+
const ft = get(m, "filterType");
|
|
2415
|
+
if (ft === "join") {
|
|
2416
|
+
const type2 = get(m, "type");
|
|
2417
|
+
if (type2 !== "AND" && type2 !== "OR") fail('join type must be "AND" or "OR"');
|
|
2418
|
+
const conditions = arr(get(m, "conditions"), "conditions").map(
|
|
2419
|
+
(c) => this.advanced(rec(c, "condition"), depth + 1)
|
|
2420
|
+
);
|
|
2421
|
+
return all(type2 === "AND" ? "and" : "or", conditions);
|
|
2422
|
+
}
|
|
2423
|
+
const colId = str2(get(m, "colId"), "colId");
|
|
2424
|
+
const type = get(m, "type");
|
|
2425
|
+
switch (ft) {
|
|
2426
|
+
case "set":
|
|
2427
|
+
if (type !== "isAnyOf" && type !== "isNoneOf")
|
|
2428
|
+
return fail('set type must be "isAnyOf" or "isNoneOf"');
|
|
2429
|
+
return this.set(colId, arr(get(m, "values"), "values"), type);
|
|
2430
|
+
case "boolean":
|
|
2431
|
+
if (type === "true" || type === "false")
|
|
2432
|
+
return { column: colId, op: "eq", value: type === "true" };
|
|
2433
|
+
return this.simple(colId, type, void 0, void 0, "scalar");
|
|
2434
|
+
case "text":
|
|
2435
|
+
case "object":
|
|
2436
|
+
case "number":
|
|
2437
|
+
return this.simple(colId, type, get(m, "filter"), get(m, "filterTo"), "scalar");
|
|
2438
|
+
case "date":
|
|
2439
|
+
case "dateString":
|
|
2440
|
+
case "dateTime":
|
|
2441
|
+
case "dateTimeString":
|
|
2442
|
+
return this.simple(colId, type, get(m, "filter"), get(m, "filterTo"), "date");
|
|
2443
|
+
case "bigint":
|
|
2444
|
+
return fail("bigint filters have no Lattice mapping");
|
|
2445
|
+
default:
|
|
2446
|
+
return fail(`unknown filterType "${String(ft)}"`);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
set(colId, values, type) {
|
|
2450
|
+
const hasNull = values.some(isNull);
|
|
2451
|
+
const keys = values.filter((v) => !isNull(v)).map((v) => this.coerce(colId, str2(v, "set value")));
|
|
2452
|
+
if (type === "isAnyOf") {
|
|
2453
|
+
const nodes2 = [];
|
|
2454
|
+
if (keys.length) nodes2.push({ column: colId, op: "in", value: keys });
|
|
2455
|
+
if (hasNull) nodes2.push({ column: colId, op: "blank" });
|
|
2456
|
+
return all("or", nodes2) ?? nothing(colId);
|
|
2457
|
+
}
|
|
2458
|
+
const nodes = [];
|
|
2459
|
+
if (keys.length) nodes.push({ column: colId, op: "notIn", value: keys });
|
|
2460
|
+
if (hasNull) nodes.push({ column: colId, op: "notBlank" });
|
|
2461
|
+
return all("and", nodes);
|
|
2462
|
+
}
|
|
2463
|
+
simple(colId, type, from, to, kind) {
|
|
2464
|
+
const value = (v) => {
|
|
2465
|
+
if (kind === "date") return str2(v, `${colId} date`).replace(" ", "T");
|
|
2466
|
+
if (isString(v) || isNumber(v) || isBoolean(v)) return v;
|
|
2467
|
+
return fail(`${colId}: the filter value is missing`);
|
|
2468
|
+
};
|
|
2469
|
+
const leaf = (op) => ({
|
|
2470
|
+
column: colId,
|
|
2471
|
+
op,
|
|
2472
|
+
value: value(from)
|
|
2473
|
+
});
|
|
2474
|
+
switch (type) {
|
|
2475
|
+
case void 0:
|
|
2476
|
+
case null:
|
|
2477
|
+
case "empty":
|
|
2478
|
+
return null;
|
|
2479
|
+
case "equals":
|
|
2480
|
+
return leaf("eq");
|
|
2481
|
+
case "notEqual":
|
|
2482
|
+
return leaf("ne");
|
|
2483
|
+
case "lessThan":
|
|
2484
|
+
return leaf("lt");
|
|
2485
|
+
case "lessThanOrEqual":
|
|
2486
|
+
return leaf("lte");
|
|
2487
|
+
case "greaterThan":
|
|
2488
|
+
return leaf("gt");
|
|
2489
|
+
case "greaterThanOrEqual":
|
|
2490
|
+
return leaf("gte");
|
|
2491
|
+
case "contains":
|
|
2492
|
+
return leaf("contains");
|
|
2493
|
+
case "notContains":
|
|
2494
|
+
return { op: "not", node: leaf("contains") };
|
|
2495
|
+
case "startsWith":
|
|
2496
|
+
return leaf("startsWith");
|
|
2497
|
+
case "endsWith":
|
|
2498
|
+
return leaf("endsWith");
|
|
2499
|
+
case "blank":
|
|
2500
|
+
return { column: colId, op: "blank" };
|
|
2501
|
+
case "notBlank":
|
|
2502
|
+
return { column: colId, op: "notBlank" };
|
|
2503
|
+
case "inRange": {
|
|
2504
|
+
const lo = value(from);
|
|
2505
|
+
const hi = value(to);
|
|
2506
|
+
if (this.inclusive) return { column: colId, op: "between", value: [lo, hi] };
|
|
2507
|
+
return {
|
|
2508
|
+
op: "and",
|
|
2509
|
+
nodes: [
|
|
2510
|
+
{ column: colId, op: "gt", value: lo },
|
|
2511
|
+
{ column: colId, op: "lt", value: hi }
|
|
2512
|
+
]
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
default:
|
|
2516
|
+
return fail(`${colId}: filter option "${String(type)}" has no Lattice mapping`);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
function all(op, nodes) {
|
|
2521
|
+
const list2 = nodes.filter((n) => n !== null);
|
|
2522
|
+
if (list2.length === 0) return null;
|
|
2523
|
+
return list2.length === 1 ? list2[0] : { op, nodes: list2 };
|
|
2524
|
+
}
|
|
2525
|
+
function agGridTree(key) {
|
|
2526
|
+
const count = (row) => {
|
|
2527
|
+
const n = row[GROUP_COUNT_KEY];
|
|
2528
|
+
return isNumber(n) ? n : 0;
|
|
2529
|
+
};
|
|
2530
|
+
return {
|
|
2531
|
+
treeData: true,
|
|
2532
|
+
isServerSideGroup: (row) => count(row) > 0,
|
|
2533
|
+
getServerSideGroupKey: (row) => String(row[key]),
|
|
2534
|
+
getChildCount: count
|
|
2535
|
+
};
|
|
2536
|
+
}
|
|
2537
|
+
function toAgGrid(response, request) {
|
|
2538
|
+
const out = { rowData: response.rows };
|
|
2539
|
+
if (response.pivotColumns) {
|
|
2540
|
+
const rename = new Map(
|
|
2541
|
+
response.pivotColumns.map((p) => [p.field, [...p.keys.map((k) => String(k)), p.value].join("_")])
|
|
2542
|
+
);
|
|
2543
|
+
out.rowData = response.rows.map(
|
|
2544
|
+
(row) => Object.fromEntries(Object.entries(row).map(([k, v]) => [rename.get(k) ?? k, v]))
|
|
2545
|
+
);
|
|
2546
|
+
out.pivotResultFields = [...rename.values()];
|
|
2547
|
+
}
|
|
2548
|
+
if (response.count !== void 0) out.rowCount = response.count;
|
|
2549
|
+
if (response.total !== void 0 && request && (request.groupKeys ?? []).length === 0) {
|
|
2550
|
+
out.grandTotalData = response.total;
|
|
2551
|
+
}
|
|
2552
|
+
return out;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
export { AGGREGATE_FNS, AgGridTranslationError, FILTER_OPS, GROUP_COUNT_KEY, LIMITS, PROTOCOL_VERSION, ProtocolValidationError, TREE_PATH_SEPARATOR, agGridTree, aggregateKey, checkCase, compareResponse, conformanceCases, evaluate, fromAgGrid, matchesFilter, mutateResultSchema, parseRowsRequest, rowOpSchema, rowsRequestSchema, rowsResponseSchema, toAgGrid, transactionSchema };
|
|
2556
|
+
//# sourceMappingURL=index.js.map
|
|
2557
|
+
//# sourceMappingURL=index.js.map
|