@routier/core 0.5.0 → 0.7.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.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/dist/assertions/index.cjs +19 -8
  3. package/dist/assertions/index.cjs.map +1 -1
  4. package/dist/assertions/index.d.ts +5 -1
  5. package/dist/assertions/index.js +21 -9
  6. package/dist/assertions/index.js.map +1 -1
  7. package/dist/collections/MemoryDataCollection.d.ts +10 -0
  8. package/dist/collections/index.cjs +29 -4
  9. package/dist/collections/index.cjs.map +1 -1
  10. package/dist/collections/index.js +29 -4
  11. package/dist/collections/index.js.map +1 -1
  12. package/dist/expressions/callSource.d.ts +41 -0
  13. package/dist/expressions/evaluate.d.ts +3 -0
  14. package/dist/expressions/fold.d.ts +7 -0
  15. package/dist/expressions/index.cjs +1754 -233
  16. package/dist/expressions/index.cjs.map +1 -1
  17. package/dist/expressions/index.d.ts +2 -0
  18. package/dist/expressions/index.js +1765 -234
  19. package/dist/expressions/index.js.map +1 -1
  20. package/dist/expressions/types.d.ts +45 -26
  21. package/dist/expressions/utils.d.ts +19 -1
  22. package/dist/index.cjs +2429 -363
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.js +2769 -682
  25. package/dist/index.js.map +1 -1
  26. package/dist/performance/index.cjs +6 -4
  27. package/dist/performance/index.cjs.map +1 -1
  28. package/dist/performance/index.js +6 -4
  29. package/dist/performance/index.js.map +1 -1
  30. package/dist/pipeline/index.cjs +6 -4
  31. package/dist/pipeline/index.cjs.map +1 -1
  32. package/dist/pipeline/index.js +6 -4
  33. package/dist/pipeline/index.js.map +1 -1
  34. package/dist/plugins/index.cjs +2323 -316
  35. package/dist/plugins/index.cjs.map +1 -1
  36. package/dist/plugins/index.d.ts +1 -0
  37. package/dist/plugins/index.js +2328 -311
  38. package/dist/plugins/index.js.map +1 -1
  39. package/dist/plugins/query/QueryOptionsCollection.d.ts +38 -10
  40. package/dist/plugins/query/describeFilter.d.ts +83 -0
  41. package/dist/plugins/query/explain.d.ts +71 -9
  42. package/dist/plugins/query/index.d.ts +1 -0
  43. package/dist/plugins/query/join.d.ts +4 -1
  44. package/dist/plugins/query/types.d.ts +36 -4
  45. package/dist/plugins/resultShape.d.ts +35 -0
  46. package/dist/schema/PropertyInfo.d.ts +0 -1
  47. package/dist/schema/index.cjs +7 -14
  48. package/dist/schema/index.cjs.map +1 -1
  49. package/dist/schema/index.js +7 -14
  50. package/dist/schema/index.js.map +1 -1
  51. package/dist/transfer/ChunkEncoder.d.ts +60 -0
  52. package/dist/transfer/decoder.d.ts +29 -0
  53. package/dist/transfer/fillers.d.ts +36 -0
  54. package/dist/transfer/index.cjs +873 -0
  55. package/dist/transfer/index.cjs.map +1 -0
  56. package/dist/transfer/index.d.ts +47 -0
  57. package/dist/transfer/index.js +872 -0
  58. package/dist/transfer/index.js.map +1 -0
  59. package/dist/transfer/plan.d.ts +94 -0
  60. package/dist/transfer/types.d.ts +138 -0
  61. package/dist/utilities/index.cjs +242 -49
  62. package/dist/utilities/index.cjs.map +1 -1
  63. package/dist/utilities/index.js +242 -49
  64. package/dist/utilities/index.js.map +1 -1
  65. package/package.json +9 -1
@@ -0,0 +1,60 @@
1
+ import { EncodedTransfer, TransferPlan } from './types';
2
+ /**
3
+ * Fills one chunk at a time from row values, and emits it with the buffers its transport can hand
4
+ * over.
5
+ *
6
+ * One encoder per result, not per chunk: a column that falls back to `clone` stays there for
7
+ * every later chunk, and a forward-only cursor cannot rewind to re-encode what it already yielded.
8
+ *
9
+ * Usage is a loop — `appendRow` or `appendRecord` until `isFull`, `take`, repeat, then `take` once
10
+ * more for the short final chunk. A zero-row result takes exactly one chunk with `rowCount: 0`.
11
+ */
12
+ export declare class ChunkEncoder {
13
+ private readonly columns;
14
+ private readonly fillers;
15
+ private readonly inheritedNames;
16
+ private rows;
17
+ constructor(plan: TransferPlan);
18
+ /** Rows in the chunk being filled. */
19
+ get rowCount(): number;
20
+ get isFull(): boolean;
21
+ /** The column names, in the order a row's values must arrive in. */
22
+ get columnNames(): readonly string[];
23
+ /**
24
+ * Adds one row, its values in plan column order.
25
+ *
26
+ * A value that does not belong in its column's encoding sends that column to `clone` for the
27
+ * rest of the result, carrying the rows already written with it. Nothing is coerced into a
28
+ * typed array.
29
+ */
30
+ appendRow(values: readonly unknown[]): void;
31
+ /**
32
+ * Adds one row from a NAME-KEYED record, reading each planned column out of it.
33
+ *
34
+ * For an engine that yields records rather than positional tuples — a document store, a
35
+ * key-value store, a driver that returns row objects. Projecting to an array is the caller's
36
+ * alternative, and getting that order wrong is silent corruption rather than an error, so the
37
+ * mapping belongs here once instead of in every plugin.
38
+ *
39
+ * A column the record does not carry is `null`, not an error. Records are legitimately
40
+ * heterogeneous outside a fixed-schema table, and the plan is what decides the result shape.
41
+ */
42
+ appendRecord(record: Record<string, unknown>): void;
43
+ /**
44
+ * A plain read, unless a planned name is one the prototype chain answers for.
45
+ *
46
+ * `record['__proto__']` on an object literal returns `Object.prototype` rather than
47
+ * `undefined`, and `toString` returns a function — either would be encoded as a value. The
48
+ * own-property test that avoids it costs a call per field, so it is only taken when a name in
49
+ * this plan actually needs it.
50
+ */
51
+ private readField;
52
+ /**
53
+ * Emits the filled chunk and readies the encoder for the next one.
54
+ *
55
+ * Transfer DETACHES the emitted buffers, so the fillers allocate fresh arrays here rather
56
+ * than reusing them. Reading a chunk's typed arrays after this is a use-after-transfer.
57
+ */
58
+ take(): EncodedTransfer;
59
+ private fallBack;
60
+ }
@@ -0,0 +1,29 @@
1
+ import { EncodedChunk, TransferPlan } from './types';
2
+ /**
3
+ * A chunk's JSON document did not parse.
4
+ *
5
+ * Reported as its own shape so a caller can retry the request WITHOUT a plan and get today's
6
+ * clone path, which parses row by row and tolerates a field holding text that is not JSON.
7
+ * Every other decode failure is a real error.
8
+ *
9
+ * Read structurally rather than with `instanceof`: an error constructed in another realm — Jest
10
+ * gives each test file its own — fails the prototype test for exactly the cases this classifies.
11
+ */
12
+ export type TransferJsonError = Error & {
13
+ readonly transferJsonColumn: string;
14
+ };
15
+ export declare const isTransferJsonError: (error: unknown) => error is TransferJsonError;
16
+ /** Emptied between tests. Not part of the decoding contract. */
17
+ export declare const clearDecoderCache: () => void;
18
+ export declare const isTransferCodecSupported: () => boolean;
19
+ /**
20
+ * Decodes one chunk into final-shape row objects — real booleans, `Date` objects, parsed JSON.
21
+ *
22
+ * Not the raw storage shape. The entity needs the final shape either way, and decoding to raw and
23
+ * re-shaping afterwards measured slower (156ms against 140ms at 100,000 rows). An absent or null
24
+ * value becomes JavaScript `null`, never `undefined` and never an absent property.
25
+ *
26
+ * A column that fell back to `clone` in the worker comes back RAW, and the caller still owes it
27
+ * whatever shaping that column would otherwise have had.
28
+ */
29
+ export declare const decodeChunk: (plan: TransferPlan, chunk: EncodedChunk) => unknown[];
@@ -0,0 +1,36 @@
1
+ import { EncodedColumn, TransferEncoding } from './types';
2
+ /**
3
+ * One column being filled, one strategy per encoding.
4
+ *
5
+ * `set` answers `false` rather than coercing a value that does not belong in its encoding. A
6
+ * schema type does not prove what an engine will actually return — custom serializers,
7
+ * migrations and external writers can put anything in a field — so the encoder validates every
8
+ * value it writes instead of trusting the plan. The caller turns a refusal into a fallback to
9
+ * `clone`.
10
+ */
11
+ export interface ColumnFiller {
12
+ readonly encoding: TransferEncoding;
13
+ set(index: number, value: unknown): boolean;
14
+ /** Rows `0..count` as raw values, which is what a fallback to `clone` has to carry forward. */
15
+ drain(count: number): unknown[];
16
+ emit(rowCount: number, transferables: ArrayBufferLike[]): EncodedColumn;
17
+ /** Readies the filler for the next chunk. Transfer detaches the buffers, so they are replaced. */
18
+ reset(): void;
19
+ }
20
+ /**
21
+ * Raw values in a plain array, structured-cloned as they are.
22
+ *
23
+ * Strings live here and are never encoded. `TextEncoder` loses to clone by a wide margin —
24
+ * 14.0ms against 8.3ms for 4,000 rows of 2KB text — because cloning a V8 string is a native
25
+ * memcpy.
26
+ */
27
+ export declare class CloneFiller implements ColumnFiller {
28
+ readonly encoding: "clone";
29
+ private data;
30
+ constructor(seed?: unknown[]);
31
+ set(index: number, value: unknown): boolean;
32
+ drain(count: number): unknown[];
33
+ emit(rowCount: number): EncodedColumn;
34
+ reset(): void;
35
+ }
36
+ export declare const createFiller: (encoding: TransferEncoding) => ColumnFiller;