@colin_kerr/query-agent-client 0.0.0-stage → 0.1.1

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/cjs/agent-client.d.ts +107 -0
  4. package/dist/cjs/agent-client.js +142 -0
  5. package/dist/cjs/agent-client.js.map +1 -0
  6. package/dist/cjs/caps.d.ts +43 -0
  7. package/dist/cjs/caps.js +51 -0
  8. package/dist/cjs/caps.js.map +1 -0
  9. package/dist/cjs/client.d.ts +145 -0
  10. package/dist/cjs/client.js +270 -0
  11. package/dist/cjs/client.js.map +1 -0
  12. package/dist/cjs/index.d.ts +11 -0
  13. package/dist/cjs/index.js +28 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/node/index.d.ts +27 -0
  16. package/dist/cjs/node/index.js +59 -0
  17. package/dist/cjs/node/index.js.map +1 -0
  18. package/dist/cjs/query-runner.d.ts +34 -0
  19. package/dist/cjs/query-runner.js +41 -0
  20. package/dist/cjs/query-runner.js.map +1 -0
  21. package/dist/cjs/result-pages.d.ts +69 -0
  22. package/dist/cjs/result-pages.js +176 -0
  23. package/dist/cjs/result-pages.js.map +1 -0
  24. package/dist/cjs/selection.d.ts +90 -0
  25. package/dist/cjs/selection.js +222 -0
  26. package/dist/cjs/selection.js.map +1 -0
  27. package/dist/cjs/startup-queries.json +182 -0
  28. package/dist/cjs/turn-api.d.ts +156 -0
  29. package/dist/cjs/turn-api.js +19 -0
  30. package/dist/cjs/turn-api.js.map +1 -0
  31. package/dist/esm/agent-client.d.ts +107 -0
  32. package/dist/esm/agent-client.js +134 -0
  33. package/dist/esm/agent-client.js.map +1 -0
  34. package/dist/esm/caps.d.ts +43 -0
  35. package/dist/esm/caps.js +48 -0
  36. package/dist/esm/caps.js.map +1 -0
  37. package/dist/esm/client.d.ts +145 -0
  38. package/dist/esm/client.js +260 -0
  39. package/dist/esm/client.js.map +1 -0
  40. package/dist/esm/index.d.ts +11 -0
  41. package/dist/esm/index.js +12 -0
  42. package/dist/esm/index.js.map +1 -0
  43. package/dist/esm/query-runner.d.ts +34 -0
  44. package/dist/esm/query-runner.js +38 -0
  45. package/dist/esm/query-runner.js.map +1 -0
  46. package/dist/esm/result-pages.d.ts +69 -0
  47. package/dist/esm/result-pages.js +172 -0
  48. package/dist/esm/result-pages.js.map +1 -0
  49. package/dist/esm/selection.d.ts +90 -0
  50. package/dist/esm/selection.js +212 -0
  51. package/dist/esm/selection.js.map +1 -0
  52. package/dist/esm/startup-queries.json +182 -0
  53. package/dist/esm/turn-api.d.ts +156 -0
  54. package/dist/esm/turn-api.js +16 -0
  55. package/dist/esm/turn-api.js.map +1 -0
  56. package/package.json +67 -4
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /**
3
+ * An answer's results with no row limit, read a page at a time for a virtualized table.
4
+ *
5
+ * Each page is its own read through the iTwin.js query reader, with the reader's `limit` option
6
+ * (`QueryPageOptions`), which is how the reader pages internally too: every page it reads is a
7
+ * request with an offset and a count. Nothing here rewrites the query. The total is read once,
8
+ * with `SELECT COUNT(*)` over the query, as the iTwin.js tests count a paged result; until it is
9
+ * known, or when the query cannot be counted that way, the rows read so far are the lower bound.
10
+ *
11
+ * Pages are read one at a time, for the rows the table last asked for: a fast scroll does not queue
12
+ * up every page it passed. Read pages are kept, so scrolling back costs nothing.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ResultPages = exports.RESULT_PAGE_ROWS = void 0;
16
+ /** How many rows one page reads. */
17
+ exports.RESULT_PAGE_ROWS = 1000;
18
+ /** The query with any trailing semicolons removed, so it can be counted inside `FROM (...)`. */
19
+ function bare(ecsql) {
20
+ return ecsql.trim().replace(/;+\s*$/, "").trim();
21
+ }
22
+ async function readAll(result) {
23
+ const rows = [];
24
+ for await (const row of result.rows)
25
+ rows.push(row);
26
+ return rows;
27
+ }
28
+ class ResultPages {
29
+ runQuery;
30
+ ecsql;
31
+ pageRows;
32
+ pages = new Map();
33
+ listeners = new Set();
34
+ _columns;
35
+ _count;
36
+ _error;
37
+ /** The highest row index known to exist, plus one: the lower bound while the count is unknown. */
38
+ _known = 0;
39
+ wanted;
40
+ loading = false;
41
+ counting;
42
+ constructor(runQuery, ecsql, first, pageRows = exports.RESULT_PAGE_ROWS) {
43
+ this.runQuery = runQuery;
44
+ this.ecsql = ecsql;
45
+ this.pageRows = pageRows;
46
+ if (first) {
47
+ this._columns = first.columns;
48
+ // The first rows fill page 0 only when they are a whole page or all the rows.
49
+ if (first.complete || first.rows.length >= pageRows) {
50
+ this.pages.set(0, first.rows.slice(0, pageRows));
51
+ this._known = Math.min(first.rows.length, pageRows);
52
+ }
53
+ if (first.complete)
54
+ this._count = first.rows.length;
55
+ }
56
+ }
57
+ /** What a run carrying this says of it when written out as JSON: the query and the count, not the rows. */
58
+ toJSON() {
59
+ return { ecsql: this.ecsql, ...(this._count !== undefined ? { count: this._count } : {}) };
60
+ }
61
+ /** The column names, once the first page (or the first rows) has been read. */
62
+ get columns() {
63
+ return this._columns;
64
+ }
65
+ /** The number of rows, when known. */
66
+ get count() {
67
+ return this._count;
68
+ }
69
+ /** How many rows there are at least: the count when known, else the rows found so far. */
70
+ get atLeast() {
71
+ return this._count ?? this._known;
72
+ }
73
+ /** The error the query gave, if a page failed. */
74
+ get error() {
75
+ return this._error;
76
+ }
77
+ /** A row, if its page has been read. */
78
+ row(index) {
79
+ return this.pages.get(Math.floor(index / this.pageRows))?.[index % this.pageRows];
80
+ }
81
+ /** Called whenever a page, the count or an error arrives. Returns a function that stops it. */
82
+ subscribe(listener) {
83
+ this.listeners.add(listener);
84
+ return () => this.listeners.delete(listener);
85
+ }
86
+ /**
87
+ * Ask for the rows from `start` up to `end`: their pages are read, one at a time, unless a later
88
+ * call asks for other rows first. The count is read alongside the first call.
89
+ */
90
+ want(start, end) {
91
+ this.wanted = { start: Math.max(0, start), end: Math.max(start, end) };
92
+ if (this._count === undefined && !this.counting)
93
+ this.counting = this.readCount();
94
+ if (!this.loading)
95
+ void this.loadWanted();
96
+ }
97
+ /** Read every page up to `end` rows (all of them when undefined): for a host or a test. */
98
+ async loadUpTo(end) {
99
+ for (let page = 0;; page++) {
100
+ const start = page * this.pageRows;
101
+ if ((end !== undefined && start >= end) || (this._count !== undefined && start >= this._count))
102
+ return;
103
+ const rows = await this.readPage(page);
104
+ if (rows === undefined || rows.length < this.pageRows)
105
+ return;
106
+ }
107
+ }
108
+ notify() {
109
+ for (const listener of this.listeners)
110
+ listener();
111
+ }
112
+ async readCount() {
113
+ try {
114
+ const result = await this.runQuery(`SELECT COUNT(*) FROM (${bare(this.ecsql)})`);
115
+ const [row] = await readAll(result);
116
+ const count = Number(row?.[0]);
117
+ if (Number.isFinite(count) && count >= 0) {
118
+ this._count = count;
119
+ this.notify();
120
+ }
121
+ }
122
+ catch {
123
+ // Some queries cannot be wrapped (a CTE, for one): the end is found when a page comes back short.
124
+ }
125
+ }
126
+ /** The next page the wanted rows need that has not been read, or undefined. */
127
+ nextWantedPage() {
128
+ if (!this.wanted || this._error !== undefined)
129
+ return undefined;
130
+ const last = this._count !== undefined ? Math.min(this.wanted.end, this._count) : this.wanted.end;
131
+ for (let page = Math.floor(this.wanted.start / this.pageRows); page * this.pageRows < last; page++) {
132
+ if (!this.pages.has(page))
133
+ return page;
134
+ }
135
+ return undefined;
136
+ }
137
+ async loadWanted() {
138
+ this.loading = true;
139
+ try {
140
+ for (let page = this.nextWantedPage(); page !== undefined; page = this.nextWantedPage()) {
141
+ const rows = await this.readPage(page);
142
+ // A failed page stops the reading; a short one is the last.
143
+ if (rows === undefined || rows.length < this.pageRows)
144
+ break;
145
+ }
146
+ }
147
+ finally {
148
+ this.loading = false;
149
+ }
150
+ }
151
+ /** Read one page (or return it, read before); undefined when the query failed. */
152
+ async readPage(page) {
153
+ const cached = this.pages.get(page);
154
+ if (cached)
155
+ return cached;
156
+ try {
157
+ const result = await this.runQuery(this.ecsql, { limit: { offset: page * this.pageRows, count: this.pageRows } });
158
+ const rows = await readAll(result);
159
+ this._columns ??= result.columns;
160
+ this.pages.set(page, rows);
161
+ this._known = Math.max(this._known, page * this.pageRows + rows.length);
162
+ // A short page is the last: the count is now known, whether or not COUNT(*) could run.
163
+ if (rows.length < this.pageRows && this._count === undefined)
164
+ this._count = page * this.pageRows + rows.length;
165
+ this.notify();
166
+ return rows;
167
+ }
168
+ catch (err) {
169
+ this._error = err instanceof Error ? err.message : String(err);
170
+ this.notify();
171
+ return undefined;
172
+ }
173
+ }
174
+ }
175
+ exports.ResultPages = ResultPages;
176
+ //# sourceMappingURL=result-pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-pages.js","sourceRoot":"","sources":["../../src/result-pages.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAIH,oCAAoC;AACvB,QAAA,gBAAgB,GAAG,IAAI,CAAC;AAUrC,gGAAgG;AAChG,SAAS,IAAI,CAAC,KAAa;IACzB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,MAAsB;IAC3C,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI;QACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAa,WAAW;IAYc;IAAuC;IACtC;IAZpB,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IACvC,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAC3C,QAAQ,CAAuB;IAC/B,MAAM,CAAqB;IAC3B,MAAM,CAAqB;IACnC,kGAAkG;IAC1F,MAAM,GAAG,CAAC,CAAC;IACX,MAAM,CAA6C;IACnD,OAAO,GAAG,KAAK,CAAC;I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EAAE,CAAC,CAAC;YAClH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,OAAO,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YACxE,uFAAuF;YACvF,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;gBAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;YACnD,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC/D,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAzJD,kCAyJC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The elements an answer is about, as instance keys for the host's selection: the selectable mode's
3
+ * `selectionQuery`, run in full on the host's iModel.
4
+ *
5
+ * Nothing here is capped. The number of elements selected is never limited (the owner's decision
6
+ * D6 in the unified selection plan): a cap would select some of the elements and say nothing of
7
+ * the rest. The rows stay with the host. They are never sent to the function.
8
+ */
9
+ import type { RunRawQuery } from "./caps.js";
10
+ /** An element as the unified selection names it: its class (`Schema.Class`) and its id (`0x..`). */
11
+ export interface InstanceKey {
12
+ className: string;
13
+ id: string;
14
+ }
15
+ /** The elements a run's `selectionQuery` returned, or why they could not be read. */
16
+ export type RunSelection = {
17
+ /**
18
+ * The elements, with their classes: all of them, or, when they were handed on in chunks
19
+ * (`readSelection`'s `onKeys`), only the first `SELECTION_SAMPLE`, so a large selection is not
20
+ * held twice. `count` is always the full number.
21
+ */
22
+ keys: InstanceKey[];
23
+ /** How many elements were selected. */
24
+ count: number;
25
+ /** Rows that named no element: no id, or an id that is not an element's (an aspect, a model). */
26
+ notElements: number;
27
+ } | {
28
+ error: string;
29
+ };
30
+ /**
31
+ * How many ids one query asks for the classes of. The runner binds no parameters, so the ids are
32
+ * written into an `IN` list, and a list this long is well inside what SQLite takes.
33
+ */
34
+ export declare const CLASS_BATCH = 1000;
35
+ /** An id as a hex string (`0x1a`), from a hex or decimal string or a number; undefined when it is not one. */
36
+ export declare function toId(value: unknown): string | undefined;
37
+ /**
38
+ * The classes of the ids that are elements, by id, read in batches of `CLASS_BATCH`. An id that is
39
+ * not an element's is not in the map.
40
+ */
41
+ export declare function elementClasses(runQuery: RunRawQuery, ids: readonly string[]): Promise<Map<string, string>>;
42
+ /**
43
+ * The instance keys of ids, for selecting them: each element once, with its class, and how many of
44
+ * the ids were not elements.
45
+ */
46
+ export declare function instanceKeys(runQuery: RunRawQuery, ids: readonly string[]): Promise<{
47
+ keys: InstanceKey[];
48
+ notElements: number;
49
+ }>;
50
+ /** How many keys a selection read in chunks keeps, for a host that wants some of them (to zoom to, say). */
51
+ export declare const SELECTION_SAMPLE = 1000;
52
+ /** How many keys `readSelection` hands on at a time, for a host that adds them to its selection in chunks. */
53
+ export declare const SELECTION_CHUNK = 10000;
54
+ /**
55
+ * Whether classes are element classes (derived from `BisCore.Element`), each read once. Ids are not
56
+ * unique across tables, so a key is an element's only when its class is an element class: an
57
+ * aspect can have the same id as an unrelated element.
58
+ */
59
+ export declare class ElementClassCheck {
60
+ private readonly runQuery;
61
+ private readonly known;
62
+ constructor(runQuery: RunRawQuery);
63
+ isElementClass(name: string): Promise<boolean>;
64
+ private read;
65
+ }
66
+ /** The columns of a result that name elements: the id (`ECInstanceId`, or `id`) and the class (`ClassName`, -1 when absent). */
67
+ export declare function keyColumns(columns: readonly string[]): {
68
+ idAt: number;
69
+ classAt: number;
70
+ };
71
+ /**
72
+ * Whether a result can be selected as it is (the owner's decision D1): it has both the
73
+ * `ECInstanceId` and the `ClassName` columns.
74
+ */
75
+ export declare function hasKeyColumns(columns: readonly string[] | undefined): boolean;
76
+ /**
77
+ * Run a selection query in full and read its rows as instance keys. Each element is kept once.
78
+ *
79
+ * - **The query is read with one reader,** which pages through the result itself; nothing is
80
+ * capped.
81
+ * - **The id is read from the `ECInstanceId` column (or `id`), and the class from `ClassName`.**
82
+ * A key is kept only when its class is an element class (`ElementClassCheck`). Where the query
83
+ * gave no class, it is read from `bis.Element`.
84
+ * - **`onKeys` is given the keys in chunks of `SELECTION_CHUNK`** as they are read, for a host
85
+ * that adds them to its selection as they come.
86
+ * - **`signal`** stops the reading (checked every 1,000 rows): a newer selection supersedes this one.
87
+ *
88
+ * Never throws: a failure is the selection's `error`.
89
+ */
90
+ export declare function readSelection(runQuery: RunRawQuery, ecsql: string, onKeys?: (keys: InstanceKey[]) => void | Promise<void>, signal?: AbortSignal): Promise<RunSelection>;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ /**
3
+ * The elements an answer is about, as instance keys for the host's selection: the selectable mode's
4
+ * `selectionQuery`, run in full on the host's iModel.
5
+ *
6
+ * Nothing here is capped. The number of elements selected is never limited (the owner's decision
7
+ * D6 in the unified selection plan): a cap would select some of the elements and say nothing of
8
+ * the rest. The rows stay with the host. They are never sent to the function.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ElementClassCheck = exports.SELECTION_CHUNK = exports.SELECTION_SAMPLE = exports.CLASS_BATCH = void 0;
12
+ exports.toId = toId;
13
+ exports.elementClasses = elementClasses;
14
+ exports.instanceKeys = instanceKeys;
15
+ exports.keyColumns = keyColumns;
16
+ exports.hasKeyColumns = hasKeyColumns;
17
+ exports.readSelection = readSelection;
18
+ /**
19
+ * How many ids one query asks for the classes of. The runner binds no parameters, so the ids are
20
+ * written into an `IN` list, and a list this long is well inside what SQLite takes.
21
+ */
22
+ exports.CLASS_BATCH = 1_000;
23
+ /** An id as a hex string (`0x1a`), from a hex or decimal string or a number; undefined when it is not one. */
24
+ function toId(value) {
25
+ if (typeof value !== "string" && typeof value !== "number")
26
+ return undefined;
27
+ const text = String(value).trim();
28
+ if (!/^(0x[0-9a-f]+|[0-9]+)$/i.test(text))
29
+ return undefined;
30
+ const id = BigInt(text);
31
+ return id > 0n ? `0x${id.toString(16)}` : undefined;
32
+ }
33
+ /** A class name in the form the selection uses, `Schema.Class`, from that form or `Schema:Class`. */
34
+ function className(value) {
35
+ return typeof value === "string" && value.trim() !== "" ? value.trim().replace(":", ".") : undefined;
36
+ }
37
+ /** The index of the column with one of these names, in any case; -1 when there is none. */
38
+ function columnNamed(columns, ...names) {
39
+ for (const name of names) {
40
+ const index = columns.findIndex((column) => column.toLowerCase() === name);
41
+ if (index >= 0)
42
+ return index;
43
+ }
44
+ return -1;
45
+ }
46
+ /**
47
+ * The classes of the ids that are elements, by id, read in batches of `CLASS_BATCH`. An id that is
48
+ * not an element's is not in the map.
49
+ */
50
+ async function elementClasses(runQuery, ids) {
51
+ const classes = new Map();
52
+ for (let start = 0; start < ids.length; start += exports.CLASS_BATCH) {
53
+ // Each id passed `toId`, so it is a number and safe to write into the query.
54
+ const list = ids.slice(start, start + exports.CLASS_BATCH).map((id) => BigInt(id).toString()).join(",");
55
+ const result = await runQuery(`SELECT ECInstanceId, ec_classname(ECClassId, 's.c') FROM bis.Element WHERE ECInstanceId IN (${list})`);
56
+ for await (const row of result.rows) {
57
+ const id = toId(row[0]);
58
+ const name = className(row[1]);
59
+ if (id && name)
60
+ classes.set(id, name);
61
+ }
62
+ }
63
+ return classes;
64
+ }
65
+ /**
66
+ * The instance keys of ids, for selecting them: each element once, with its class, and how many of
67
+ * the ids were not elements.
68
+ */
69
+ async function instanceKeys(runQuery, ids) {
70
+ const unique = [...new Set(ids.map(toId).filter((id) => id !== undefined))];
71
+ const classes = await elementClasses(runQuery, unique);
72
+ const keys = unique.flatMap((id) => (classes.has(id) ? [{ className: classes.get(id), id }] : []));
73
+ return { keys, notElements: ids.length - keys.length };
74
+ }
75
+ /** How many keys a selection read in chunks keeps, for a host that wants some of them (to zoom to, say). */
76
+ exports.SELECTION_SAMPLE = 1_000;
77
+ /** How many keys `readSelection` hands on at a time, for a host that adds them to its selection in chunks. */
78
+ exports.SELECTION_CHUNK = 10_000;
79
+ /** A class name that is safe to write into a query: `Schema.Class` with word characters only. */
80
+ const CLASS_NAME = /^[A-Za-z_]\w*\.[A-Za-z_]\w*$/;
81
+ /**
82
+ * Whether classes are element classes (derived from `BisCore.Element`), each read once. Ids are not
83
+ * unique across tables, so a key is an element's only when its class is an element class: an
84
+ * aspect can have the same id as an unrelated element.
85
+ */
86
+ class ElementClassCheck {
87
+ runQuery;
88
+ known = new Map();
89
+ constructor(runQuery) {
90
+ this.runQuery = runQuery;
91
+ }
92
+ isElementClass(name) {
93
+ let found = this.known.get(name);
94
+ if (!found) {
95
+ found = this.read(name);
96
+ this.known.set(name, found);
97
+ }
98
+ return found;
99
+ }
100
+ async read(name) {
101
+ if (!CLASS_NAME.test(name))
102
+ return false;
103
+ try {
104
+ const result = await this.runQuery("SELECT COUNT(*) FROM meta.ClassHasAllBaseClasses " +
105
+ `WHERE SourceECInstanceId = ec_classid('${name}') AND TargetECInstanceId = ec_classid('BisCore.Element')`);
106
+ for await (const row of result.rows)
107
+ return Number(row[0]) > 0;
108
+ return false;
109
+ }
110
+ catch {
111
+ return false;
112
+ }
113
+ }
114
+ }
115
+ exports.ElementClassCheck = ElementClassCheck;
116
+ /** The columns of a result that name elements: the id (`ECInstanceId`, or `id`) and the class (`ClassName`, -1 when absent). */
117
+ function keyColumns(columns) {
118
+ return { idAt: columnNamed(columns, "ecinstanceid", "id"), classAt: columnNamed(columns, "classname") };
119
+ }
120
+ /**
121
+ * Whether a result can be selected as it is (the owner's decision D1): it has both the
122
+ * `ECInstanceId` and the `ClassName` columns.
123
+ */
124
+ function hasKeyColumns(columns) {
125
+ const { classAt } = keyColumns(columns ?? []);
126
+ return classAt >= 0 && columnNamed(columns ?? [], "ecinstanceid") >= 0;
127
+ }
128
+ /**
129
+ * Run a selection query in full and read its rows as instance keys. Each element is kept once.
130
+ *
131
+ * - **The query is read with one reader,** which pages through the result itself; nothing is
132
+ * capped.
133
+ * - **The id is read from the `ECInstanceId` column (or `id`), and the class from `ClassName`.**
134
+ * A key is kept only when its class is an element class (`ElementClassCheck`). Where the query
135
+ * gave no class, it is read from `bis.Element`.
136
+ * - **`onKeys` is given the keys in chunks of `SELECTION_CHUNK`** as they are read, for a host
137
+ * that adds them to its selection as they come.
138
+ * - **`signal`** stops the reading (checked every 1,000 rows): a newer selection supersedes this one.
139
+ *
140
+ * Never throws: a failure is the selection's `error`.
141
+ */
142
+ async function readSelection(runQuery, ecsql, onKeys, signal) {
143
+ try {
144
+ const result = await runQuery(ecsql);
145
+ const { idAt, classAt } = keyColumns(result.columns);
146
+ if (idAt < 0)
147
+ return { error: `The selection query returned no ECInstanceId column, only ${JSON.stringify(result.columns)}.` };
148
+ const check = new ElementClassCheck(runQuery);
149
+ // Each element once: the ids seen, by class (no key strings are built for this).
150
+ const seen = new Map();
151
+ const isNew = (name, id) => {
152
+ let ids = seen.get(name);
153
+ if (!ids) {
154
+ ids = new Set();
155
+ seen.set(name, ids);
156
+ }
157
+ if (ids.has(id))
158
+ return false;
159
+ ids.add(id);
160
+ return true;
161
+ };
162
+ const unnamed = new Set();
163
+ const keys = [];
164
+ let count = 0;
165
+ let pending = [];
166
+ let notElements = 0;
167
+ const keep = async (key) => {
168
+ count++;
169
+ // Handed on in chunks, the keys are the host's to hold: only a sample is kept here.
170
+ if (!onKeys || keys.length < exports.SELECTION_SAMPLE)
171
+ keys.push(key);
172
+ if (!onKeys)
173
+ return;
174
+ pending.push(key);
175
+ if (onKeys && pending.length >= exports.SELECTION_CHUNK) {
176
+ const chunk = pending;
177
+ pending = [];
178
+ await onKeys(chunk);
179
+ }
180
+ };
181
+ let read = 0;
182
+ for await (const row of result.rows) {
183
+ if (signal && ++read % 1_000 === 0 && signal.aborted)
184
+ return { error: "The selection was superseded." };
185
+ const id = toId(row[idAt]);
186
+ if (!id) {
187
+ notElements++;
188
+ continue;
189
+ }
190
+ const name = classAt >= 0 ? className(row[classAt]) : undefined;
191
+ if (name === undefined) {
192
+ unnamed.add(id);
193
+ continue;
194
+ }
195
+ if (!isNew(name, id))
196
+ continue;
197
+ if (await check.isElementClass(name))
198
+ await keep({ className: name, id });
199
+ else
200
+ notElements++;
201
+ }
202
+ if (unnamed.size > 0) {
203
+ const classes = await elementClasses(runQuery, [...unnamed]);
204
+ for (const id of unnamed) {
205
+ const name = classes.get(id);
206
+ if (name && isNew(name, id)) {
207
+ await keep({ className: name, id });
208
+ }
209
+ else if (!name) {
210
+ notElements++;
211
+ }
212
+ }
213
+ }
214
+ if (onKeys && pending.length > 0)
215
+ await onKeys(pending);
216
+ return { keys, count, notElements };
217
+ }
218
+ catch (err) {
219
+ return { error: err instanceof Error ? err.message : String(err) };
220
+ }
221
+ }
222
+ //# sourceMappingURL=selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/selection.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAiCH,oBAQC;AAqBD,wCAcC;AAMD,oCAKC;AA6CD,gCAEC;AAMD,sCAGC;AAgBD,sCA8EC;AAnND;;;GAGG;AACU,QAAA,WAAW,GAAG,KAAK,CAAC;AAEjC,8GAA8G;AAC9G,SAAgB,IAAI,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QACxD,OAAO,SAAS,CAAC;IACnB,MAAM,IAAI,GAAG,MAAM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