@things-factory/ai-assistant 10.1.221 → 10.1.223

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.
@@ -30,6 +30,12 @@ export interface ReadColumn {
30
30
  * currencies are never added into one number.
31
31
  */
32
32
  currency?: string;
33
+ /**
34
+ * The i18n prefix that names this column's codes - `<words><code>` (`announcement.category.` reads `HR` as
35
+ * `announcement.category.HR`). The rows keep the code, so a filter or a card's match means the same in every
36
+ * language; the model is given the words (`legendOf`) and a table or chart shows them (`wordOf`).
37
+ */
38
+ words?: string;
33
39
  }
34
40
  export interface ReadScreen {
35
41
  /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */
@@ -166,13 +172,29 @@ export declare function readCriteria(target: ReadTarget, args: any): {
166
172
  };
167
173
  export declare function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[];
168
174
  export declare const valueAt: (row: any, path: string) => any;
169
- /** One row as the columns say - a number column as a number, a missing value as null. */
170
- export declare function rowOf(target: Pick<ReadTarget, 'columns'>, item: any): Record<string, string | number | null>;
175
+ /**
176
+ * A date column's moment as people read it - `YYYY-MM-DD HH:mm` in the domain's time zone. A day (`YYYY-MM-DD`) or
177
+ * month stays as it is; anything that is not a moment is left alone. Still ordered as text, so a card's comparison
178
+ * with a day keeps working.
179
+ */
180
+ export declare function localDateTime(value: string, timeZone?: string): string;
181
+ /** How the reader's words are asked - `(key, fallback)`, the fallback when the key has no word. */
182
+ export type SayWord = (key: string | undefined, fallback: string) => string;
183
+ /** The word a coded value is read as, in the reader's language - the value itself when its column has no words. */
184
+ export declare function wordOf(column: Pick<ReadColumn, 'words'> | undefined, value: unknown, say: SayWord): unknown;
185
+ /** The words of the coded values the rows hold, column by column - what the model reads the codes by. */
186
+ export declare function legendOf(columns: readonly Pick<ReadColumn, 'name' | 'words'>[], rows: Record<string, any>[], say: SayWord): Record<string, Record<string, string>>;
187
+ /** What shapes a row besides its columns - the domain's time zone, for a moment. */
188
+ export type RowOptions = {
189
+ timeZone?: string;
190
+ };
191
+ /** One row as the columns say - a number column as a number, a moment in the domain's time zone, a missing value as null. */
192
+ export declare function rowOf(target: Pick<ReadTarget, 'columns'>, item: any, options?: RowOptions): Record<string, string | number | null>;
171
193
  /**
172
194
  * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the
173
195
  * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.
174
196
  */
175
- export declare function readRows(target: ReadTarget, filters: ReadFilter[], run: GraphqlRunner, search?: string): Promise<{
197
+ export declare function readRows(target: ReadTarget, filters: ReadFilter[], run: GraphqlRunner, search?: string, options?: RowOptions): Promise<{
176
198
  rows: Record<string, any>[];
177
199
  total: number;
178
200
  complete: boolean;
@@ -10,6 +10,9 @@ exports.declareDetailRead = declareDetailRead;
10
10
  exports.detailReadOf = detailReadOf;
11
11
  exports.readCriteria = readCriteria;
12
12
  exports.filtersOf = filtersOf;
13
+ exports.localDateTime = localDateTime;
14
+ exports.wordOf = wordOf;
15
+ exports.legendOf = legendOf;
13
16
  exports.rowOf = rowOf;
14
17
  exports.readRows = readRows;
15
18
  exports.sumsOf = sumsOf;
@@ -198,8 +201,50 @@ function filtersOf(target, criteria) {
198
201
  }
199
202
  const valueAt = (row, path) => path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : at[part]), row);
200
203
  exports.valueAt = valueAt;
201
- /** One row as the columns say - a number column as a number, a missing value as null. */
202
- function rowOf(target, item) {
204
+ /**
205
+ * A date column's moment as people read it - `YYYY-MM-DD HH:mm` in the domain's time zone. A day (`YYYY-MM-DD`) or
206
+ * month stays as it is; anything that is not a moment is left alone. Still ordered as text, so a card's comparison
207
+ * with a day keeps working.
208
+ */
209
+ function localDateTime(value, timeZone) {
210
+ if (!/^\d{4}-\d{2}-\d{2}T/.test(value))
211
+ return value;
212
+ const moment = new Date(value);
213
+ if (Number.isNaN(moment.getTime()))
214
+ return value;
215
+ try {
216
+ const parts = Object.fromEntries(new Intl.DateTimeFormat('en-CA', { timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })
217
+ .formatToParts(moment)
218
+ .map(part => [part.type, part.value]));
219
+ return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
220
+ }
221
+ catch {
222
+ return value;
223
+ }
224
+ }
225
+ /** The word a coded value is read as, in the reader's language - the value itself when its column has no words. */
226
+ function wordOf(column, value, say) {
227
+ if (!column?.words || value === null || value === undefined || value === '')
228
+ return value;
229
+ return say(`${column.words}${value}`, String(value));
230
+ }
231
+ /** The words of the coded values the rows hold, column by column - what the model reads the codes by. */
232
+ function legendOf(columns, rows, say) {
233
+ const legend = {};
234
+ for (const column of columns) {
235
+ if (!column.words)
236
+ continue;
237
+ for (const row of rows) {
238
+ const code = row[column.name];
239
+ if (code === null || code === undefined || code === '')
240
+ continue;
241
+ (legend[column.name] ??= {})[String(code)] = String(wordOf(column, code, say));
242
+ }
243
+ }
244
+ return legend;
245
+ }
246
+ /** One row as the columns say - a number column as a number, a moment in the domain's time zone, a missing value as null. */
247
+ function rowOf(target, item, options = {}) {
203
248
  return Object.fromEntries([
204
249
  /* The id names the record to the model - for one record's detail, a change, or its screen. */
205
250
  ...(item?.id ? [['id', String(item.id)]] : []),
@@ -211,7 +256,7 @@ function rowOf(target, item) {
211
256
  const number = Number(raw);
212
257
  return [column.name, Number.isFinite(number) ? number : null];
213
258
  }
214
- return [column.name, String(raw)];
259
+ return [column.name, column.type === 'date' ? localDateTime(String(raw), options.timeZone) : String(raw)];
215
260
  })
216
261
  ]);
217
262
  }
@@ -219,7 +264,7 @@ function rowOf(target, item) {
219
264
  * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the
220
265
  * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.
221
266
  */
222
- async function readRows(target, filters, run, search) {
267
+ async function readRows(target, filters, run, search, options = {}) {
223
268
  const rows = [];
224
269
  let total = 0;
225
270
  for (let page = 1; rows.length < exports.MAX_READ_ROWS; page++) {
@@ -234,7 +279,7 @@ async function readRows(target, filters, run, search) {
234
279
  const read = target.rowsOf(answer.data);
235
280
  total = Number(read?.total) || 0;
236
281
  const items = read?.rows ?? [];
237
- rows.push(...items.slice(0, exports.MAX_READ_ROWS - rows.length).map(item => rowOf(target, item)));
282
+ rows.push(...items.slice(0, exports.MAX_READ_ROWS - rows.length).map(item => rowOf(target, item, options)));
238
283
  if (items.length < exports.READ_PAGE || rows.length >= total)
239
284
  break;
240
285
  }
@@ -1 +1 @@
1
- {"version":3,"file":"read-target.js","sourceRoot":"","sources":["../../../server/service/data-read/read-target.ts"],"names":[],"mappings":";;;AAmIA,8CAgBC;AAED,oCAEC;AAGD,wCAEC;AAGD,wCAEC;AAED,4CAGC;AAuED,8CAuBC;AAED,oCAEC;AAMD,oCA0BC;AAED,8BAOC;AAKD,sBAcC;AAMD,4BAkBC;AAiBD,wBAeC;AAGD,oCAIC;AAGD,4BAsBC;AAGD,sCAmBC;AAlbD;;;;;;;;;;GAUG;AACH,mEAA2G;AAC3G,gEAA8D;AAE9D,qCAA+B;AAmF/B,wGAAwG;AAC3F,QAAA,aAAa,GAAG,IAAI,CAAA;AACjC,0DAA0D;AAC7C,QAAA,cAAc,GAAG,EAAE,CAAA;AAChC,gCAAgC;AACnB,QAAA,SAAS,GAAG,GAAG,CAAA;AAE5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE9C,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE,CAC/B,GAAG;KACA,KAAK,CAAC,eAAe,CAAC;KACtB,MAAM,CAAC,OAAO,CAAC;KACf,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAClD,IAAI,CAAC,EAAE,CAAC,CAAA;AAEN,MAAM,aAAa,G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EAAE,CAAA;IACrB,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;QACvD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["/*\n * AI 조회 - an application's list, read through its own query as the person (operato-application/design/ai/read-targets.md).\n *\n * The application declares what it lets the assistant read: its list query, the conditions the model may set and\n * how each becomes one of the query's filters, the columns to show, and the screen that lists the same records.\n * The framework reads the rows through that query with the person's request state - the same @privilege and\n * domain as the screen - counts and sums them itself, and puts a long result on the AI 작업판 as the query returned\n * it. The model is told the count, the sums and a few rows; it never copies a table.\n *\n * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.\n */\nimport { readFieldValue, recordIdOfKey, rootFieldOf, type EntryField } from '../data-entry/entry-target.js'\nimport { encodeListQuery } from '@operato/utils/list-query.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { parse } from 'graphql'\n\nexport interface ReadFilter {\n name: string\n operator: string\n value: unknown\n}\n\n/** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */\nexport interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {\n filter: (value: any) => ReadFilter | ReadFilter[]\n /** A string condition holding a month as YYYY-MM - a value of another shape is refused (`not-a-month`). */\n format?: 'month'\n /**\n * The condition takes several values at once - its filter is given the list. Asked for the expenditure requests not\n * approved, rejected or withdrawn, the model read the list once per status and stopped (2026-10-25).\n */\n many?: boolean\n}\n\nexport interface ReadColumn {\n /** The key in the workspace table. */\n name: string\n /** Where the value is in a row - a dotted path into the query's item (`account.name`). Defaults to `name`. */\n path?: string\n type: 'string' | 'number' | 'date'\n labelKey?: string\n /** A number column the server sums. */\n total?: boolean\n /**\n * The column that holds this amount's currency (ISO 4217, `KRW`). Its sums are kept per currency - amounts of two\n * currencies are never added into one number.\n */\n currency?: string\n}\n\nexport interface ReadScreen {\n /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */\n queryState?: boolean\n /** The application's route of the list screen (`cash-transaction-list`). */\n route: string\n /** The conditions the screen takes, as its address's query arguments. A condition left out is said on the card. */\n params: (criteria: Record<string, any>) => Record<string, string | number | undefined>\n /** The conditions `params` carries - the card names the others as not applied on the screen. */\n takes: string[]\n labelKey?: string\n}\n\nexport interface ReadTarget {\n /** `<app>.<record>` - the tools are named after it. */\n key: string\n /** i18n key naming the records (「은행 입출금」). */\n labelKey?: string\n /** What the records are, for the model. */\n description: string\n /**\n * The list query - takes `$filters: [Filter!]`, `$pagination: Pagination` and `$sortings: [Sorting!]`, and\n * `$search: String` when `search` is declared.\n */\n query: string\n /**\n * The list takes ListParam's free-text term, matched by the resolver across its own searchable fields - the\n * condition `text`. Say what it finds in, for the model.\n */\n search?: { description: string }\n criteria: ReadCriterion[]\n /**\n * Filters every read of this list applies - the records it is of (a book's confirmed lines, not its forecasts). Not\n * a condition: the model neither sees nor sets them, so a read can narrow the list but never widen it.\n */\n fixedFilters?: ReadFilter[]\n columns: ReadColumn[]\n rowsOf: (data: any) => { rows: any[]; total: number }\n /** Orders the rows; the query's own order when left out. */\n sortings?: { name: string; desc?: boolean }[]\n screen?: ReadScreen\n /**\n * The rows are the person's own, whoever reads them (내 지출결의) - the query answers for the one asking. A dashboard\n * card of it shows each viewer their own rows and takes no filter on a person (ADR-0160).\n */\n mine?: boolean\n}\n\n/** At most this many rows are read - the AI 작업판 table's own limit (workspace-blocks MAX_TABLE_ROWS). */\nexport const MAX_READ_ROWS = 1000\n/** Rows the model is shown; the rest stay on the card. */\nexport const ROWS_FOR_MODEL = 20\n/** A page of the list query. */\nexport const READ_PAGE = 200\n\nconst registry = new Map<string, ReadTarget>()\n\nconst pascalOf = (key: string) =>\n key\n .split(/[^a-zA-Z0-9]+/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n\nexport const queryToolName = (key: string) => `query${pascalOf(key)}`\nexport const screenToolName = (key: string) => `open${pascalOf(key)}Screen`\nexport const readCategoryName = (key: string) => `data-read:${key}`\n\n/** The columns of a list - shown, each named once, a currency only on a summed number and taken from a string column. */\nfunction checkColumns(of: string, columns: ReadColumn[]): void {\n if (!columns.length) throw new Error(`read target '${of}' shows no column`)\n const names = new Set<string>()\n for (const column of columns) {\n if (names.has(column.name)) throw new Error(`read target '${of}' names the column '${column.name}' twice`)\n names.add(column.name)\n }\n for (const column of columns.filter(one => one.currency)) {\n if (!column.total || column.type !== 'number') throw new Error(`column '${column.name}' of '${of}' names a currency but is not a summed number`)\n if (columns.find(one => one.name === column.currency)?.type !== 'string') throw new Error(`column '${column.name}' of '${of}' takes its currency from '${column.currency}', which is no string column`)\n }\n}\n\nexport function declareReadTarget(target: ReadTarget): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`read target key '${target.key}' is not <app>.<record>`)\n if (registry.has(target.key) || details.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n checkColumns(target.key, target.columns)\n const names = new Set<string>(['id'])\n for (const criterion of target.criteria) {\n if (criterion.name === 'id') throw new Error(`read target '${target.key}' declares 'id' - every target takes it`)\n if (criterion.name === 'text' && target.search) throw new Error(`read target '${target.key}' declares 'text' and search - search is the text condition`)\n if (names.has(criterion.name)) throw new Error(`read target '${target.key}' names the condition '${criterion.name}' twice`)\n names.add(criterion.name)\n if (criterion.type === 'enum' && !criterion.values?.length) throw new Error(`condition '${criterion.name}' of '${target.key}' lists no values`)\n }\n if (target.search) names.add('text')\n for (const taken of target.screen?.takes ?? []) if (!names.has(taken)) throw new Error(`the screen of '${target.key}' takes '${taken}', which is no condition`)\n registry.set(target.key, target)\n}\n\nexport function readTargetOf(key: string | undefined): ReadTarget | undefined {\n return key ? registry.get(key) : undefined\n}\n\n/** Every list read target declared - what else reads the declarations (a dashboard card, ADR-0160) lists them by key. */\nexport function readTargetKeys(): string[] {\n return [...registry.keys()]\n}\n\n/** Every detail read declared. */\nexport function detailReadKeys(): string[] {\n return [...details.keys()]\n}\n\nexport function clearReadTargets(): void {\n registry.clear()\n details.clear()\n}\n\n/* ── One answer of a query ──────────────────────────────────────────────────────────────────────────────────── */\n\n/** An argument of a detail read - one variable of its query, read with the entry fields' rules. */\nexport interface DetailArg {\n name: string\n type: 'string' | 'integer' | 'number' | 'boolean' | 'date' | 'enum'\n values?: string[]\n description?: string\n required?: boolean\n /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */\n axis?: string | readonly string[]\n /** A string argument holding a month as YYYY-MM. */\n format?: 'month'\n}\n\n/**\n * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md\n * §9). The application declares the query with the fields its screen reads; the framework runs it as the person, with\n * the arguments the model set, and hands the answer over as the query returned it. Nothing is summed or cut here: the\n * selection is the projection, and an answer too long to hand over is refused, never cut.\n */\nexport interface DetailRead {\n /** `<app>.<thing>` - the tool is named after it. */\n key: string\n labelKey?: string\n /** What it answers, for the model. */\n description: string\n /** One query with one root field. Its variables are the arguments - each declared in `args`. */\n query: string\n args?: DetailArg[]\n /**\n * The records the answer is about, whose screens put it in front (EntryTarget.axes) - the management check answers\n * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).\n */\n axes?: string[]\n /**\n * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read\n * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.\n */\n lists?: DetailList[]\n /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */\n mine?: boolean\n}\n\n/** A list inside a detail read's answer. */\nexport interface DetailList {\n /** A name stable within the read (`by-contract`) - what a card keeps. */\n key: string\n /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */\n at: string\n labelKey?: string\n /** What the rows are, for the model. */\n description?: string\n columns: ReadColumn[]\n}\n\n/** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */\nexport const MAX_DETAIL_CHARS = 60_000\n\nconst details = new Map<string, DetailRead>()\n\nexport const detailToolName = (key: string) => `read${pascalOf(key)}`\n\n/** The variables a query declares, and whether each is required (`!`). */\nfunction variablesOf(document: string): { name: string; required: boolean }[] {\n const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')\n return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))\n}\n\nexport function declareDetailRead(target: DetailRead): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)\n if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n const args = target.args ?? []\n for (const variable of variablesOf(target.query)) {\n const arg = args.find(one => one.name === variable.name)\n if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)\n if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)\n }\n for (const arg of args) {\n if (!variablesOf(target.query).some(one => one.name === arg.name)) throw new Error(`detail read '${target.key}' declares '${arg.name}', which its query does not take`)\n if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)\n }\n const lists = new Set<string>()\n for (const list of target.lists ?? []) {\n if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)\n if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)\n lists.add(list.key)\n if (!/^([A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*)?$/.test(list.at)) throw new Error(`list '${list.key}' of '${target.key}' is at '${list.at}', which is no dotted path`)\n checkColumns(`${target.key}/${list.key}`, list.columns)\n }\n details.set(target.key, target)\n}\n\nexport function detailReadOf(key: string | undefined): DetailRead | undefined {\n return key ? details.get(key) : undefined\n}\n\n/** A month as a `month` condition holds it. */\nconst MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/\n\n/** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */\nexport function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {\n const criteria: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n /* One record by its id - every target takes it (the id a list answer or a find tool gave, or the key `<axis>:<id>` an open record is shown by, the axis being the key's last part). */\n if (typeof args?.id === 'string' && args.id.trim()) criteria.id = recordIdOfKey(target.key.split('.').pop()!, args.id) ?? args.id.trim()\n if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()\n for (const criterion of target.criteria) {\n const value = args?.[criterion.name]\n if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length)) continue\n if (criterion.many && Array.isArray(value)) {\n const each = value.map(one => readFieldValue(criterion as EntryField, one))\n const wrong = each.find(one => one.read === undefined)\n if (wrong) refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' })\n else criteria[criterion.name] = [...new Set(each.map(one => one.read))]\n continue\n }\n if (Array.isArray(value)) {\n refused.push({ name: criterion.name, code: 'one-value' })\n continue\n }\n const { read, code } = readFieldValue(criterion as EntryField, value)\n if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })\n else if (criterion.format === 'month' && !MONTH.test(String(read))) refused.push({ name: criterion.name, code: 'not-a-month' })\n else criteria[criterion.name] = read\n }\n return { criteria, refused }\n}\n\nexport function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {\n return [\n ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),\n ...target.criteria.flatMap(criterion =>\n criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []\n )\n ]\n}\n\nexport const valueAt = (row: any, path: string) => path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : at[part]), row)\n\n/** One row as the columns say - a number column as a number, a missing value as null. */\nexport function rowOf(target: Pick<ReadTarget, 'columns'>, item: any): Record<string, string | number | null> {\n return Object.fromEntries([\n /* The id names the record to the model - for one record's detail, a change, or its screen. */\n ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),\n ...target.columns.map(column => {\n const raw = valueAt(item, column.path ?? column.name)\n if (raw === undefined || raw === null || raw === '') return [column.name, null]\n if (column.type === 'number') {\n const number = Number(raw)\n return [column.name, Number.isFinite(number) ? number : null]\n }\n return [column.name, String(raw)]\n })\n ])\n}\n\n/**\n * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the\n * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.\n */\nexport async function readRows(target: ReadTarget, filters: ReadFilter[], run: GraphqlRunner, search?: string): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {\n const rows: Record<string, any>[] = []\n let total = 0\n for (let page = 1; rows.length < MAX_READ_ROWS; page++) {\n const answer = await run(target.query, {\n filters: [...filters, ...(target.fixedFilters ?? [])],\n ...(search ? { search } : {}),\n pagination: { page, limit: READ_PAGE },\n ...(target.sortings ? { sortings: target.sortings } : {})\n })\n if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))\n const read = target.rowsOf(answer.data)\n total = Number(read?.total) || 0\n const items = read?.rows ?? []\n rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item)))\n if (items.length < READ_PAGE || rows.length >= total) break\n }\n return { rows, total, complete: rows.length >= total }\n}\n\n/** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */\nexport type ReadSum = number | Record<string, number>\n\nexport interface ReadGroup {\n key: string\n count: number\n sums: Record<string, ReadSum>\n}\n\n/** The currency a row without one is summed under - said as it is, never taken for the domain's own. */\nexport const UNKNOWN_CURRENCY = 'unknown'\n\nconst sumOf = (rows: Record<string, any>[], name: string) => Math.round(rows.reduce((sum, row) => sum + (typeof row[name] === 'number' ? row[name] : 0), 0) * 100) / 100\n\n/** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */\nexport function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {\n const sums: Record<string, ReadSum> = {}\n for (const column of target.columns.filter(one => one.total && one.type === 'number')) {\n if (!column.currency) {\n sums[column.name] = sumOf(rows, column.name)\n continue\n }\n const byCurrency = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY\n byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])\n }\n sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))\n }\n return sums\n}\n\n/** The currencies a set of sums holds for one column - none for a column summed as one number. */\nexport function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {\n const codes = new Set<string>()\n for (const one of sums) if (one[column] && typeof one[column] === 'object') for (const code of Object.keys(one[column] as object)) codes.add(code)\n return [...codes].sort()\n}\n\n/** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */\nexport function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {\n const column = target.columns.find(one => one.name === by)\n if (!column) return undefined\n const groups = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const value = row[by]\n const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)\n groups.set(key, [...(groups.get(key) ?? []), row])\n }\n const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))\n if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))\n /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */\n const first = target.columns.find(one => one.total)?.name\n const codes = first ? currenciesOf(list.map(group => group.sums), first) : []\n const size = (group: ReadGroup) => {\n const sum = first ? group.sums[first] : undefined\n return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined\n }\n return list.sort((a, b) => {\n const [x, y] = [size(a), size(b)]\n return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count\n })\n}\n\n/** The address of the target's list screen with the conditions it takes, and the conditions it does not. */\nexport function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {\n const screen = target.screen\n if (!screen) return undefined\n const params = new URLSearchParams()\n for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))\n const given = Object.keys(criteria)\n const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))\n const query = screen.queryState\n ? encodeListQuery({\n filters: filtersOf(target, applicable),\n search: typeof applicable.text === 'string' ? applicable.text : undefined,\n sorters: target.sortings\n })\n : params.toString()\n return {\n href: query ? `${screen.route}?${query}` : screen.route,\n applied: given.filter(name => screen.takes.includes(name)),\n notApplied: given.filter(name => !screen.takes.includes(name))\n }\n}\n"]}
1
+ {"version":3,"file":"read-target.js","sourceRoot":"","sources":["../../../server/service/data-read/read-target.ts"],"names":[],"mappings":";;;AAyIA,8CAgBC;AAED,oCAEC;AAGD,wCAEC;AAGD,wCAEC;AAED,4CAGC;AAuED,8CAuBC;AAED,oCAEC;AAMD,oCA0BC;AAED,8BAOC;AASD,sCAcC;AAMD,wBAGC;AAGD,4BAWC;AAMD,sBAcC;AAMD,4BAwBC;AAiBD,wBAeC;AAGD,oCAIC;AAGD,4BAsBC;AAGD,sCAmBC;AA7eD;;;;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CAAC,MAAM,EAAE,UAAU,CAAC;YACtC,MAAM,EAAE,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACzE,OAAO,EAAE,MAAM,CAAC,QAAQ;SACzB,CAAC;QACJ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;IACrB,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;QACvD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["/*\n * AI 조회 - an application's list, read through its own query as the person (operato-application/design/ai/read-targets.md).\n *\n * The application declares what it lets the assistant read: its list query, the conditions the model may set and\n * how each becomes one of the query's filters, the columns to show, and the screen that lists the same records.\n * The framework reads the rows through that query with the person's request state - the same @privilege and\n * domain as the screen - counts and sums them itself, and puts a long result on the AI 작업판 as the query returned\n * it. The model is told the count, the sums and a few rows; it never copies a table.\n *\n * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.\n */\nimport { readFieldValue, recordIdOfKey, rootFieldOf, type EntryField } from '../data-entry/entry-target.js'\nimport { encodeListQuery } from '@operato/utils/list-query.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { parse } from 'graphql'\n\nexport interface ReadFilter {\n name: string\n operator: string\n value: unknown\n}\n\n/** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */\nexport interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {\n filter: (value: any) => ReadFilter | ReadFilter[]\n /** A string condition holding a month as YYYY-MM - a value of another shape is refused (`not-a-month`). */\n format?: 'month'\n /**\n * The condition takes several values at once - its filter is given the list. Asked for the expenditure requests not\n * approved, rejected or withdrawn, the model read the list once per status and stopped (2026-10-25).\n */\n many?: boolean\n}\n\nexport interface ReadColumn {\n /** The key in the workspace table. */\n name: string\n /** Where the value is in a row - a dotted path into the query's item (`account.name`). Defaults to `name`. */\n path?: string\n type: 'string' | 'number' | 'date'\n labelKey?: string\n /** A number column the server sums. */\n total?: boolean\n /**\n * The column that holds this amount's currency (ISO 4217, `KRW`). Its sums are kept per currency - amounts of two\n * currencies are never added into one number.\n */\n currency?: string\n /**\n * The i18n prefix that names this column's codes - `<words><code>` (`announcement.category.` reads `HR` as\n * `announcement.category.HR`). The rows keep the code, so a filter or a card's match means the same in every\n * language; the model is given the words (`legendOf`) and a table or chart shows them (`wordOf`).\n */\n words?: string\n}\n\nexport interface ReadScreen {\n /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */\n queryState?: boolean\n /** The application's route of the list screen (`cash-transaction-list`). */\n route: string\n /** The conditions the screen takes, as its address's query arguments. A condition left out is said on the card. */\n params: (criteria: Record<string, any>) => Record<string, string | number | undefined>\n /** The conditions `params` carries - the card names the others as not applied on the screen. */\n takes: string[]\n labelKey?: string\n}\n\nexport interface ReadTarget {\n /** `<app>.<record>` - the tools are named after it. */\n key: string\n /** i18n key naming the records (「은행 입출금」). */\n labelKey?: string\n /** What the records are, for the model. */\n description: string\n /**\n * The list query - takes `$filters: [Filter!]`, `$pagination: Pagination` and `$sortings: [Sorting!]`, and\n * `$search: String` when `search` is declared.\n */\n query: string\n /**\n * The list takes ListParam's free-text term, matched by the resolver across its own searchable fields - the\n * condition `text`. Say what it finds in, for the model.\n */\n search?: { description: string }\n criteria: ReadCriterion[]\n /**\n * Filters every read of this list applies - the records it is of (a book's confirmed lines, not its forecasts). Not\n * a condition: the model neither sees nor sets them, so a read can narrow the list but never widen it.\n */\n fixedFilters?: ReadFilter[]\n columns: ReadColumn[]\n rowsOf: (data: any) => { rows: any[]; total: number }\n /** Orders the rows; the query's own order when left out. */\n sortings?: { name: string; desc?: boolean }[]\n screen?: ReadScreen\n /**\n * The rows are the person's own, whoever reads them (내 지출결의) - the query answers for the one asking. A dashboard\n * card of it shows each viewer their own rows and takes no filter on a person (ADR-0160).\n */\n mine?: boolean\n}\n\n/** At most this many rows are read - the AI 작업판 table's own limit (workspace-blocks MAX_TABLE_ROWS). */\nexport const MAX_READ_ROWS = 1000\n/** Rows the model is shown; the rest stay on the card. */\nexport const ROWS_FOR_MODEL = 20\n/** A page of the list query. */\nexport const READ_PAGE = 200\n\nconst registry = new Map<string, ReadTarget>()\n\nconst pascalOf = (key: string) =>\n key\n .split(/[^a-zA-Z0-9]+/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n\nexport const queryToolName = (key: string) => `query${pascalOf(key)}`\nexport const screenToolName = (key: string) => `open${pascalOf(key)}Screen`\nexport const readCategoryName = (key: string) => `data-read:${key}`\n\n/** The columns of a list - shown, each named once, a currency only on a summed number and taken from a string column. */\nfunction checkColumns(of: string, columns: ReadColumn[]): void {\n if (!columns.length) throw new Error(`read target '${of}' shows no column`)\n const names = new Set<string>()\n for (const column of columns) {\n if (names.has(column.name)) throw new Error(`read target '${of}' names the column '${column.name}' twice`)\n names.add(column.name)\n }\n for (const column of columns.filter(one => one.currency)) {\n if (!column.total || column.type !== 'number') throw new Error(`column '${column.name}' of '${of}' names a currency but is not a summed number`)\n if (columns.find(one => one.name === column.currency)?.type !== 'string') throw new Error(`column '${column.name}' of '${of}' takes its currency from '${column.currency}', which is no string column`)\n }\n}\n\nexport function declareReadTarget(target: ReadTarget): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`read target key '${target.key}' is not <app>.<record>`)\n if (registry.has(target.key) || details.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n checkColumns(target.key, target.columns)\n const names = new Set<string>(['id'])\n for (const criterion of target.criteria) {\n if (criterion.name === 'id') throw new Error(`read target '${target.key}' declares 'id' - every target takes it`)\n if (criterion.name === 'text' && target.search) throw new Error(`read target '${target.key}' declares 'text' and search - search is the text condition`)\n if (names.has(criterion.name)) throw new Error(`read target '${target.key}' names the condition '${criterion.name}' twice`)\n names.add(criterion.name)\n if (criterion.type === 'enum' && !criterion.values?.length) throw new Error(`condition '${criterion.name}' of '${target.key}' lists no values`)\n }\n if (target.search) names.add('text')\n for (const taken of target.screen?.takes ?? []) if (!names.has(taken)) throw new Error(`the screen of '${target.key}' takes '${taken}', which is no condition`)\n registry.set(target.key, target)\n}\n\nexport function readTargetOf(key: string | undefined): ReadTarget | undefined {\n return key ? registry.get(key) : undefined\n}\n\n/** Every list read target declared - what else reads the declarations (a dashboard card, ADR-0160) lists them by key. */\nexport function readTargetKeys(): string[] {\n return [...registry.keys()]\n}\n\n/** Every detail read declared. */\nexport function detailReadKeys(): string[] {\n return [...details.keys()]\n}\n\nexport function clearReadTargets(): void {\n registry.clear()\n details.clear()\n}\n\n/* ── One answer of a query ──────────────────────────────────────────────────────────────────────────────────── */\n\n/** An argument of a detail read - one variable of its query, read with the entry fields' rules. */\nexport interface DetailArg {\n name: string\n type: 'string' | 'integer' | 'number' | 'boolean' | 'date' | 'enum'\n values?: string[]\n description?: string\n required?: boolean\n /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */\n axis?: string | readonly string[]\n /** A string argument holding a month as YYYY-MM. */\n format?: 'month'\n}\n\n/**\n * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md\n * §9). The application declares the query with the fields its screen reads; the framework runs it as the person, with\n * the arguments the model set, and hands the answer over as the query returned it. Nothing is summed or cut here: the\n * selection is the projection, and an answer too long to hand over is refused, never cut.\n */\nexport interface DetailRead {\n /** `<app>.<thing>` - the tool is named after it. */\n key: string\n labelKey?: string\n /** What it answers, for the model. */\n description: string\n /** One query with one root field. Its variables are the arguments - each declared in `args`. */\n query: string\n args?: DetailArg[]\n /**\n * The records the answer is about, whose screens put it in front (EntryTarget.axes) - the management check answers\n * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).\n */\n axes?: string[]\n /**\n * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read\n * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.\n */\n lists?: DetailList[]\n /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */\n mine?: boolean\n}\n\n/** A list inside a detail read's answer. */\nexport interface DetailList {\n /** A name stable within the read (`by-contract`) - what a card keeps. */\n key: string\n /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */\n at: string\n labelKey?: string\n /** What the rows are, for the model. */\n description?: string\n columns: ReadColumn[]\n}\n\n/** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */\nexport const MAX_DETAIL_CHARS = 60_000\n\nconst details = new Map<string, DetailRead>()\n\nexport const detailToolName = (key: string) => `read${pascalOf(key)}`\n\n/** The variables a query declares, and whether each is required (`!`). */\nfunction variablesOf(document: string): { name: string; required: boolean }[] {\n const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')\n return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))\n}\n\nexport function declareDetailRead(target: DetailRead): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)\n if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n const args = target.args ?? []\n for (const variable of variablesOf(target.query)) {\n const arg = args.find(one => one.name === variable.name)\n if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)\n if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)\n }\n for (const arg of args) {\n if (!variablesOf(target.query).some(one => one.name === arg.name)) throw new Error(`detail read '${target.key}' declares '${arg.name}', which its query does not take`)\n if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)\n }\n const lists = new Set<string>()\n for (const list of target.lists ?? []) {\n if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)\n if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)\n lists.add(list.key)\n if (!/^([A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*)?$/.test(list.at)) throw new Error(`list '${list.key}' of '${target.key}' is at '${list.at}', which is no dotted path`)\n checkColumns(`${target.key}/${list.key}`, list.columns)\n }\n details.set(target.key, target)\n}\n\nexport function detailReadOf(key: string | undefined): DetailRead | undefined {\n return key ? details.get(key) : undefined\n}\n\n/** A month as a `month` condition holds it. */\nconst MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/\n\n/** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */\nexport function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {\n const criteria: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n /* One record by its id - every target takes it (the id a list answer or a find tool gave, or the key `<axis>:<id>` an open record is shown by, the axis being the key's last part). */\n if (typeof args?.id === 'string' && args.id.trim()) criteria.id = recordIdOfKey(target.key.split('.').pop()!, args.id) ?? args.id.trim()\n if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()\n for (const criterion of target.criteria) {\n const value = args?.[criterion.name]\n if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length)) continue\n if (criterion.many && Array.isArray(value)) {\n const each = value.map(one => readFieldValue(criterion as EntryField, one))\n const wrong = each.find(one => one.read === undefined)\n if (wrong) refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' })\n else criteria[criterion.name] = [...new Set(each.map(one => one.read))]\n continue\n }\n if (Array.isArray(value)) {\n refused.push({ name: criterion.name, code: 'one-value' })\n continue\n }\n const { read, code } = readFieldValue(criterion as EntryField, value)\n if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })\n else if (criterion.format === 'month' && !MONTH.test(String(read))) refused.push({ name: criterion.name, code: 'not-a-month' })\n else criteria[criterion.name] = read\n }\n return { criteria, refused }\n}\n\nexport function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {\n return [\n ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),\n ...target.criteria.flatMap(criterion =>\n criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []\n )\n ]\n}\n\nexport const valueAt = (row: any, path: string) => path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : at[part]), row)\n\n/**\n * A date column's moment as people read it - `YYYY-MM-DD HH:mm` in the domain's time zone. A day (`YYYY-MM-DD`) or\n * month stays as it is; anything that is not a moment is left alone. Still ordered as text, so a card's comparison\n * with a day keeps working.\n */\nexport function localDateTime(value: string, timeZone?: string): string {\n if (!/^\\d{4}-\\d{2}-\\d{2}T/.test(value)) return value\n const moment = new Date(value)\n if (Number.isNaN(moment.getTime())) return value\n try {\n const parts = Object.fromEntries(\n new Intl.DateTimeFormat('en-CA', { timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })\n .formatToParts(moment)\n .map(part => [part.type, part.value])\n )\n return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`\n } catch {\n return value\n }\n}\n\n/** How the reader's words are asked - `(key, fallback)`, the fallback when the key has no word. */\nexport type SayWord = (key: string | undefined, fallback: string) => string\n\n/** The word a coded value is read as, in the reader's language - the value itself when its column has no words. */\nexport function wordOf(column: Pick<ReadColumn, 'words'> | undefined, value: unknown, say: SayWord): unknown {\n if (!column?.words || value === null || value === undefined || value === '') return value\n return say(`${column.words}${value}`, String(value))\n}\n\n/** The words of the coded values the rows hold, column by column - what the model reads the codes by. */\nexport function legendOf(columns: readonly Pick<ReadColumn, 'name' | 'words'>[], rows: Record<string, any>[], say: SayWord): Record<string, Record<string, string>> {\n const legend: Record<string, Record<string, string>> = {}\n for (const column of columns) {\n if (!column.words) continue\n for (const row of rows) {\n const code = row[column.name]\n if (code === null || code === undefined || code === '') continue\n ;(legend[column.name] ??= {})[String(code)] = String(wordOf(column, code, say))\n }\n }\n return legend\n}\n\n/** What shapes a row besides its columns - the domain's time zone, for a moment. */\nexport type RowOptions = { timeZone?: string }\n\n/** One row as the columns say - a number column as a number, a moment in the domain's time zone, a missing value as null. */\nexport function rowOf(target: Pick<ReadTarget, 'columns'>, item: any, options: RowOptions = {}): Record<string, string | number | null> {\n return Object.fromEntries([\n /* The id names the record to the model - for one record's detail, a change, or its screen. */\n ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),\n ...target.columns.map(column => {\n const raw = valueAt(item, column.path ?? column.name)\n if (raw === undefined || raw === null || raw === '') return [column.name, null]\n if (column.type === 'number') {\n const number = Number(raw)\n return [column.name, Number.isFinite(number) ? number : null]\n }\n return [column.name, column.type === 'date' ? localDateTime(String(raw), options.timeZone) : String(raw)]\n })\n ])\n}\n\n/**\n * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the\n * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.\n */\nexport async function readRows(\n target: ReadTarget,\n filters: ReadFilter[],\n run: GraphqlRunner,\n search?: string,\n options: RowOptions = {}\n): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {\n const rows: Record<string, any>[] = []\n let total = 0\n for (let page = 1; rows.length < MAX_READ_ROWS; page++) {\n const answer = await run(target.query, {\n filters: [...filters, ...(target.fixedFilters ?? [])],\n ...(search ? { search } : {}),\n pagination: { page, limit: READ_PAGE },\n ...(target.sortings ? { sortings: target.sortings } : {})\n })\n if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))\n const read = target.rowsOf(answer.data)\n total = Number(read?.total) || 0\n const items = read?.rows ?? []\n rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item, options)))\n if (items.length < READ_PAGE || rows.length >= total) break\n }\n return { rows, total, complete: rows.length >= total }\n}\n\n/** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */\nexport type ReadSum = number | Record<string, number>\n\nexport interface ReadGroup {\n key: string\n count: number\n sums: Record<string, ReadSum>\n}\n\n/** The currency a row without one is summed under - said as it is, never taken for the domain's own. */\nexport const UNKNOWN_CURRENCY = 'unknown'\n\nconst sumOf = (rows: Record<string, any>[], name: string) => Math.round(rows.reduce((sum, row) => sum + (typeof row[name] === 'number' ? row[name] : 0), 0) * 100) / 100\n\n/** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */\nexport function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {\n const sums: Record<string, ReadSum> = {}\n for (const column of target.columns.filter(one => one.total && one.type === 'number')) {\n if (!column.currency) {\n sums[column.name] = sumOf(rows, column.name)\n continue\n }\n const byCurrency = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY\n byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])\n }\n sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))\n }\n return sums\n}\n\n/** The currencies a set of sums holds for one column - none for a column summed as one number. */\nexport function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {\n const codes = new Set<string>()\n for (const one of sums) if (one[column] && typeof one[column] === 'object') for (const code of Object.keys(one[column] as object)) codes.add(code)\n return [...codes].sort()\n}\n\n/** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */\nexport function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {\n const column = target.columns.find(one => one.name === by)\n if (!column) return undefined\n const groups = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const value = row[by]\n const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)\n groups.set(key, [...(groups.get(key) ?? []), row])\n }\n const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))\n if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))\n /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */\n const first = target.columns.find(one => one.total)?.name\n const codes = first ? currenciesOf(list.map(group => group.sums), first) : []\n const size = (group: ReadGroup) => {\n const sum = first ? group.sums[first] : undefined\n return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined\n }\n return list.sort((a, b) => {\n const [x, y] = [size(a), size(b)]\n return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count\n })\n}\n\n/** The address of the target's list screen with the conditions it takes, and the conditions it does not. */\nexport function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {\n const screen = target.screen\n if (!screen) return undefined\n const params = new URLSearchParams()\n for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))\n const given = Object.keys(criteria)\n const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))\n const query = screen.queryState\n ? encodeListQuery({\n filters: filtersOf(target, applicable),\n search: typeof applicable.text === 'string' ? applicable.text : undefined,\n sorters: target.sortings\n })\n : params.toString()\n return {\n href: query ? `${screen.route}?${query}` : screen.route,\n applied: given.filter(name => screen.takes.includes(name)),\n notApplied: given.filter(name => !screen.takes.includes(name))\n }\n}\n"]}
@@ -17,6 +17,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
17
17
  } | {
18
18
  record: any;
19
19
  message: string;
20
+ legend?: Record<string, Record<string, string>>;
21
+ legendNote?: string;
20
22
  rowsNotShown?: number;
21
23
  rows: any;
22
24
  moreGroups?: number;
@@ -34,6 +36,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
34
36
  } | {
35
37
  record: any;
36
38
  message: string;
39
+ legend?: Record<string, Record<string, string>>;
40
+ legendNote?: string;
37
41
  rowsNotShown?: number;
38
42
  rows: any;
39
43
  groupBy: any;
@@ -50,6 +54,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
50
54
  } | {
51
55
  record: any;
52
56
  message: string;
57
+ legend?: Record<string, Record<string, string>>;
58
+ legendNote?: string;
53
59
  rowsNotShown?: number;
54
60
  rows: any;
55
61
  target: string;
@@ -63,6 +69,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
63
69
  refused?: undefined;
64
70
  } | {
65
71
  message: string;
72
+ legend?: Record<string, Record<string, string>>;
73
+ legendNote?: string;
66
74
  rowsNotShown?: number;
67
75
  rows: any;
68
76
  moreGroups?: number;
@@ -79,6 +87,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
79
87
  refused?: undefined;
80
88
  } | {
81
89
  message: string;
90
+ legend?: Record<string, Record<string, string>>;
91
+ legendNote?: string;
82
92
  rowsNotShown?: number;
83
93
  rows: any;
84
94
  groupBy: any;
@@ -94,6 +104,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
94
104
  refused?: undefined;
95
105
  } | {
96
106
  message: string;
107
+ legend?: Record<string, Record<string, string>>;
108
+ legendNote?: string;
97
109
  rowsNotShown?: number;
98
110
  rows: any;
99
111
  target: string;
@@ -111,6 +123,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
111
123
  contents: Record<string, number>;
112
124
  };
113
125
  message: string;
126
+ legend?: Record<string, Record<string, string>>;
127
+ legendNote?: string;
114
128
  rowsNotShown?: number;
115
129
  rows: any;
116
130
  moreGroups?: number;
@@ -135,6 +149,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
135
149
  contents: Record<string, number>;
136
150
  };
137
151
  message: string;
152
+ legend?: Record<string, Record<string, string>>;
153
+ legendNote?: string;
138
154
  rowsNotShown?: number;
139
155
  rows: any;
140
156
  groupBy: any;
@@ -158,6 +174,8 @@ export declare function queryRecords(target: ReadTarget, args: any, context: any
158
174
  contents: Record<string, number>;
159
175
  };
160
176
  message: string;
177
+ legend?: Record<string, Record<string, string>>;
178
+ legendNote?: string;
161
179
  rowsNotShown?: number;
162
180
  rows: any;
163
181
  target: string;
@@ -50,7 +50,9 @@ async function queryRecords(target, args, context, run) {
50
50
  }
51
51
  let read;
52
52
  try {
53
- read = await (0, read_target_js_1.readRows)(target, (0, read_target_js_1.filtersOf)(target, criteria), run, typeof criteria.text === 'string' && target.search ? criteria.text : undefined);
53
+ read = await (0, read_target_js_1.readRows)(target, (0, read_target_js_1.filtersOf)(target, criteria), run, typeof criteria.text === 'string' && target.search ? criteria.text : undefined, {
54
+ timeZone: context?.state?.domain?.timezone
55
+ });
54
56
  }
55
57
  catch (error) {
56
58
  return { rejected: true, error: 'query-failed', message: `the list could not be read: ${error?.message ?? error}` };
@@ -61,6 +63,8 @@ async function queryRecords(target, args, context, run) {
61
63
  const groups = groupBy ? (0, read_target_js_1.groupsOf)(target, rows, groupBy) : undefined;
62
64
  const words = wordsOf(context);
63
65
  const label = words(target.labelKey, target.key);
66
+ /* The rows keep their codes - a condition names them; the person is told the words (ADR-0163, 2026-10-26). */
67
+ const legend = (0, read_target_js_1.legendOf)(target.columns, rows, words);
64
68
  const said = {
65
69
  target: target.key,
66
70
  criteria,
@@ -70,7 +74,8 @@ async function queryRecords(target, args, context, run) {
70
74
  sums,
71
75
  ...(groupBy ? (groups ? { groupBy, groups: groups.slice(0, 50), ...(groups.length > 50 ? { moreGroups: groups.length - 50 } : {}) } : { groupBy, groupRefused: 'no such column' }) : {}),
72
76
  rows: rows.slice(0, read_target_js_1.ROWS_FOR_MODEL),
73
- ...(rows.length > read_target_js_1.ROWS_FOR_MODEL ? { rowsNotShown: rows.length - read_target_js_1.ROWS_FOR_MODEL } : {})
77
+ ...(rows.length > read_target_js_1.ROWS_FOR_MODEL ? { rowsNotShown: rows.length - read_target_js_1.ROWS_FOR_MODEL } : {}),
78
+ ...(Object.keys(legend).length ? { legend, legendNote: 'a coded value is said by its word in legend, never by its code' } : {})
74
79
  };
75
80
  const incomplete = complete
76
81
  ? ''
@@ -83,6 +88,8 @@ async function queryRecords(target, args, context, run) {
83
88
  }
84
89
  /* The workspace is built here from the rows as read - the model never copies the table. */
85
90
  const columns = target.columns.map(column => ({ name: column.name, label: words(column.labelKey, column.name), type: column.type }));
91
+ const shownRows = rows.map(row => Object.fromEntries(Object.entries(row).map(([name, value]) => [name, (0, read_target_js_1.wordOf)(target.columns.find(one => one.name === name), value, words)])));
92
+ const groupColumn = target.columns.find(one => one.name === groupBy);
86
93
  const totalColumns = target.columns.filter(one => one.total);
87
94
  /* A sum per currency is one figure and one group column per currency it holds - 「계약금액 (USD)」. */
88
95
  const sumColumns = totalColumns.flatMap(column => {
@@ -108,11 +115,11 @@ async function queryRecords(target, args, context, run) {
108
115
  kind: 'table',
109
116
  caption: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy),
110
117
  columns: [{ name: 'key', label: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy), type: 'string' }, { name: 'count', label: words('ai-assistant.read.count', 'rows'), type: 'number' }, ...sumColumns.map(column => ({ name: column.name, label: column.label, type: 'number' }))],
111
- rows: groups.map(group => ({ key: group.key, count: group.count, ...Object.fromEntries(sumColumns.map(column => [column.name, column.of(group.sums)])) }))
118
+ rows: groups.map(group => ({ key: (0, read_target_js_1.wordOf)(groupColumn, group.key, words), count: group.count, ...Object.fromEntries(sumColumns.map(column => [column.name, column.of(group.sums)])) }))
112
119
  }
113
120
  ]
114
121
  : []),
115
- { kind: 'table', caption: label, columns, rows }
122
+ { kind: 'table', caption: label, columns, rows: shownRows }
116
123
  ]
117
124
  });
118
125
  return {