@hanzo/crm 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE-MIT +21 -0
  2. package/LICENSE.md +21 -0
  3. package/NOTICE +52 -0
  4. package/README.md +72 -2
  5. package/dist/CrmModule.d.ts +4 -0
  6. package/dist/CrmModule.d.ts.map +1 -0
  7. package/dist/CrmModule.js +78 -0
  8. package/dist/CrmModule.js.map +1 -0
  9. package/dist/crm/Access.d.ts +10 -0
  10. package/dist/crm/Access.d.ts.map +1 -0
  11. package/dist/crm/Access.js +35 -0
  12. package/dist/crm/Access.js.map +1 -0
  13. package/dist/crm/Actions.d.ts +38 -0
  14. package/dist/crm/Actions.d.ts.map +1 -0
  15. package/dist/crm/Actions.js +224 -0
  16. package/dist/crm/Actions.js.map +1 -0
  17. package/dist/crm/Create.d.ts +13 -0
  18. package/dist/crm/Create.d.ts.map +1 -0
  19. package/dist/crm/Create.js +64 -0
  20. package/dist/crm/Create.js.map +1 -0
  21. package/dist/crm/Import.d.ts +7 -0
  22. package/dist/crm/Import.d.ts.map +1 -0
  23. package/dist/crm/Import.js +94 -0
  24. package/dist/crm/Import.js.map +1 -0
  25. package/dist/crm/Record.d.ts +6 -0
  26. package/dist/crm/Record.d.ts.map +1 -0
  27. package/dist/crm/Record.js +254 -0
  28. package/dist/crm/Record.js.map +1 -0
  29. package/dist/crm/Records.d.ts +33 -0
  30. package/dist/crm/Records.d.ts.map +1 -0
  31. package/dist/crm/Records.js +275 -0
  32. package/dist/crm/Records.js.map +1 -0
  33. package/dist/crm/Timeline.d.ts +22 -0
  34. package/dist/crm/Timeline.d.ts.map +1 -0
  35. package/dist/crm/Timeline.js +117 -0
  36. package/dist/crm/Timeline.js.map +1 -0
  37. package/dist/crm/csv.d.ts +75 -0
  38. package/dist/crm/csv.d.ts.map +1 -0
  39. package/dist/crm/csv.js +300 -0
  40. package/dist/crm/csv.js.map +1 -0
  41. package/dist/crm/importer.d.ts +39 -0
  42. package/dist/crm/importer.d.ts.map +1 -0
  43. package/dist/crm/importer.js +147 -0
  44. package/dist/crm/importer.js.map +1 -0
  45. package/dist/crm/objects.d.ts +80 -0
  46. package/dist/crm/objects.d.ts.map +1 -0
  47. package/dist/crm/objects.js +167 -0
  48. package/dist/crm/objects.js.map +1 -0
  49. package/dist/crm/schema.d.ts +58 -0
  50. package/dist/crm/schema.d.ts.map +1 -0
  51. package/dist/crm/schema.js +175 -0
  52. package/dist/crm/schema.js.map +1 -0
  53. package/dist/crm/studio/Sequences.d.ts +4 -0
  54. package/dist/crm/studio/Sequences.d.ts.map +1 -0
  55. package/dist/crm/studio/Sequences.js +114 -0
  56. package/dist/crm/studio/Sequences.js.map +1 -0
  57. package/dist/crm/studio/logic.d.ts +32 -0
  58. package/dist/crm/studio/logic.d.ts.map +1 -0
  59. package/dist/crm/studio/logic.js +59 -0
  60. package/dist/crm/studio/logic.js.map +1 -0
  61. package/dist/crm/studio/style.d.ts +8 -0
  62. package/dist/crm/studio/style.d.ts.map +1 -0
  63. package/dist/crm/studio/style.js +21 -0
  64. package/dist/crm/studio/style.js.map +1 -0
  65. package/dist/crm/suppression.d.ts +11 -0
  66. package/dist/crm/suppression.d.ts.map +1 -0
  67. package/dist/crm/suppression.js +20 -0
  68. package/dist/crm/suppression.js.map +1 -0
  69. package/dist/index.d.ts +12 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +19 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/lib/base-data/api.d.ts +48 -0
  74. package/dist/lib/base-data/api.d.ts.map +1 -0
  75. package/dist/lib/base-data/api.js +2 -0
  76. package/dist/lib/base-data/api.js.map +1 -0
  77. package/dist/lib/base-data/client.d.ts +29 -0
  78. package/dist/lib/base-data/client.d.ts.map +1 -0
  79. package/dist/lib/base-data/client.js +76 -0
  80. package/dist/lib/base-data/client.js.map +1 -0
  81. package/dist/lib/base-data/fields.d.ts +103 -0
  82. package/dist/lib/base-data/fields.d.ts.map +1 -0
  83. package/dist/lib/base-data/fields.js +251 -0
  84. package/dist/lib/base-data/fields.js.map +1 -0
  85. package/dist/lib/base-data/html.d.ts +20 -0
  86. package/dist/lib/base-data/html.d.ts.map +1 -0
  87. package/dist/lib/base-data/html.js +49 -0
  88. package/dist/lib/base-data/html.js.map +1 -0
  89. package/dist/lib/base-data/query.d.ts +50 -0
  90. package/dist/lib/base-data/query.d.ts.map +1 -0
  91. package/dist/lib/base-data/query.js +220 -0
  92. package/dist/lib/base-data/query.js.map +1 -0
  93. package/dist/lib/crm.d.ts +374 -0
  94. package/dist/lib/crm.d.ts.map +1 -0
  95. package/dist/lib/crm.js +337 -0
  96. package/dist/lib/crm.js.map +1 -0
  97. package/dist/lib/host.d.ts +117 -0
  98. package/dist/lib/host.d.ts.map +1 -0
  99. package/dist/lib/host.js +43 -0
  100. package/dist/lib/host.js.map +1 -0
  101. package/dist/nav.d.ts +7 -0
  102. package/dist/nav.d.ts.map +1 -0
  103. package/dist/nav.js +18 -0
  104. package/dist/nav.js.map +1 -0
  105. package/package.json +58 -3
@@ -0,0 +1,251 @@
1
+ import { editorText, paragraphs } from './html.js';
2
+ /**
3
+ * Base field type → @hanzo/data field type. 1:1 cases only — `select` (single vs
4
+ * multi), `autodate` and `actor` (read-only) carry extra shape and are handled in
5
+ * `toFieldDefinition`.
6
+ */
7
+ const TYPE_MAP = {
8
+ text: 'text',
9
+ number: 'number',
10
+ bool: 'boolean',
11
+ email: 'email',
12
+ emails: 'email',
13
+ url: 'url',
14
+ links: 'links',
15
+ phones: 'phone',
16
+ fullName: 'fullName',
17
+ address: 'address',
18
+ currency: 'currency',
19
+ editor: 'richText',
20
+ date: 'date',
21
+ json: 'json',
22
+ relation: 'relation',
23
+ file: 'files',
24
+ geoPoint: 'json',
25
+ };
26
+ /** The hues @hanzo/data draws a tag in; a module's colour outside them is drawn grey. */
27
+ const HUES = new Set([
28
+ 'red', 'ruby', 'crimson', 'tomato', 'orange', 'amber', 'yellow', 'lime', 'grass', 'green', 'jade', 'mint', 'teal',
29
+ 'cyan', 'sky', 'blue', 'iris', 'violet', 'purple', 'plum', 'pink', 'bronze', 'gold', 'brown', 'gray', 'mauve',
30
+ 'olive', 'sage', 'sand', 'slate',
31
+ ]);
32
+ /** A module's own names for two hues the palette spells otherwise. */
33
+ const HUE_ALIAS = { turquoise: 'teal' };
34
+ /** Words rendered upper-case in a humanized label. */
35
+ const ACRONYMS = new Set(['id', 'url', 'uuid', 'api', 'ip']);
36
+ /** `firstName` / `first_name` → "First Name"; known acronyms upper-cased (`id` → "ID"). */
37
+ function humanize(name) {
38
+ return name
39
+ .replace(/[_-]+/g, ' ')
40
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
41
+ .trim()
42
+ .split(/\s+/)
43
+ .filter(Boolean)
44
+ .map((w) => (ACRONYMS.has(w.toLowerCase()) ? w.toUpperCase() : w.charAt(0).toUpperCase() + w.slice(1)))
45
+ .join(' ');
46
+ }
47
+ /** The legacy nested options object, when that is what a field carries. */
48
+ const legacy = (f) => f.options && !Array.isArray(f.options) ? f.options : undefined;
49
+ /** Effective `maxSelect` of a select/file/relation field (flat shape or legacy `options`). */
50
+ const maxSelectOf = (f) => f.maxSelect ?? legacy(f)?.maxSelect ?? 1;
51
+ /** A select's options: the module's (label, hue, order) where it gives them, else its bare values. */
52
+ export function optionsOf(f) {
53
+ const declared = Array.isArray(f.options) ? f.options : [];
54
+ const values = f.values ?? legacy(f)?.values ?? declared.map((o) => o.value);
55
+ const byValue = new Map(declared.map((o) => [o.value, o]));
56
+ return values.map((v) => {
57
+ const o = byValue.get(v);
58
+ const hue = o?.color ? (HUE_ALIAS[o.color] ?? (HUES.has(o.color) ? o.color : undefined)) : undefined;
59
+ return { value: v, label: o?.label || v, ...(hue ? { color: hue } : {}) };
60
+ });
61
+ }
62
+ /** Keep a field unless it is hidden, or a system field other than `id`. */
63
+ const isRenderable = (f) => typeof f?.name === 'string' && typeof f?.type === 'string' && !f.hidden && (!f.system || f.name === 'id');
64
+ /** Translate ONE Base field to a @hanzo/data `FieldDefinition`. */
65
+ function toFieldDefinition(f, opts) {
66
+ const base = { name: f.name, label: f.label || humanize(f.name) };
67
+ // The only system field that survives `isRenderable` is `id` — server-owned, so
68
+ // it renders as a value everywhere and never enters edit mode (no id input).
69
+ const ro = f.system ? { readOnly: true } : {};
70
+ if (f.type === 'select') {
71
+ return { ...base, type: maxSelectOf(f) > 1 ? 'multiSelect' : 'select', metadata: { options: optionsOf(f) }, ...ro };
72
+ }
73
+ if (f.type === 'autodate') {
74
+ // Server-assigned create/update timestamps are never user-editable.
75
+ return { ...base, type: 'dateTime', readOnly: true };
76
+ }
77
+ if (f.type === 'actor')
78
+ return { ...base, type: 'actor', readOnly: true };
79
+ if (f.type === 'relation') {
80
+ const target = f.collectionId ? (opts.names?.get(f.collectionId) ?? f.collectionId) : undefined;
81
+ const people = target === 'people' || target === 'candidates';
82
+ return { ...base, type: 'relation', metadata: { objectName: target, shape: people ? 'circle' : 'square' }, ...ro };
83
+ }
84
+ // Unmapped (or future) types render as raw JSON — honest, never a wrong guess.
85
+ return { ...base, type: TYPE_MAP[f.type] ?? 'json', ...ro };
86
+ }
87
+ /** The raw Base fields of a collection, in the module's order where it states one. */
88
+ export function baseFieldsOf(collection) {
89
+ const raw = collection?.fields ?? collection?.schema ?? [];
90
+ if (!Array.isArray(raw))
91
+ return [];
92
+ const ordered = raw.some((f) => typeof f?.position === 'number');
93
+ return ordered ? [...raw].sort((a, b) => (a.position ?? 0) - (b.position ?? 0)) : raw;
94
+ }
95
+ /**
96
+ * Map a Base collection schema to the ordered `FieldDefinition[]` a `DataTable`
97
+ * renders. Accepts the modern `fields` key and the legacy `schema` key; skips
98
+ * hidden + system fields (keeping `id`). Total: returns `[]` for an absent or
99
+ * malformed schema.
100
+ */
101
+ export function baseCollectionToFields(collection, opts = {}) {
102
+ return baseFieldsOf(collection)
103
+ .filter(isRenderable)
104
+ .map((f) => toFieldDefinition(f, opts));
105
+ }
106
+ // ── values ───────────────────────────────────────────────────────────────────
107
+ //
108
+ // Keyed by the BASE type, which is what decides a value's shape: Base's `email`
109
+ // (one address) and `emails` (a primary and others) both read as @hanzo/data's
110
+ // `email`, and only the Base type says which to write back.
111
+ const str = (v) => (v == null ? '' : String(v).trim());
112
+ const obj = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
113
+ /** Micros per major unit of a Base currency amount. */
114
+ const MICROS = 1_000_000;
115
+ /**
116
+ * A Base value as @hanzo/data reads it. A type that is the same on both sides
117
+ * passes through; money and links become @hanzo/data's shape; an expanded
118
+ * relation becomes the record it names, so a cell shows its name, not an id.
119
+ */
120
+ export function fromBase(baseType, value, expanded) {
121
+ switch (baseType) {
122
+ case 'currency': {
123
+ const v = obj(value);
124
+ if (v.amountMicros == null || v.amountMicros === '')
125
+ return null;
126
+ const micros = Number(v.amountMicros);
127
+ return Number.isFinite(micros) ? { amount: micros / MICROS, currencyCode: str(v.currencyCode) || 'USD' } : null;
128
+ }
129
+ case 'links': {
130
+ const v = obj(value);
131
+ const out = [];
132
+ if (str(v.primaryLinkUrl))
133
+ out.push({ url: str(v.primaryLinkUrl), ...(str(v.primaryLinkLabel) ? { label: str(v.primaryLinkLabel) } : {}) });
134
+ for (const l of Array.isArray(v.secondaryLinks) ? v.secondaryLinks : []) {
135
+ const o = obj(l);
136
+ const url = str(o.url ?? o.primaryLinkUrl);
137
+ if (url)
138
+ out.push({ url, ...(str(o.label) ? { label: str(o.label) } : {}) });
139
+ }
140
+ return out;
141
+ }
142
+ case 'relation':
143
+ if (expanded && typeof expanded === 'object')
144
+ return Array.isArray(expanded) ? (expanded[0] ?? value) : expanded;
145
+ return value;
146
+ // An editor field is HTML in Base and the words it says here (html.ts).
147
+ case 'editor':
148
+ return typeof value === 'string' ? editorText(value) : value;
149
+ default:
150
+ return value;
151
+ }
152
+ }
153
+ /**
154
+ * What an edit writes back to Base for one field. `prior` is the record's current
155
+ * Base value, so a composite keeps the parts the editor does not show (a
156
+ * person's other addresses, a phone's calling code).
157
+ */
158
+ export function toBase(baseType, value, prior) {
159
+ const was = obj(prior);
160
+ switch (baseType) {
161
+ case 'currency': {
162
+ if (value == null || value === '')
163
+ return null;
164
+ const v = typeof value === 'object' ? obj(value) : { amount: value };
165
+ const amount = Number(v.amount);
166
+ if (v.amount == null || v.amount === '' || !Number.isFinite(amount))
167
+ return null;
168
+ return { amountMicros: Math.round(amount * MICROS), currencyCode: str(v.currencyCode ?? was.currencyCode) || 'USD' };
169
+ }
170
+ case 'emails': {
171
+ const list = (Array.isArray(value) ? value : str(value).split(/[,;\s]+/)).map((e) => str(e).toLowerCase()).filter(Boolean);
172
+ if (!list.length)
173
+ return null;
174
+ const [primaryEmail, ...rest] = list;
175
+ return { primaryEmail, additionalEmails: rest.length ? rest : Array.isArray(was.additionalEmails) ? was.additionalEmails : [] };
176
+ }
177
+ case 'email':
178
+ return (Array.isArray(value) ? str(value[0]) : str(value)).toLowerCase();
179
+ case 'phones': {
180
+ const v = typeof value === 'object' && value ? obj(value) : { number: value };
181
+ const number = str(v.number ?? v.primaryPhoneNumber);
182
+ if (!number)
183
+ return null;
184
+ return {
185
+ primaryPhoneNumber: number,
186
+ primaryPhoneCountryCode: str(v.country ?? v.primaryPhoneCountryCode ?? was.primaryPhoneCountryCode),
187
+ primaryPhoneCallingCode: str(v.callingCode ?? v.primaryPhoneCallingCode ?? was.primaryPhoneCallingCode),
188
+ additionalPhones: Array.isArray(was.additionalPhones) ? was.additionalPhones : [],
189
+ };
190
+ }
191
+ case 'fullName': {
192
+ const words = typeof value === 'string' ? value.trim().split(/\s+/) : null;
193
+ const v = words ? { first: words[0], last: words.slice(1).join(' ') } : obj(value);
194
+ const firstName = str(v.first ?? v.firstName);
195
+ const lastName = str(v.last ?? v.lastName);
196
+ return firstName || lastName ? { firstName, lastName } : null;
197
+ }
198
+ case 'address': {
199
+ const v = typeof value === 'string' ? { street1: value } : obj(value);
200
+ const pick = (k, base) => str(v[k] ?? v[base]);
201
+ const out = {
202
+ addressStreet1: pick('street1', 'addressStreet1'),
203
+ addressStreet2: pick('street2', 'addressStreet2'),
204
+ addressCity: pick('city', 'addressCity'),
205
+ addressState: pick('state', 'addressState'),
206
+ addressPostcode: pick('postcode', 'addressPostcode'),
207
+ addressCountry: pick('country', 'addressCountry'),
208
+ };
209
+ return Object.values(out).some(Boolean) ? out : null;
210
+ }
211
+ case 'links': {
212
+ const list = (Array.isArray(value) ? value : value ? [value] : [])
213
+ .map((l) => (typeof l === 'string' ? { url: l } : obj(l)))
214
+ .map((l) => ({ url: str(l.url), label: str(l.label) }))
215
+ .filter((l) => l.url);
216
+ if (!list.length)
217
+ return null;
218
+ const [first, ...rest] = list;
219
+ return { primaryLinkUrl: first.url, primaryLinkLabel: first.label, secondaryLinks: rest };
220
+ }
221
+ case 'relation': {
222
+ const id = (v) => (v && typeof v === 'object' ? str(obj(v).id ?? obj(v).value) : str(v));
223
+ return Array.isArray(value) ? value.map(id).filter(Boolean) : id(value);
224
+ }
225
+ case 'date': {
226
+ if (value == null || value === '')
227
+ return '';
228
+ const d = value instanceof Date ? value : new Date(String(value));
229
+ return Number.isNaN(d.getTime()) ? '' : d.toISOString().replace('T', ' ');
230
+ }
231
+ case 'editor':
232
+ return typeof value === 'string' ? paragraphs(value) : value;
233
+ default:
234
+ return value;
235
+ }
236
+ }
237
+ /**
238
+ * A record's own value for a field. The hosted Base writes a record's stamps as
239
+ * `createdAt` and `updatedAt` while its schema, its filters and its sorts name them
240
+ * `created` and `updated`; an autodate is read under either.
241
+ */
242
+ export const valueOf = (f, record) => f.type === 'autodate' && record[f.name] === undefined ? record[`${f.name}At`] : record[f.name];
243
+ /** A whole Base record as @hanzo/data reads it, each relation resolved from `expand`. */
244
+ export function recordFromBase(fields, record) {
245
+ const expand = obj(record.expand);
246
+ const out = { id: record.id };
247
+ for (const f of fields)
248
+ out[f.name] = fromBase(f.type, valueOf(f, record), expand[f.name]);
249
+ return out;
250
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AAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAmC,EAAE,MAA+B,EAAW,EAAE,CACvG,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAEhG,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAAC,MAA4B,EAAE,MAA+B;IAC1F,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACjC,MAAM,GAAG,GAA4B,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAA;IACtD,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1F,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * An `editor` field and the text a person reads and writes. Base keeps an editor
3
+ * field as HTML — paragraphs, breaks, every character escaped — and a page that
4
+ * showed it as stored printed "<p>I&#39;m a product designer…" (hanzo-inc/cloud#478).
5
+ * So an editor field is read as text and written back as paragraphs.
6
+ */
7
+ /**
8
+ * An editor field's HTML as the plain text a person wrote. A mail that was HTML
9
+ * already is filed escaped inside the editor's paragraphs, so what one pass leaves
10
+ * still reads as markup: it is read again, once.
11
+ */
12
+ export declare function plain(html: string): string;
13
+ /** Text as an editor field holds it: each paragraph its own, every character escaped. */
14
+ export declare function paragraphs(text: string): string;
15
+ /**
16
+ * An editor field as the text a field shows and edits: its paragraphs apart by a
17
+ * blank line, so paragraphs() writes back the paragraphs it read.
18
+ */
19
+ export declare const editorText: (html: string) => string;
20
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/lib/base-data/html.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI1C;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAKzB,CAAA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * An `editor` field and the text a person reads and writes. Base keeps an editor
3
+ * field as HTML — paragraphs, breaks, every character escaped — and a page that
4
+ * showed it as stored printed "<p>I&#39;m a product designer…" (hanzo-inc/cloud#478).
5
+ * So an editor field is read as text and written back as paragraphs.
6
+ */
7
+ /** One pass of HTML to text: paragraphs, breaks and tags, then the entities read back. */
8
+ const unhtml = (html) => html
9
+ .replace(/<br\s*\/?>/gi, '\n')
10
+ .replace(/<\/(p|div|li|h[1-6])>\s*/gi, '\n')
11
+ .replace(/<(style|script)[^>]*>[\s\S]*?<\/\1>/gi, '')
12
+ .replace(/<[^>]*>/g, '')
13
+ .replace(/&lt;/g, '<')
14
+ .replace(/&gt;/g, '>')
15
+ .replace(/&quot;/g, '"')
16
+ .replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
17
+ .replace(/&nbsp;/g, ' ')
18
+ .replace(/&amp;/g, '&');
19
+ /**
20
+ * An editor field's HTML as the plain text a person wrote. A mail that was HTML
21
+ * already is filed escaped inside the editor's paragraphs, so what one pass leaves
22
+ * still reads as markup: it is read again, once.
23
+ */
24
+ export function plain(html) {
25
+ let text = unhtml(html);
26
+ if (/<\/?[a-z][^>]*>/i.test(text))
27
+ text = unhtml(text);
28
+ return text.replace(/\n{3,}/g, '\n\n').trim();
29
+ }
30
+ /** Text as an editor field holds it: each paragraph its own, every character escaped. */
31
+ export function paragraphs(text) {
32
+ const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
33
+ return text
34
+ .split(/\n{2,}/)
35
+ .map((p) => p.trim())
36
+ .filter(Boolean)
37
+ .map((p) => `<p>${esc(p).replace(/\n/g, '<br>')}</p>`)
38
+ .join('');
39
+ }
40
+ /**
41
+ * An editor field as the text a field shows and edits: its paragraphs apart by a
42
+ * blank line, so paragraphs() writes back the paragraphs it read.
43
+ */
44
+ export const editorText = (html) => html
45
+ .split(/<\/p\s*>/i)
46
+ .map(plain)
47
+ .filter(Boolean)
48
+ .join('\n\n');
49
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../../../src/lib/base-data/html.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0FAA0F;AAC1F,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CACtC,IAAI;KACD,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC;KAC7B,OAAO,CAAC,4BAA4B,EAAE,IAAI,CAAC;KAC3C,OAAO,CAAC,uCAAuC,EAAE,EAAE,CAAC;KACpD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;KACvB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;KACrB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;KACrB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;KACvB,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;KACtE,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;KACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AAE3B;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IACtD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;AAC/C,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC/F,OAAO,IAAI;SACR,KAAK,CAAC,QAAQ,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;SACrD,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CACjD,IAAI;KACD,KAAK,CAAC,WAAW,CAAC;KAClB,GAAG,CAAC,KAAK,CAAC;KACV,MAAM,CAAC,OAAO,CAAC;KACf,IAAI,CAAC,MAAM,CAAC,CAAA"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * A @hanzo/data view as a Base query: its search, its filter rules (by every or
3
+ * any), and its sort, written in Base's own filter and sort language so the
4
+ * server does the work and the browser holds one page.
5
+ *
6
+ * Each rule compiles from the field's BASE type, because that is what decides how
7
+ * Base reaches the value: a person's name is a JSON object searched across its
8
+ * parts (`name ~ "ada"`), money is compared by its micros (`amount.amountMicros
9
+ * >= 1000000000`), a primary address is one part (`emails.primaryEmail = …`), and
10
+ * a calendar day is a range of stamps. A rule that is not finished (no operand
11
+ * yet) is left out, as the table's own logic leaves it out.
12
+ *
13
+ * Pure: data in, a string out.
14
+ */
15
+ import type { FilterRule, SortRule } from '@hanzo/data';
16
+ import type { BaseField } from './fields.js';
17
+ /** What a view holds that a query reads. */
18
+ export interface QueryView {
19
+ filters: FilterRule[];
20
+ match?: 'and' | 'or';
21
+ sorts: SortRule[];
22
+ search?: string;
23
+ }
24
+ /** A Base list query's `filter` and `sort`, each empty when the view asks nothing. */
25
+ export interface BaseQuery {
26
+ filter: string;
27
+ sort: string;
28
+ }
29
+ /** A string literal in Base's filter language. */
30
+ export declare function lit(v: unknown): string;
31
+ /** A day (YYYY-MM-DD) from a date operand, or '' when it names none. */
32
+ export declare function dayOf(v: unknown): string;
33
+ /** One rule as a Base filter expression, or '' when it constrains nothing yet. */
34
+ export declare function ruleFilter(field: BaseField, rule: FilterRule): string;
35
+ /**
36
+ * The parts a relation is read by when searched or sorted: what it points at is
37
+ * named by its field (a CRM `company` is a company, a `contact` or `person` a
38
+ * person), and a person's name is two parts.
39
+ */
40
+ export declare function relationPaths(field: BaseField): string[];
41
+ /** A quick search across every text field of a collection, and the names of what it relates to. */
42
+ export declare function searchFilter(fields: readonly BaseField[], search: string | undefined): string;
43
+ export declare function sortOf(fields: readonly BaseField[], sorts: SortRule[]): string;
44
+ /**
45
+ * The view as one Base query. `scope` is what every row must also meet (a
46
+ * pipeline, a list's members), ANDed outside the view's own rules, so an `or`
47
+ * view never reaches past it.
48
+ */
49
+ export declare function baseQuery(fields: readonly BaseField[], view: QueryView, scope?: string): BaseQuery;
50
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/lib/base-data/query.ts"],"names":[],"mappings":"AAAA;;;;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String(v ?? '').replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
4
+ }
5
+ const num = (v) => {
6
+ if (v == null || v === '')
7
+ return null;
8
+ if (typeof v === 'object' && !Array.isArray(v) && 'amount' in v)
9
+ return num(v.amount);
10
+ const n = Number(v);
11
+ return Number.isFinite(n) ? n : null;
12
+ };
13
+ /** A day (YYYY-MM-DD) from a date operand, or '' when it names none. */
14
+ export function dayOf(v) {
15
+ if (v == null || v === '')
16
+ return '';
17
+ const s = String(v).trim();
18
+ const m = s.match(/^(\d{4}-\d{2}-\d{2})/);
19
+ if (m)
20
+ return m[1];
21
+ const d = new Date(s);
22
+ return Number.isNaN(d.getTime()) ? '' : d.toISOString().slice(0, 10);
23
+ }
24
+ const start = (day) => lit(`${day} 00:00:00.000Z`);
25
+ const end = (day) => lit(`${day} 23:59:59.999Z`);
26
+ /**
27
+ * The parts of each composite a person searches. A "contains" over the whole
28
+ * value would read its JSON text, keys and all, so "first" would find every
29
+ * person (`{"firstName":…}`): a composite is searched part by part instead.
30
+ */
31
+ const TEXT_PARTS = {
32
+ fullName: ['firstName', 'lastName'],
33
+ emails: ['primaryEmail', 'additionalEmails'],
34
+ phones: ['primaryPhoneNumber', 'additionalPhones'],
35
+ links: ['primaryLinkUrl', 'primaryLinkLabel'],
36
+ address: ['addressStreet1', 'addressCity', 'addressState', 'addressPostcode', 'addressCountry'],
37
+ };
38
+ const COMPOSITE_TEXT = new Set(Object.keys(TEXT_PARTS));
39
+ /** Whether a field's text holds `q`: across a composite's parts, or the field itself. */
40
+ function contains(field, q, negate = false) {
41
+ const parts = TEXT_PARTS[field.type];
42
+ if (!parts)
43
+ return `${field.type === 'actor' ? `${field.name}.name` : field.name} ${negate ? '!~' : '~'} ${lit(q)}`;
44
+ // A part a record leaves out reads as NULL, which "does not contain" must count as not containing.
45
+ return negate
46
+ ? and(parts.map((p) => `(${field.name}.${p} = null || ${field.name}.${p} !~ ${lit(q)})`))
47
+ : or(parts.map((p) => `${field.name}.${p} ~ ${lit(q)}`));
48
+ }
49
+ /** The part a composite's "is" compares, where the composite has one that is the value. */
50
+ const PRIMARY = { emails: 'primaryEmail', phones: 'primaryPhoneNumber', links: 'primaryLinkUrl' };
51
+ /** The part a relation is read by when searched or sorted: its target's name. */
52
+ const LABEL = 'name';
53
+ const and = (xs) => (xs.length === 1 ? xs[0] : `(${xs.join(' && ')})`);
54
+ const or = (xs) => (xs.length === 1 ? xs[0] : `(${xs.join(' || ')})`);
55
+ const set = (v) => (Array.isArray(v) ? v : v == null || v === '' ? [] : [v]).map((x) => (x && typeof x === 'object' ? String(x.id ?? x.value ?? '') : String(x))).filter(Boolean);
56
+ const range = (v) => {
57
+ const pair = Array.isArray(v) ? v : [];
58
+ const end_ = (x) => (x == null || x === '' ? undefined : x);
59
+ return [end_(pair[0]), end_(pair[1])];
60
+ };
61
+ /** One rule as a Base filter expression, or '' when it constrains nothing yet. */
62
+ export function ruleFilter(field, rule) {
63
+ const f = field.name;
64
+ const op = rule.op;
65
+ const t = field.type;
66
+ if (op === 'isEmpty' || op === 'isNotEmpty') {
67
+ const empty = op === 'isEmpty';
68
+ if (t === 'number')
69
+ return empty ? `${f} = 0` : `${f} != 0`;
70
+ if (t === 'currency')
71
+ return empty ? `${f}.amountMicros = null` : `${f}.amountMicros != null`;
72
+ if (t === 'bool')
73
+ return empty ? `${f} = false` : `${f} = true`;
74
+ if (COMPOSITE_TEXT.has(t)) {
75
+ // An empty composite is NULL; one with a primary part may also hold it blank.
76
+ const part = PRIMARY[t];
77
+ if (!part)
78
+ return `${f} ${empty ? '=' : '!='} null`;
79
+ return empty ? or([`${f} = null`, `${f}.${part} = ""`]) : and([`${f} != null`, `${f}.${part} != ""`]);
80
+ }
81
+ return `${f} ${empty ? '=' : '!='} ""`;
82
+ }
83
+ if (t === 'number' || t === 'currency') {
84
+ const path = t === 'currency' ? `${f}.amountMicros` : f;
85
+ const scale = (n) => (t === 'currency' ? Math.round(n * 1_000_000) : n);
86
+ if (op === 'between') {
87
+ const [lo, hi] = range(rule.value).map(num);
88
+ const parts = [lo != null ? `${path} >= ${scale(lo)}` : '', hi != null ? `${path} <= ${scale(hi)}` : ''].filter(Boolean);
89
+ return parts.length ? and(parts) : '';
90
+ }
91
+ const n = num(rule.value);
92
+ if (n == null)
93
+ return '';
94
+ const cmp = { is: '=', isNot: '!=', gt: '>', gte: '>=', lt: '<', lte: '<=' };
95
+ return cmp[op] ? `${path} ${cmp[op]} ${scale(n)}` : '';
96
+ }
97
+ if (t === 'date' || t === 'autodate') {
98
+ if (op === 'between') {
99
+ const [lo, hi] = range(rule.value).map(dayOf);
100
+ const parts = [lo ? `${f} >= ${start(lo)}` : `${f} != ""`, hi ? `${f} <= ${end(hi)}` : ''].filter(Boolean);
101
+ return lo || hi ? and(parts) : '';
102
+ }
103
+ const day = dayOf(rule.value);
104
+ if (!day)
105
+ return '';
106
+ switch (op) {
107
+ case 'is': return and([`${f} >= ${start(day)}`, `${f} <= ${end(day)}`]);
108
+ case 'isNot': return or([`${f} < ${start(day)}`, `${f} > ${end(day)}`]);
109
+ case 'gt': return `${f} > ${end(day)}`;
110
+ case 'gte': return `${f} >= ${start(day)}`;
111
+ // A date left empty is "", which sorts before every day: "before" is only a day that is set.
112
+ case 'lt': return and([`${f} != ""`, `${f} < ${start(day)}`]);
113
+ case 'lte': return and([`${f} != ""`, `${f} <= ${end(day)}`]);
114
+ default: return '';
115
+ }
116
+ }
117
+ if (t === 'bool') {
118
+ if (rule.value == null || rule.value === '')
119
+ return '';
120
+ const on = rule.value === true || rule.value === 'true' || rule.value === 1;
121
+ return op === 'isNot' ? `${f} != ${on}` : `${f} = ${on}`;
122
+ }
123
+ if (t === 'select' || t === 'relation') {
124
+ const multi = (field.maxSelect ?? 1) > 1;
125
+ const values = set(rule.value);
126
+ if (!values.length)
127
+ return '';
128
+ const eq = multi ? '?=' : '=';
129
+ if (op === 'isAnyOf')
130
+ return or(values.map((v) => `${f} ${eq} ${lit(v)}`));
131
+ if (op === 'is')
132
+ return `${f} ${eq} ${lit(values[0])}`;
133
+ if (op === 'isNot')
134
+ return multi ? `${f} !~ ${lit(values[0])}` : `${f} != ${lit(values[0])}`;
135
+ // A relation searched by words reads its target's name.
136
+ if (t === 'relation' && op === 'contains')
137
+ return or(relationPaths(field).map((p) => `${p} ~ ${lit(values[0])}`));
138
+ if (t === 'relation' && op === 'notContains')
139
+ return and(relationPaths(field).map((p) => `${p} !~ ${lit(values[0])}`));
140
+ return '';
141
+ }
142
+ const text = rule.value == null ? '' : String(Array.isArray(rule.value) ? rule.value[0] ?? '' : rule.value).trim();
143
+ if (!text)
144
+ return '';
145
+ const part = PRIMARY[t];
146
+ const exact = t === 'emails' || t === 'email' ? text.toLowerCase() : text;
147
+ switch (op) {
148
+ case 'contains': return contains(field, text);
149
+ case 'notContains': return contains(field, text, true);
150
+ // A composite with no single part that is its value (a name, an address) is matched by its words.
151
+ case 'is': return part ? `${f}.${part} = ${lit(exact)}` : COMPOSITE_TEXT.has(t) ? contains(field, text) : `${t === 'actor' ? `${f}.name` : f} = ${lit(exact)}`;
152
+ case 'isNot': return part ? `${f}.${part} != ${lit(exact)}` : COMPOSITE_TEXT.has(t) ? contains(field, text, true) : `${t === 'actor' ? `${f}.name` : f} != ${lit(exact)}`;
153
+ default: return '';
154
+ }
155
+ }
156
+ /** The Base types a quick search reads. */
157
+ const SEARCHED = new Set(['text', 'email', 'url', 'fullName', 'emails', 'phones', 'links', 'address']);
158
+ /**
159
+ * The parts a relation is read by when searched or sorted: what it points at is
160
+ * named by its field (a CRM `company` is a company, a `contact` or `person` a
161
+ * person), and a person's name is two parts.
162
+ */
163
+ export function relationPaths(field) {
164
+ if (/^(contact|person|people)$/.test(field.name))
165
+ return [`${field.name}.name.firstName`, `${field.name}.name.lastName`];
166
+ return [`${field.name}.${LABEL}`];
167
+ }
168
+ /** A quick search across every text field of a collection, and the names of what it relates to. */
169
+ export function searchFilter(fields, search) {
170
+ const q = (search ?? '').trim();
171
+ if (!q)
172
+ return '';
173
+ const reads = fields.filter((f) => !f.hidden && SEARCHED.has(f.type)).map((f) => contains(f, q));
174
+ const related = fields
175
+ .filter((f) => f.type === 'relation' && !f.hidden && (f.maxSelect ?? 1) <= 1 && /^(company|contact|person)$/.test(f.name))
176
+ .flatMap((f) => relationPaths(f).map((p) => `${p} ~ ${lit(q)}`));
177
+ const all = [...reads, ...related];
178
+ return all.length ? or(all) : '';
179
+ }
180
+ /** A sort rule as Base names it: a composite by its part a person reads first. */
181
+ const SORT_PART = {
182
+ fullName: 'firstName',
183
+ emails: 'primaryEmail',
184
+ phones: 'primaryPhoneNumber',
185
+ links: 'primaryLinkUrl',
186
+ address: 'addressCity',
187
+ currency: 'amountMicros',
188
+ actor: 'name',
189
+ };
190
+ export function sortOf(fields, sorts) {
191
+ const byName = new Map(fields.map((f) => [f.name, f]));
192
+ return sorts
193
+ .map((s) => {
194
+ const f = byName.get(s.field);
195
+ if (!f)
196
+ return '';
197
+ const path = SORT_PART[f.type] ? `${f.name}.${SORT_PART[f.type]}` : f.type === 'relation' ? relationPaths(f)[0] : f.name;
198
+ return `${s.dir === 'desc' ? '-' : ''}${path}`;
199
+ })
200
+ .filter(Boolean)
201
+ .join(',');
202
+ }
203
+ /**
204
+ * The view as one Base query. `scope` is what every row must also meet (a
205
+ * pipeline, a list's members), ANDed outside the view's own rules, so an `or`
206
+ * view never reaches past it.
207
+ */
208
+ export function baseQuery(fields, view, scope) {
209
+ const byName = new Map(fields.map((f) => [f.name, f]));
210
+ const rules = view.filters
211
+ .map((r) => {
212
+ const f = byName.get(r.field);
213
+ return f ? ruleFilter(f, r) : '';
214
+ })
215
+ .filter(Boolean);
216
+ const matched = rules.length ? (view.match === 'or' ? or(rules) : and(rules)) : '';
217
+ const parts = [scope ?? '', searchFilter(fields, view.search), matched].filter(Boolean);
218
+ return { filter: parts.length ? and(parts) : '', sort: sortOf(fields, view.sorts) };
219
+ }
220
+ //# sourceMappingURL=query.js.map