clivly 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -27
- package/{adapter-BMAUq4hf.d.mts → adapter-C63F9VZL.d.mts} +1 -3
- package/{adapter-IH3r_I8v.d.cts → adapter-OO5g17qF.d.cts} +1 -3
- package/{auth-adapter-CiEXcweZ.cjs → auth-adapter-CNVuxT9W.cjs} +1 -2
- package/{auth-adapter-Bt1GZiag.d.cts → auth-adapter-COMP0Fud.d.cts} +1 -3
- package/{auth-adapter-CHy273qb.d.mts → auth-adapter-ZlhllVpm.d.mts} +1 -3
- package/{auth-adapter-gfVDxf3d.mjs → auth-adapter-u91PByaw.mjs} +1 -2
- package/auth-better-auth.cjs +2 -4
- package/auth-better-auth.d.cts +1 -5
- package/auth-better-auth.d.mts +1 -5
- package/auth-better-auth.mjs +2 -4
- package/auth-clerk.cjs +2 -4
- package/auth-clerk.d.cts +1 -5
- package/auth-clerk.d.mts +1 -5
- package/auth-clerk.mjs +2 -4
- package/auth-workos.cjs +2 -4
- package/auth-workos.d.cts +1 -5
- package/auth-workos.d.mts +1 -5
- package/auth-workos.mjs +2 -4
- package/core-adapter.cjs +2 -3
- package/core-adapter.d.cts +1 -1
- package/core-adapter.d.mts +1 -1
- package/core-adapter.mjs +2 -3
- package/core-auth-adapter.cjs +3 -4
- package/core-auth-adapter.d.cts +1 -1
- package/core-auth-adapter.d.mts +1 -1
- package/core-auth-adapter.mjs +3 -5
- package/core-drizzle.cjs +3 -4
- package/core-drizzle.d.cts +1 -1
- package/core-drizzle.d.mts +1 -1
- package/core-drizzle.mjs +3 -5
- package/core-entity-config.cjs +3 -4
- package/core-entity-config.d.cts +1 -1
- package/core-entity-config.d.mts +1 -1
- package/core-entity-config.mjs +3 -5
- package/core-entity-heuristics.cjs +18 -18
- package/core-entity-heuristics.d.cts +3 -3
- package/core-entity-heuristics.d.mts +3 -3
- package/core-entity-heuristics.mjs +3 -5
- package/core-mapping-form.cjs +3 -4
- package/core-mapping-form.d.cts +1 -1
- package/core-mapping-form.d.mts +1 -1
- package/core-mapping-form.mjs +3 -5
- package/core-mapping-score.cjs +3 -4
- package/core-mapping-score.d.cts +1 -1
- package/core-mapping-score.d.mts +1 -1
- package/core-mapping-score.mjs +3 -5
- package/core-mappings-config.cjs +3 -4
- package/core-mappings-config.d.cts +1 -1
- package/core-mappings-config.d.mts +1 -1
- package/core-mappings-config.mjs +3 -5
- package/core-sync-engine.cjs +3 -4
- package/core-sync-engine.d.cts +1 -1
- package/core-sync-engine.d.mts +1 -1
- package/core-sync-engine.mjs +3 -5
- package/core-types.cjs +3 -4
- package/core-types.d.cts +1 -1
- package/core-types.d.mts +1 -1
- package/core-types.mjs +3 -5
- package/core-view-compiler.cjs +3 -4
- package/core-view-compiler.d.cts +1 -1
- package/core-view-compiler.d.mts +1 -1
- package/core-view-compiler.mjs +3 -5
- package/core.cjs +13 -13
- package/core.d.cts +11 -11
- package/core.d.mts +11 -11
- package/core.mjs +13 -14
- package/{deprecate-subpath-CmvZtCpE.mjs → deprecate-subpath-CK37DKXH.mjs} +1 -2
- package/{deprecate-subpath-B9ngvizt.cjs → deprecate-subpath-dGwDiHKV.cjs} +1 -2
- package/{drizzle-CiK37zJm.d.cts → drizzle-B9cjBavj.d.cts} +1 -3
- package/{drizzle-DcB7OfBp.cjs → drizzle-C0bfX-6a.cjs} +1 -2
- package/{drizzle-wbcuG-cy.mjs → drizzle-CZuOzIu4.mjs} +1 -2
- package/{drizzle-ehVWLSrN.d.mts → drizzle-L5FOGe_-.d.mts} +1 -3
- package/{drizzle-meta-Bb1JWYqf.cjs → drizzle-meta-BPnRLpsB.cjs} +1 -2
- package/{drizzle-meta-D-5k3n0i.mjs → drizzle-meta-D00lFvAk.mjs} +1 -2
- package/drizzle.cjs +7 -10
- package/drizzle.d.cts +3 -7
- package/drizzle.d.mts +3 -7
- package/drizzle.mjs +7 -10
- package/{entity-config-BI4RYNKL.cjs → entity-config-DiCJ6mhI.cjs} +8 -11
- package/entity-config-X-KlnYXX.d.mts +632 -0
- package/entity-config-dNclLyBM.d.cts +632 -0
- package/{entity-config-Ccfb2IL9.mjs → entity-config-g_oMPXlN.mjs} +8 -11
- package/entity-heuristics-CIParuQe.cjs +655 -0
- package/entity-heuristics-DE5ujoHw.mjs +566 -0
- package/index.cjs +65 -111
- package/index.d.cts +1 -12
- package/index.d.mts +1 -12
- package/index.mjs +53 -99
- package/{integration-state-BA4c0RbD.d.mts → integration-state-xK4PLm5T.d.cts} +0 -2
- package/{integration-state-BA4c0RbD.d.cts → integration-state-xK4PLm5T.d.mts} +0 -2
- package/{internal-CLvZdVj5.mjs → internal-9oDwwbNg.mjs} +37 -9
- package/{internal-DsArcqkP.cjs → internal-BKYt5j0l.cjs} +42 -8
- package/{internal-C7NlPM3M.d.mts → internal-COALpgov.d.cts} +1 -17
- package/{internal-D2J4VQWT.d.cts → internal-D3q4FPcA.d.mts} +1 -17
- package/internal-adapter.d.cts +1 -1
- package/internal-adapter.d.mts +1 -1
- package/internal-auth-adapter.cjs +1 -1
- package/internal-auth-adapter.d.cts +1 -1
- package/internal-auth-adapter.d.mts +1 -1
- package/internal-auth-adapter.mjs +1 -2
- package/internal-drizzle.cjs +1 -1
- package/internal-drizzle.d.cts +1 -1
- package/internal-drizzle.d.mts +1 -1
- package/internal-drizzle.mjs +1 -2
- package/internal-entity-config.cjs +1 -1
- package/internal-entity-config.d.cts +1 -1
- package/internal-entity-config.d.mts +1 -1
- package/internal-entity-config.mjs +1 -2
- package/internal-entity-heuristics.cjs +16 -576
- package/internal-entity-heuristics.d.cts +4 -4
- package/internal-entity-heuristics.d.mts +4 -4
- package/internal-entity-heuristics.mjs +1 -563
- package/internal-mapping-form.cjs +1 -1
- package/internal-mapping-form.d.cts +1 -1
- package/internal-mapping-form.d.mts +1 -1
- package/internal-mapping-form.mjs +1 -2
- package/internal-mapping-score.cjs +1 -1
- package/internal-mapping-score.d.cts +1 -1
- package/internal-mapping-score.d.mts +1 -1
- package/internal-mapping-score.mjs +1 -2
- package/internal-mappings-config.cjs +1 -1
- package/internal-mappings-config.d.cts +1 -1
- package/internal-mappings-config.d.mts +1 -1
- package/internal-mappings-config.mjs +1 -2
- package/internal-sync-engine.cjs +1 -1
- package/internal-sync-engine.d.cts +1 -1
- package/internal-sync-engine.d.mts +1 -1
- package/internal-sync-engine.mjs +1 -2
- package/internal-types.cjs +1 -1
- package/internal-types.d.cts +1 -1
- package/internal-types.d.mts +1 -1
- package/internal-types.mjs +1 -2
- package/internal-view-compiler.cjs +1 -1
- package/internal-view-compiler.d.cts +1 -1
- package/internal-view-compiler.d.mts +1 -1
- package/internal-view-compiler.mjs +1 -2
- package/internal.cjs +11 -10
- package/internal.d.cts +11 -11
- package/internal.d.mts +11 -11
- package/internal.mjs +11 -11
- package/{mapping-form-XsLLCqW_.d.cts → mapping-form-Bpvgf5b8.d.mts} +1 -3
- package/{mapping-form-BpfON_ME.cjs → mapping-form-Bs6JQurC.cjs} +1 -2
- package/{mapping-form-DigkuvFc.mjs → mapping-form-C7kDMWzp.mjs} +1 -2
- package/{mapping-form-Btn-7gzv.d.mts → mapping-form-CV7y6qox.d.cts} +1 -3
- package/{mapping-score-D7Gzg7Ii.d.cts → mapping-score-BKrxddz0.d.cts} +0 -2
- package/{mapping-score-D7Gzg7Ii.d.mts → mapping-score-BKrxddz0.d.mts} +0 -2
- package/{mapping-score-C68uAqGB.mjs → mapping-score-CS-MTDL9.mjs} +1 -2
- package/{mapping-score-CaB3F4Uu.cjs → mapping-score-D2TCQiOr.cjs} +1 -2
- package/{mappings-config-D6_oCi2Q.d.mts → mappings-config-BBppW9fp.d.cts} +1 -3
- package/{mappings-config-BCsRLohT.cjs → mappings-config-CNxBrbt9.cjs} +3 -4
- package/{mappings-config-CwQNQ6bA.mjs → mappings-config-D_g20PyS.mjs} +3 -4
- package/{mappings-config-iJzbcUMp.d.cts → mappings-config-Dmm0H6p_.d.mts} +1 -3
- package/{namespace-probe-DykR0kgh.d.mts → namespace-probe-BHk3NcyI.d.cts} +32 -9
- package/{namespace-probe-H7yWc0JV.d.cts → namespace-probe-Dt_HXcI-.d.mts} +32 -9
- package/package.json +1 -7
- package/{projection-DvNewmI1.mjs → projection-BkYXvjTr.mjs} +2444 -1166
- package/{projection-BELgANG2.cjs → projection-By63gMC-.cjs} +2447 -1163
- package/{projection-sql-DweUaWRc.mjs → projection-sql-C3gZE3GS.mjs} +2 -3
- package/{projection-sql-DuCtFE9t.cjs → projection-sql-CHz7KzNS.cjs} +2 -3
- package/schemas-BSuo_eZQ.d.cts +2160 -0
- package/schemas-BSuo_eZQ.d.mts +2160 -0
- package/{sdk-ZMy4C4VK.cjs → sdk-BZSTXPyK.cjs} +185 -74
- package/{sdk-DLoVPlGB.mjs → sdk-KzHpSf7F.mjs} +185 -74
- package/sdk.cjs +2 -2
- package/sdk.d.cts +4 -12
- package/sdk.d.mts +4 -12
- package/sdk.mjs +2 -2
- package/{sync-engine-C_5TpvfX.d.mts → sync-engine-C7W0Gkq0.d.cts} +2 -4
- package/{sync-engine-CYsWOujz.d.cts → sync-engine-C9Q2FkR9.d.mts} +2 -4
- package/{sync-engine-DH058G3w.mjs → sync-engine-CwdLkmch.mjs} +2 -3
- package/{sync-engine-BGVDsrOQ.cjs → sync-engine-Di-vF26b.cjs} +2 -3
- package/{types-YJTkXKzU.mjs → types-8KSw2AWg.mjs} +1 -2
- package/{types-Cq5gHCTq.cjs → types-B8m39L1s.cjs} +1 -2
- package/{types-CpAtAtxd.d.cts → types-C9_2vW5a.d.mts} +30 -3
- package/{types-CpAtAtxd.d.mts → types-CQ2DgEH7.d.cts} +30 -3
- package/{view-compiler-C-6RydKK.mjs → view-compiler-CLTi1VL-.mjs} +3 -4
- package/{view-compiler-xiwm5iar.cjs → view-compiler-DaOz5QVl.cjs} +3 -4
- package/{view-compiler-CwKVoK1w.d.mts → view-compiler-M23WiVGG.d.mts} +1 -3
- package/{view-compiler-Cq8apvZ4.d.cts → view-compiler-cXqt4X-c.d.cts} +1 -3
- package/vite.cjs +1 -2
- package/vite.d.cts +2 -4
- package/vite.d.mts +2 -4
- package/vite.mjs +1 -2
- package/entity-config-ApnT5j3X.d.cts +0 -4472
- package/entity-config-CKcj4-M_.d.mts +0 -4473
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
|
|
2
|
+
const require_mapping_score = require("./mapping-score-D2TCQiOr.cjs");
|
|
3
|
+
// ../core/src/entity-heuristics.ts
|
|
4
|
+
const TARGET_CONCEPTS = [
|
|
5
|
+
"contact",
|
|
6
|
+
"company",
|
|
7
|
+
"deal",
|
|
8
|
+
"activity",
|
|
9
|
+
"conversation",
|
|
10
|
+
"note"
|
|
11
|
+
];
|
|
12
|
+
const TABLE_PATTERNS = [
|
|
13
|
+
{
|
|
14
|
+
concept: "contact",
|
|
15
|
+
names: [
|
|
16
|
+
"users",
|
|
17
|
+
"customers",
|
|
18
|
+
"clients",
|
|
19
|
+
"accounts",
|
|
20
|
+
"participants",
|
|
21
|
+
"attendees",
|
|
22
|
+
"people",
|
|
23
|
+
"members",
|
|
24
|
+
"contacts",
|
|
25
|
+
"students",
|
|
26
|
+
"pupils",
|
|
27
|
+
"learners",
|
|
28
|
+
"patients",
|
|
29
|
+
"subscribers",
|
|
30
|
+
"donors",
|
|
31
|
+
"guests",
|
|
32
|
+
"residents",
|
|
33
|
+
"tenants",
|
|
34
|
+
"applicants",
|
|
35
|
+
"candidates",
|
|
36
|
+
"leads",
|
|
37
|
+
"prospects"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
concept: "company",
|
|
42
|
+
names: [
|
|
43
|
+
"companies",
|
|
44
|
+
"organizations",
|
|
45
|
+
"organisations",
|
|
46
|
+
"orgs",
|
|
47
|
+
"teams",
|
|
48
|
+
"businesses",
|
|
49
|
+
"accounts"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
concept: "deal",
|
|
54
|
+
names: [
|
|
55
|
+
"deals",
|
|
56
|
+
"opportunities",
|
|
57
|
+
"subscriptions",
|
|
58
|
+
"orders",
|
|
59
|
+
"invoices",
|
|
60
|
+
"sales"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
concept: "conversation",
|
|
65
|
+
names: [
|
|
66
|
+
"conversations",
|
|
67
|
+
"messages",
|
|
68
|
+
"tickets",
|
|
69
|
+
"threads",
|
|
70
|
+
"chats",
|
|
71
|
+
"inbox"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
concept: "activity",
|
|
76
|
+
names: [
|
|
77
|
+
"events",
|
|
78
|
+
"activities",
|
|
79
|
+
"jobs",
|
|
80
|
+
"logs",
|
|
81
|
+
"audit",
|
|
82
|
+
"shifts",
|
|
83
|
+
"scans",
|
|
84
|
+
"sessions"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
concept: "note",
|
|
89
|
+
names: [
|
|
90
|
+
"notes",
|
|
91
|
+
"comments",
|
|
92
|
+
"annotations"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
const CONCEPT_FIELDS = {
|
|
97
|
+
contact: [
|
|
98
|
+
{
|
|
99
|
+
field: "name",
|
|
100
|
+
candidates: [
|
|
101
|
+
"name",
|
|
102
|
+
"full_name",
|
|
103
|
+
"fullname",
|
|
104
|
+
"display_name",
|
|
105
|
+
"first_name",
|
|
106
|
+
"firstname",
|
|
107
|
+
"given_name"
|
|
108
|
+
],
|
|
109
|
+
required: false
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
field: "email",
|
|
113
|
+
candidates: ["email", "email_address"],
|
|
114
|
+
required: true
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
field: "phone",
|
|
118
|
+
candidates: [
|
|
119
|
+
"phone",
|
|
120
|
+
"phone_number",
|
|
121
|
+
"phonenumber",
|
|
122
|
+
"mobile",
|
|
123
|
+
"mobile_number",
|
|
124
|
+
"mobilenumber",
|
|
125
|
+
"telephone"
|
|
126
|
+
],
|
|
127
|
+
required: false
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
company: [{
|
|
131
|
+
field: "name",
|
|
132
|
+
candidates: [
|
|
133
|
+
"name",
|
|
134
|
+
"company_name",
|
|
135
|
+
"legal_name",
|
|
136
|
+
"title"
|
|
137
|
+
],
|
|
138
|
+
required: true
|
|
139
|
+
}, {
|
|
140
|
+
field: "domain",
|
|
141
|
+
candidates: [
|
|
142
|
+
"domain",
|
|
143
|
+
"website",
|
|
144
|
+
"url"
|
|
145
|
+
],
|
|
146
|
+
required: false
|
|
147
|
+
}],
|
|
148
|
+
deal: [
|
|
149
|
+
{
|
|
150
|
+
field: "name",
|
|
151
|
+
candidates: ["name", "title"],
|
|
152
|
+
required: true
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
field: "value",
|
|
156
|
+
candidates: [
|
|
157
|
+
"value",
|
|
158
|
+
"amount",
|
|
159
|
+
"total",
|
|
160
|
+
"price"
|
|
161
|
+
],
|
|
162
|
+
required: false
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
field: "stage",
|
|
166
|
+
candidates: [
|
|
167
|
+
"stage",
|
|
168
|
+
"status",
|
|
169
|
+
"state"
|
|
170
|
+
],
|
|
171
|
+
required: false
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
activity: [
|
|
175
|
+
{
|
|
176
|
+
field: "type",
|
|
177
|
+
candidates: [
|
|
178
|
+
"type",
|
|
179
|
+
"kind",
|
|
180
|
+
"event_type"
|
|
181
|
+
],
|
|
182
|
+
required: false
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
field: "summary",
|
|
186
|
+
candidates: [
|
|
187
|
+
"summary",
|
|
188
|
+
"description",
|
|
189
|
+
"message",
|
|
190
|
+
"title"
|
|
191
|
+
],
|
|
192
|
+
required: false
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
field: "createdAt",
|
|
196
|
+
candidates: [
|
|
197
|
+
"created_at",
|
|
198
|
+
"createdat",
|
|
199
|
+
"timestamp"
|
|
200
|
+
],
|
|
201
|
+
required: false
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
conversation: [{
|
|
205
|
+
field: "status",
|
|
206
|
+
candidates: ["status", "state"],
|
|
207
|
+
required: false
|
|
208
|
+
}, {
|
|
209
|
+
field: "subject",
|
|
210
|
+
candidates: [
|
|
211
|
+
"subject",
|
|
212
|
+
"title",
|
|
213
|
+
"preview"
|
|
214
|
+
],
|
|
215
|
+
required: false
|
|
216
|
+
}],
|
|
217
|
+
note: [{
|
|
218
|
+
field: "body",
|
|
219
|
+
candidates: [
|
|
220
|
+
"body",
|
|
221
|
+
"content",
|
|
222
|
+
"text",
|
|
223
|
+
"note"
|
|
224
|
+
],
|
|
225
|
+
required: true
|
|
226
|
+
}]
|
|
227
|
+
};
|
|
228
|
+
const CURSOR_CANDIDATES = [
|
|
229
|
+
"updatedat",
|
|
230
|
+
"updated_at",
|
|
231
|
+
"modifiedat",
|
|
232
|
+
"modified_at",
|
|
233
|
+
"createdat",
|
|
234
|
+
"created_at"
|
|
235
|
+
];
|
|
236
|
+
function suggestCursorField(columnKeys) {
|
|
237
|
+
const lowerToActual = new Map(columnKeys.map((c) => [c.toLowerCase(), c]));
|
|
238
|
+
for (const candidate of CURSOR_CANDIDATES) {
|
|
239
|
+
const match = lowerToActual.get(candidate);
|
|
240
|
+
if (match) return match;
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const MATERIALIZING = new Set(require_entity_config.MATERIALIZING_CONCEPTS);
|
|
245
|
+
const ENDS_IN_CONSONANT_Y = /[^aeiou]y$/;
|
|
246
|
+
const NEEDS_ES = /(s|x|z|ch|sh)$/;
|
|
247
|
+
const IRREGULAR_PLURALS = {
|
|
248
|
+
person: "people",
|
|
249
|
+
child: "children",
|
|
250
|
+
man: "men",
|
|
251
|
+
woman: "women"
|
|
252
|
+
};
|
|
253
|
+
function pluralize(name) {
|
|
254
|
+
const irregular = IRREGULAR_PLURALS[name];
|
|
255
|
+
if (irregular) return irregular;
|
|
256
|
+
if (ENDS_IN_CONSONANT_Y.test(name)) return `${name.slice(0, -1)}ies`;
|
|
257
|
+
if (NEEDS_ES.test(name)) return `${name}es`;
|
|
258
|
+
return `${name}s`;
|
|
259
|
+
}
|
|
260
|
+
function matchesConcept(tableName, concept) {
|
|
261
|
+
const normalized = tableName.toLowerCase();
|
|
262
|
+
const entry = TABLE_PATTERNS.find((p) => p.concept === concept);
|
|
263
|
+
if (!entry) return null;
|
|
264
|
+
const candidates = [normalized, pluralize(normalized)];
|
|
265
|
+
if (candidates.some((candidate) => entry.names.includes(candidate))) return { exact: true };
|
|
266
|
+
if (entry.names.some((name) => candidates.some((candidate) => candidate.includes(name)))) return { exact: false };
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const SENSITIVE_COLUMNS = /* @__PURE__ */ new Set([
|
|
270
|
+
"password",
|
|
271
|
+
"password_hash",
|
|
272
|
+
"passwordhash",
|
|
273
|
+
"access_token",
|
|
274
|
+
"accesstoken",
|
|
275
|
+
"api_key",
|
|
276
|
+
"apikey",
|
|
277
|
+
"client_secret",
|
|
278
|
+
"clientsecret",
|
|
279
|
+
"encrypted_password",
|
|
280
|
+
"encryptedpassword",
|
|
281
|
+
"refresh_token",
|
|
282
|
+
"refreshtoken",
|
|
283
|
+
"id_token",
|
|
284
|
+
"idtoken",
|
|
285
|
+
"password_digest",
|
|
286
|
+
"passworddigest",
|
|
287
|
+
"private_key",
|
|
288
|
+
"privatekey",
|
|
289
|
+
"secret",
|
|
290
|
+
"session_token",
|
|
291
|
+
"sessiontoken"
|
|
292
|
+
]);
|
|
293
|
+
/**
|
|
294
|
+
* Does this table carry credentials? Such tables are withheld from suggestions
|
|
295
|
+
* and from bulk apply, so one click can never map an auth table into the CRM.
|
|
296
|
+
* They stay manually selectable — an explicit, informed choice is legitimate.
|
|
297
|
+
*/
|
|
298
|
+
function hasSensitiveColumns(columns) {
|
|
299
|
+
return columns.some(isSensitiveColumn);
|
|
300
|
+
}
|
|
301
|
+
/** Is this one column a credential (a password, token, key or secret)? */
|
|
302
|
+
function isSensitiveColumn(column) {
|
|
303
|
+
return SENSITIVE_COLUMNS.has(column.toLowerCase().replaceAll("-", "_"));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Table names the supported auth libraries create.
|
|
307
|
+
*
|
|
308
|
+
* `hasSensitiveColumns` cannot catch these. Better Auth's `organization` table
|
|
309
|
+
* is `{id, name, slug, logo}` — no credential column anywhere, a real `name`,
|
|
310
|
+
* and "organizations" is in the company vocabulary above. It is, by every
|
|
311
|
+
* signal this module has, an excellent company candidate. On `vue-academy`
|
|
312
|
+
* `clivly init` duly chose it over `campuses`, the actual business table that
|
|
313
|
+
* every student row points at, and the first sync exported rows nothing could
|
|
314
|
+
* receive.
|
|
315
|
+
*
|
|
316
|
+
* Matched on name, deliberately, and this is the inverse of the rule above:
|
|
317
|
+
* withholding a table on a wrong guess is a real loss, so that is decided on
|
|
318
|
+
* columns; *ranking* one below another is cheap to get wrong, so a name match
|
|
319
|
+
* is enough. These are fixed names the plugins create, and an app whose own
|
|
320
|
+
* business table is called `member` still ranks — just after its rivals.
|
|
321
|
+
*/
|
|
322
|
+
const FRAMEWORK_TABLE_NAMES = /* @__PURE__ */ new Set([
|
|
323
|
+
"account",
|
|
324
|
+
"session",
|
|
325
|
+
"user",
|
|
326
|
+
"verification",
|
|
327
|
+
"invitation",
|
|
328
|
+
"member",
|
|
329
|
+
"organization",
|
|
330
|
+
"team",
|
|
331
|
+
"team_member",
|
|
332
|
+
"apikey",
|
|
333
|
+
"api_key",
|
|
334
|
+
"jwks",
|
|
335
|
+
"passkey",
|
|
336
|
+
"rate_limit",
|
|
337
|
+
"ratelimit",
|
|
338
|
+
"two_factor",
|
|
339
|
+
"twofactor",
|
|
340
|
+
"__drizzle_migrations",
|
|
341
|
+
"drizzle_migrations"
|
|
342
|
+
]);
|
|
343
|
+
/**
|
|
344
|
+
* Is this table one your auth library created, rather than one you wrote?
|
|
345
|
+
*
|
|
346
|
+
* Used to rank such tables below the developer's own when both could serve a
|
|
347
|
+
* concept. Never to exclude them: mapping `user` as the contact entity is
|
|
348
|
+
* legitimate for plenty of apps, and it stays selectable.
|
|
349
|
+
*/
|
|
350
|
+
function isFrameworkTable(name) {
|
|
351
|
+
return FRAMEWORK_TABLE_NAMES.has(name.toLowerCase().replaceAll("-", "_"));
|
|
352
|
+
}
|
|
353
|
+
function metaFor(table, column) {
|
|
354
|
+
return table.columnsMeta?.find((c) => c.name === column);
|
|
355
|
+
}
|
|
356
|
+
function hasDefiningColumn(concept, columns) {
|
|
357
|
+
const lower = new Set(columns.map((c) => c.toLowerCase()));
|
|
358
|
+
const required = CONCEPT_FIELDS[concept].filter((f) => f.required);
|
|
359
|
+
return required.length > 0 && required.every((f) => f.candidates.some((c) => lower.has(c)));
|
|
360
|
+
}
|
|
361
|
+
function scoreConcepts(table) {
|
|
362
|
+
const out = [];
|
|
363
|
+
for (const concept of TARGET_CONCEPTS) {
|
|
364
|
+
if (!MATERIALIZING.has(concept)) continue;
|
|
365
|
+
const nameMatch = matchesConcept(table.name, concept);
|
|
366
|
+
const definingColumns = hasDefiningColumn(concept, table.columns);
|
|
367
|
+
if (!(nameMatch || definingColumns)) continue;
|
|
368
|
+
let score = 0;
|
|
369
|
+
const reasons = [];
|
|
370
|
+
if (nameMatch?.exact) {
|
|
371
|
+
score += require_mapping_score.W.nameExact;
|
|
372
|
+
reasons.push(`name matches "${table.name}"`);
|
|
373
|
+
} else if (nameMatch) {
|
|
374
|
+
score += require_mapping_score.W.nameSubstring;
|
|
375
|
+
reasons.push(`name looks like ${concept}`);
|
|
376
|
+
}
|
|
377
|
+
if (definingColumns) {
|
|
378
|
+
score += require_mapping_score.W.definingColumn;
|
|
379
|
+
reasons.push(`has the columns a ${concept} needs`);
|
|
380
|
+
}
|
|
381
|
+
if (table.columnsMeta?.some((c) => c.isPrimaryKey)) {
|
|
382
|
+
score += require_mapping_score.W.hasPrimaryKey;
|
|
383
|
+
reasons.push("has primary key");
|
|
384
|
+
}
|
|
385
|
+
if (table.rowCount !== void 0) {
|
|
386
|
+
if (table.rowCount === 0) {
|
|
387
|
+
score += require_mapping_score.W.emptyTable;
|
|
388
|
+
reasons.push("table is empty");
|
|
389
|
+
} else {
|
|
390
|
+
score += require_mapping_score.W.hasRows;
|
|
391
|
+
reasons.push(`${table.rowCount.toLocaleString("en-US")} rows`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
out.push({
|
|
395
|
+
value: concept,
|
|
396
|
+
score,
|
|
397
|
+
tier: require_mapping_score.tierFor(score, require_mapping_score.CONCEPT_TIERS),
|
|
398
|
+
reasons
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return out.sort((a, b) => b.score - a.score);
|
|
402
|
+
}
|
|
403
|
+
function topConcept(table) {
|
|
404
|
+
const ranked = scoreConcepts(table);
|
|
405
|
+
const best = ranked[0];
|
|
406
|
+
if (!best) return null;
|
|
407
|
+
return {
|
|
408
|
+
best,
|
|
409
|
+
ambiguous: require_mapping_score.isAmbiguous(ranked)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function requiredFieldsFor(concept) {
|
|
413
|
+
if (concept === "custom") return [];
|
|
414
|
+
return CONCEPT_FIELDS[concept].filter((f) => f.required).map((f) => f.field);
|
|
415
|
+
}
|
|
416
|
+
function validateMapping(requiredFields, fieldMap) {
|
|
417
|
+
const missing = requiredFields.filter((field) => !fieldMap[field]);
|
|
418
|
+
return {
|
|
419
|
+
valid: missing.length === 0,
|
|
420
|
+
missing
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
const DISCRIMINATOR_COLUMNS = [
|
|
424
|
+
"role",
|
|
425
|
+
"type",
|
|
426
|
+
"kind",
|
|
427
|
+
"status",
|
|
428
|
+
"state",
|
|
429
|
+
"category",
|
|
430
|
+
"tier"
|
|
431
|
+
];
|
|
432
|
+
function suggestDiscriminatorColumns(columns) {
|
|
433
|
+
const lowerToActual = new Map(columns.map((c) => [c.toLowerCase(), c]));
|
|
434
|
+
const out = [];
|
|
435
|
+
for (const name of DISCRIMINATOR_COLUMNS) {
|
|
436
|
+
const match = lowerToActual.get(name);
|
|
437
|
+
if (match) out.push(match);
|
|
438
|
+
}
|
|
439
|
+
return out;
|
|
440
|
+
}
|
|
441
|
+
const COMPANY_FK_HINTS = [
|
|
442
|
+
"organization_id",
|
|
443
|
+
"organisation_id",
|
|
444
|
+
"org_id",
|
|
445
|
+
"company_id",
|
|
446
|
+
"account_id",
|
|
447
|
+
"team_id"
|
|
448
|
+
];
|
|
449
|
+
function firstMatchingColumn(columns, hints) {
|
|
450
|
+
const lowerToActual = new Map(columns.map((c) => [c.toLowerCase(), c]));
|
|
451
|
+
for (const hint of hints) {
|
|
452
|
+
const match = lowerToActual.get(hint);
|
|
453
|
+
if (match) return match;
|
|
454
|
+
}
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Suggest contact→company relationships. When the source table carries FK
|
|
459
|
+
* metadata (`references`), the target table is a *fact*, not a name guess —
|
|
460
|
+
* that scores highest. Without metadata (v1 hosts) we fall back to the legacy
|
|
461
|
+
* FK-name hints at a lower tier.
|
|
462
|
+
*/
|
|
463
|
+
function scoreRelationships(source, allTables) {
|
|
464
|
+
const companyTables = allTables.filter((t) => t.name !== source.name && topConcept(t)?.best.value === "company");
|
|
465
|
+
if (companyTables.length === 0) return [];
|
|
466
|
+
const companyNames = new Set(companyTables.map((t) => t.name.toLowerCase()));
|
|
467
|
+
const out = [];
|
|
468
|
+
const seenTargets = /* @__PURE__ */ new Set();
|
|
469
|
+
for (const col of source.columnsMeta ?? []) {
|
|
470
|
+
const ref = col.references;
|
|
471
|
+
if (!(ref && companyNames.has(ref.table.toLowerCase()))) continue;
|
|
472
|
+
if (seenTargets.has(ref.table.toLowerCase())) continue;
|
|
473
|
+
seenTargets.add(ref.table.toLowerCase());
|
|
474
|
+
out.push({
|
|
475
|
+
value: {
|
|
476
|
+
name: "company",
|
|
477
|
+
entityTable: ref.table,
|
|
478
|
+
via: {
|
|
479
|
+
fkOn: "contact",
|
|
480
|
+
column: `${source.name}.${col.name}`
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
score: require_mapping_score.W.fkResolved,
|
|
484
|
+
tier: require_mapping_score.tierFor(require_mapping_score.W.fkResolved, require_mapping_score.RELATIONSHIP_TIERS),
|
|
485
|
+
reasons: [`foreign key → ${ref.table}.${ref.column}`]
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
if (source.columnsMeta?.length) return out.sort((a, b) => b.score - a.score);
|
|
489
|
+
const contactFk = firstMatchingColumn(source.columns, COMPANY_FK_HINTS);
|
|
490
|
+
if (contactFk) out.push({
|
|
491
|
+
value: {
|
|
492
|
+
name: "company",
|
|
493
|
+
entityTable: companyTables[0]?.name ?? "",
|
|
494
|
+
via: {
|
|
495
|
+
fkOn: "contact",
|
|
496
|
+
column: `${source.name}.${contactFk}`
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
score: require_mapping_score.W.fkNameHint,
|
|
500
|
+
tier: require_mapping_score.tierFor(require_mapping_score.W.fkNameHint, require_mapping_score.RELATIONSHIP_TIERS),
|
|
501
|
+
reasons: [`column "${contactFk}" looks like a company link`]
|
|
502
|
+
});
|
|
503
|
+
return out.sort((a, b) => b.score - a.score);
|
|
504
|
+
}
|
|
505
|
+
const FIELD_TYPE_EXPECTATION = {
|
|
506
|
+
name: "text",
|
|
507
|
+
email: "text",
|
|
508
|
+
phone: "text",
|
|
509
|
+
domain: "text",
|
|
510
|
+
stage: "text",
|
|
511
|
+
status: "text",
|
|
512
|
+
subject: "text",
|
|
513
|
+
body: "text",
|
|
514
|
+
summary: "text",
|
|
515
|
+
type: "text",
|
|
516
|
+
value: "numeric",
|
|
517
|
+
createdAt: "timestamp"
|
|
518
|
+
};
|
|
519
|
+
function typeFits(field, type) {
|
|
520
|
+
const expectation = FIELD_TYPE_EXPECTATION[field];
|
|
521
|
+
if (!(expectation && type)) return null;
|
|
522
|
+
if (expectation === "text") return require_mapping_score.isTextLike(type);
|
|
523
|
+
if (expectation === "numeric") return require_mapping_score.isNumericLike(type);
|
|
524
|
+
return require_mapping_score.isTimestampLike(type);
|
|
525
|
+
}
|
|
526
|
+
function scoreFieldMap(concept, table) {
|
|
527
|
+
const lowerToActual = new Map(table.columns.map((c) => [c.toLowerCase(), c]));
|
|
528
|
+
const out = [];
|
|
529
|
+
for (const { field, candidates, required } of CONCEPT_FIELDS[concept]) for (const candidate of candidates) {
|
|
530
|
+
const column = lowerToActual.get(candidate);
|
|
531
|
+
if (!column) continue;
|
|
532
|
+
let score = require_mapping_score.W.fieldNameMatch;
|
|
533
|
+
const reasons = [`name matches "${column}"`];
|
|
534
|
+
const meta = metaFor(table, column);
|
|
535
|
+
const fits = typeFits(field, meta?.type);
|
|
536
|
+
if (fits === true) {
|
|
537
|
+
score += require_mapping_score.W.typeCompatible;
|
|
538
|
+
reasons.push(`type ${meta?.type}`);
|
|
539
|
+
} else if (fits === false) {
|
|
540
|
+
score += require_mapping_score.W.typeMismatch;
|
|
541
|
+
reasons.push(`type ${meta?.type} does not fit ${field}`);
|
|
542
|
+
}
|
|
543
|
+
if (required && meta?.nullable === false) {
|
|
544
|
+
score += require_mapping_score.W.requiredNotNull;
|
|
545
|
+
reasons.push("not null");
|
|
546
|
+
}
|
|
547
|
+
out.push({
|
|
548
|
+
value: {
|
|
549
|
+
field,
|
|
550
|
+
column,
|
|
551
|
+
required
|
|
552
|
+
},
|
|
553
|
+
score,
|
|
554
|
+
tier: require_mapping_score.tierFor(score, require_mapping_score.FIELD_TIERS),
|
|
555
|
+
reasons
|
|
556
|
+
});
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
return out;
|
|
560
|
+
}
|
|
561
|
+
function toFieldMap(scored) {
|
|
562
|
+
const map = {};
|
|
563
|
+
for (const { value } of scored) map[value.field] = value.column;
|
|
564
|
+
return map;
|
|
565
|
+
}
|
|
566
|
+
Object.defineProperty(exports, "TARGET_CONCEPTS", {
|
|
567
|
+
enumerable: true,
|
|
568
|
+
get: function() {
|
|
569
|
+
return TARGET_CONCEPTS;
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
Object.defineProperty(exports, "hasDefiningColumn", {
|
|
573
|
+
enumerable: true,
|
|
574
|
+
get: function() {
|
|
575
|
+
return hasDefiningColumn;
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
Object.defineProperty(exports, "hasSensitiveColumns", {
|
|
579
|
+
enumerable: true,
|
|
580
|
+
get: function() {
|
|
581
|
+
return hasSensitiveColumns;
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
Object.defineProperty(exports, "isFrameworkTable", {
|
|
585
|
+
enumerable: true,
|
|
586
|
+
get: function() {
|
|
587
|
+
return isFrameworkTable;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
Object.defineProperty(exports, "isSensitiveColumn", {
|
|
591
|
+
enumerable: true,
|
|
592
|
+
get: function() {
|
|
593
|
+
return isSensitiveColumn;
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
Object.defineProperty(exports, "matchesConcept", {
|
|
597
|
+
enumerable: true,
|
|
598
|
+
get: function() {
|
|
599
|
+
return matchesConcept;
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
Object.defineProperty(exports, "requiredFieldsFor", {
|
|
603
|
+
enumerable: true,
|
|
604
|
+
get: function() {
|
|
605
|
+
return requiredFieldsFor;
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
Object.defineProperty(exports, "scoreConcepts", {
|
|
609
|
+
enumerable: true,
|
|
610
|
+
get: function() {
|
|
611
|
+
return scoreConcepts;
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
Object.defineProperty(exports, "scoreFieldMap", {
|
|
615
|
+
enumerable: true,
|
|
616
|
+
get: function() {
|
|
617
|
+
return scoreFieldMap;
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
Object.defineProperty(exports, "scoreRelationships", {
|
|
621
|
+
enumerable: true,
|
|
622
|
+
get: function() {
|
|
623
|
+
return scoreRelationships;
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
Object.defineProperty(exports, "suggestCursorField", {
|
|
627
|
+
enumerable: true,
|
|
628
|
+
get: function() {
|
|
629
|
+
return suggestCursorField;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
Object.defineProperty(exports, "suggestDiscriminatorColumns", {
|
|
633
|
+
enumerable: true,
|
|
634
|
+
get: function() {
|
|
635
|
+
return suggestDiscriminatorColumns;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
Object.defineProperty(exports, "toFieldMap", {
|
|
639
|
+
enumerable: true,
|
|
640
|
+
get: function() {
|
|
641
|
+
return toFieldMap;
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
Object.defineProperty(exports, "topConcept", {
|
|
645
|
+
enumerable: true,
|
|
646
|
+
get: function() {
|
|
647
|
+
return topConcept;
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
Object.defineProperty(exports, "validateMapping", {
|
|
651
|
+
enumerable: true,
|
|
652
|
+
get: function() {
|
|
653
|
+
return validateMapping;
|
|
654
|
+
}
|
|
655
|
+
});
|