@aglyn/plugins-data 1.0.0-beta.233 → 1.0.0-beta.235

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.
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import type { RepeatRowsModel } from '@aglyn/aglyn/app-utils/expand-repeatables';
18
+ import { type DatasetFieldDefinition, type DatasetFilterValues, type DatasetModel } from './dataset-model-core';
18
19
  /**
19
20
  * Dataset models (AGL-177): the runtime promotion of the type-level
20
21
  * blueprint in `libs/shared/data/types/src/lib/dod.ts` (kept as the
@@ -31,92 +32,7 @@ import type { RepeatRowsModel } from '@aglyn/aglyn/app-utils/expand-repeatables'
31
32
  * numbers, coordinates as `{ latitude, longitude }`, `sorted` as arrays,
32
33
  * `map` as plain objects, references as target-document id strings.
33
34
  */
34
- /**
35
- * A human field entry from the quick creator: the stable id plus the
36
- * display name shown in table headers and bindings pickers (AGL-558).
37
- */
38
- export interface DatasetFieldEntry {
39
- id: string;
40
- name: string;
41
- }
42
- /** Display fallback for raw ids: "roast_preference" → "Roast preference". */
43
- export declare function humanizeDatasetFieldId(id: string): string;
44
- /** dod.ts `FT.Tag` vocabulary plus `reference` (AGL-180 builds on it). */
45
- export type DatasetFieldType = 'bool' | 'bytes' | 'timestamp' | 'float' | 'int32' | 'int64' | 'nil' | 'text' | 'coordinates' | 'map' | 'sorted' | 'reference';
46
- export declare const DATASET_FIELD_TYPES: DatasetFieldType[];
47
- /** Display names, mirroring dod.ts `lbl`. */
48
- export declare const DATASET_FIELD_TYPE_LABELS: Record<DatasetFieldType, string>;
49
- /**
50
- * Plain-JSON validation vocabulary (the dod.ts `Eval` shape, extended
51
- * with min/max and options, serialized flat instead of enum-keyed).
52
- */
53
- export interface DatasetFieldValidation {
54
- required?: boolean;
55
- /** Source of a RegExp applied to text values. */
56
- regex?: string;
57
- /** Numbers/timestamps: value bound. Text: length bound. */
58
- min?: number;
59
- max?: number;
60
- /** Enum: value must be one of these (text fields). */
61
- options?: string[];
62
- }
63
- export interface DatasetFieldDefinition {
64
- /**
65
- * Human-facing display label only. The stable reference id is the KEY in
66
- * `DatasetModel.fields` (and `order`), NOT this name — bindings resolve
67
- * `{{item.<fieldId>}}` against that key. The default id is derived from
68
- * this name once at creation but is user-overridable (AGL-578); renaming
69
- * the label afterwards never changes the id.
70
- */
71
- name: string;
72
- type: DatasetFieldType;
73
- /**
74
- * Plugin-declared custom type riding this base type (AGL-434) — see
75
- * plugin-manager/custom-fields. Unknown names degrade to the base type.
76
- */
77
- customType?: string;
78
- /**
79
- * A page-address field's source (AGL-3475): the field an EMPTY address
80
- * fills in from, once — see `fillRecordAddresses` in `record-pages`.
81
- * Meaningful only on a field of the page-address custom type.
82
- */
83
- slugFrom?: string;
84
- description?: string;
85
- required?: boolean;
86
- /** Default applied by editors when creating documents; never coerced. */
87
- default?: unknown;
88
- validation?: DatasetFieldValidation;
89
- /**
90
- * Reference fields (AGL-180): target collection + display field id.
91
- * `multiple` stores a `sorted` array of FKeys (small-cardinality
92
- * many-to-many per the dod.ts guidance); `onDelete` is the referenced-
93
- * document delete policy (default `setNull` — never cascade in v2).
94
- */
95
- reference?: {
96
- datasetId: string;
97
- displayFieldId?: string;
98
- multiple?: boolean;
99
- onDelete?: 'restrict' | 'setNull';
100
- };
101
- }
102
- export interface DatasetModel {
103
- fields: Record<string, DatasetFieldDefinition>;
104
- /** Field ids in display order. */
105
- order: string[];
106
- }
107
- /**
108
- * Migration shim (v1 → v2): datasets created before models carry flat
109
- * `fields: string[]` — derive a model where every column is an optional
110
- * text field whose id is the column name, so the editor and AGL-103
111
- * bindings keep working on unmigrated docs during rollout.
112
- */
113
- export declare function deriveModelFromFields(fields: string[]): DatasetModel;
114
- /**
115
- * Model from quick-creator entries (AGL-558): stable slug ids with the
116
- * human display names preserved — "Roast preference" → id
117
- * `roast_preference`, name "Roast preference".
118
- */
119
- export declare function modelFromFieldEntries(entries: readonly DatasetFieldEntry[]): DatasetModel;
35
+ export * from './dataset-model-core';
120
36
  /**
121
37
  * The part of a dataset's model a repeat reads (AGL-180): each reference
122
38
  * field, by the id of the dataset it points into, which is a key the rows map
@@ -124,11 +40,6 @@ export declare function modelFromFieldEntries(entries: readonly DatasetFieldEntr
124
40
  * resolves wherever its target's rows were loaded.
125
41
  */
126
42
  export declare function repeatRowsModelOf(model: DatasetModel): RepeatRowsModel;
127
- /** The dataset's model, deriving one from v1 `fields` when absent. */
128
- export declare function effectiveDatasetModel(dataset: {
129
- model?: DatasetModel;
130
- fields?: string[];
131
- }): DatasetModel;
132
43
  /**
133
44
  * Validates a document's values against a model, returning fieldId →
134
45
  * human-readable error (empty object = valid). Values are expected in
@@ -136,14 +47,6 @@ export declare function effectiveDatasetModel(dataset: {
136
47
  * when starting from user input strings.
137
48
  */
138
49
  export declare function validateDocument(model: DatasetModel, values: Record<string, unknown>): Record<string, string>;
139
- /** Storage value → grid display string (AGL-179). */
140
- export declare function formatDatasetValue(field: DatasetFieldDefinition, value: unknown): string;
141
- /**
142
- * Storage value → form-input string (AGL-179): the inverse of
143
- * `coerceDocumentValues` for populating type-appropriate inputs
144
- * (timestamps as `datetime-local` values, coordinates as "lat, lon").
145
- */
146
- export declare function datasetValueToInput(field: DatasetFieldDefinition, value: unknown): string;
147
50
  /**
148
51
  * Whether a field stores a list: `sorted`, and a `reference` that may point at
149
52
  * more than one record. Both go through {@link coerceListValue}.
@@ -258,135 +161,3 @@ export declare function datasetIntegrityUpdate<TClear>(model: DatasetModel, valu
258
161
  filterKeys: string[] | TClear;
259
162
  filterValues: DatasetFilterValues | TClear;
260
163
  };
261
- /**
262
- * A dataset record's FILTER TOKENS: every word-level question the records
263
- * table can ask of a record, flattened into one array of strings Firestore
264
- * indexes on its own. Its twin, {@link datasetFilterValues}, holds the
265
- * equalities.
266
- *
267
- * ## Why these fields, and not the values
268
- *
269
- * A record's fields live under `values`, a user-defined, unbounded map that
270
- * the index configuration exempts from indexing — auto-indexing it can exceed
271
- * Firestore's per-document index-entry limit — so `where('values.<field>', …)`
272
- * is refused. A composite index per dataset would need an admin call per
273
- * dataset, runs into the project's composite-index cap, and is deleted by the
274
- * next `firestore:indexes` deploy of a file that does not list it.
275
- *
276
- * `filterKeys` and `filterValues` need none of that. Firestore's AUTOMATIC
277
- * single-field indexes serve `where('filterKeys', 'array-contains', token)`
278
- * and `where('filterValues.<field>', '==', value)`, and every automatic index
279
- * ends in the document name — so any number of those equalities and ONE
280
- * `array-contains`, under `orderBy(documentId())`, compose by index merging,
281
- * with no composite index and no index deploy, on any dataset of any project
282
- * (AGL-3321).
283
- *
284
- * ## The token grammar
285
- *
286
- * `f:<fieldId>=<value>` a field equals a value. Enum (a text field with
287
- * `validation.options`) values are kept exactly;
288
- * plain text is lower-cased, trimmed and clipped to
289
- * {@link DATASET_FILTER_VALUE_MAX} characters;
290
- * booleans are `true`/`false`; numbers are
291
- * `String(number)`; a `sorted` list contributes one
292
- * token per member.
293
- * `f:<fieldId>^<prefix>` a word of a plain text field starts with this.
294
- * `s:<prefix>` a word of ANY text value (enums and list members
295
- * included) starts with this — the quick search.
296
- *
297
- * Timestamps, references, maps, bytes, coordinates and nil fields carry no
298
- * field tokens: a timestamp is asked in ranges, which one token cannot serve,
299
- * and the rest are not asked about by value.
300
- *
301
- * The array is sorted, de-duplicated and capped at
302
- * {@link DATASET_FILTER_KEYS_MAX}. Past the cap, the `=` tokens are kept
303
- * first, then the per-field word prefixes, then the search prefixes, so a
304
- * very long record loses search reach before it loses exact matches.
305
- */
306
- export declare const DATASET_FILTER_KEYS_MAX = 500;
307
- /** Plain text values are clipped to this many characters in an `=` token. */
308
- export declare const DATASET_FILTER_VALUE_MAX = 64;
309
- /** Word prefixes run from 1 to this many characters. */
310
- export declare const DATASET_FILTER_PREFIX_MAX = 12;
311
- /** Only the first this-many words of a value contribute prefixes. */
312
- export declare const DATASET_FILTER_WORDS_MAX = 40;
313
- /** One clause of the records table's filter: `{ field, op, value }`. */
314
- export interface DatasetFilterClause {
315
- field: string;
316
- op: string;
317
- value: string;
318
- }
319
- /**
320
- * The words of a text value: split on anything that is not a letter or a
321
- * digit, lower-cased, at most {@link DATASET_FILTER_WORDS_MAX} of them.
322
- */
323
- export declare function datasetFilterWords(text: string): string[];
324
- /**
325
- * Plain text as its stored key — its `=` token's value and its
326
- * `filterValues` entry: lower-cased, trimmed, clipped to
327
- * {@link DATASET_FILTER_VALUE_MAX} characters. What the records table asks a
328
- * typed value to equal.
329
- */
330
- export declare function datasetFilterTextKey(value: string): string;
331
- /** The tokens described in {@link DATASET_FILTER_KEYS_MAX}'s comment. */
332
- export declare function datasetFilterKeys(model: DatasetModel, values: Record<string, unknown> | undefined): string[];
333
- /** A record's `filterValues`: field id → the value an equality asks for. */
334
- export type DatasetFilterValues = Record<string, string | number | boolean>;
335
- /**
336
- * The query path of a field's `filterValues` entry, or null for a field id
337
- * no path can name — such a field is stamped no entry, and the records table
338
- * offers it no equality (its `contains`, served by `filterKeys`, stands).
339
- */
340
- export declare function datasetFilterValuePath(fieldId: string): string | null;
341
- /**
342
- * A dataset record's FILTER VALUES: `{ [fieldId]: value }`, one scalar per
343
- * field an equality can be asked of, so the records table puts every
344
- * equality on its query (AGL-3321).
345
- *
346
- * enum text (`validation.options`) the value exactly, as its `=` token;
347
- * plain text {@link datasetFilterTextKey};
348
- * bool a boolean;
349
- * int32 / int64 / float a number.
350
- *
351
- * A form or an automation stores every value as text, so `'19.50'` is the
352
- * number 19.5 and `'true'` the boolean, as in {@link datasetFilterKeys}.
353
- * Fields with no value, and timestamps, lists, references, maps, bytes,
354
- * coordinates and nil fields, carry no entry: a list is asked by member
355
- * (`f:<id>=<member>` in `filterKeys`), and the rest are not asked about by
356
- * value.
357
- *
358
- * ## What it costs
359
- *
360
- * Unlike `values`, this map is NOT exempt from indexing — that is its whole
361
- * point. Each entry is a scalar and costs two automatic index entries
362
- * (ascending, descending), so a record costs at most two per model field —
363
- * bounded by the model's field count (the `/v1` API caps a model at 100
364
- * fields), far inside Firestore's 40,000 entries per document, where
365
- * `values` was unbounded because a `map` or `sorted` value may hold anything.
366
- */
367
- export declare function datasetFilterValues(model: DatasetModel, values: Record<string, unknown> | undefined): DatasetFilterValues;
368
- /**
369
- * The `filterKeys` token a word-level clause asks for, or null when it is
370
- * not one:
371
- *
372
- * - plain text `contains` → the `^` token of the value's FIRST word, so a
373
- * `contains` is a word-prefix match, not a mid-string one, and one word
374
- * of several is asked (the records table says so);
375
- * - list `contains` (and `equals`) → the member's `=` token;
376
- * - enum, boolean, number and plain text `equals` → the `=` token of the
377
- * value. The records table asks these of `filterValues` instead, which
378
- * composes with a `contains`; the token remains what the quick search and
379
- * older readers match.
380
- * - everything else — ranges, dates, `isEmpty`, `isAnyOf`, negations — null.
381
- *
382
- * `clause.field` is the field id. The operator names are the grid's: a
383
- * select's `equals`, a number's `=`, a boolean's `is`, a list's `contains`.
384
- */
385
- export declare function datasetFilterToken(model: DatasetModel, clause: DatasetFilterClause): string | null;
386
- /**
387
- * The quick-search token for one typed word, or null for a word with no
388
- * letters or digits. A word with punctuation inside it is asked by its first
389
- * run — split the search text with {@link datasetFilterWords} to ask for
390
- * every run.
391
- */
392
- export declare function datasetSearchToken(word: string): string | null;