clivly 0.7.4 → 0.9.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.
- package/core-drizzle.cjs +3 -1
- package/core-drizzle.d.cts +3 -2
- package/core-drizzle.d.mts +3 -2
- package/core-drizzle.mjs +2 -2
- package/core-entity-config.cjs +1 -1
- package/core-entity-config.d.cts +2 -2
- package/core-entity-config.d.mts +2 -2
- package/core-entity-config.mjs +1 -1
- package/core-entity-heuristics.d.cts +3 -2
- package/core-entity-heuristics.d.mts +3 -2
- package/core-mapping-form.d.cts +1 -1
- package/core-mapping-form.d.mts +1 -1
- package/core-mappings-config.cjs +1 -1
- package/core-mappings-config.d.cts +1 -1
- package/core-mappings-config.d.mts +1 -1
- package/core-mappings-config.mjs +1 -1
- package/core-sync-engine.cjs +1 -1
- package/core-sync-engine.d.cts +1 -1
- package/core-sync-engine.d.mts +1 -1
- package/core-sync-engine.mjs +1 -1
- package/core-view-compiler.cjs +1 -1
- package/core-view-compiler.d.cts +1 -1
- package/core-view-compiler.d.mts +1 -1
- package/core-view-compiler.mjs +1 -1
- package/core.cjs +21 -5
- package/core.d.cts +7 -6
- package/core.d.mts +7 -6
- package/core.mjs +7 -6
- package/drizzle-3kvhkwO7.mjs +110 -0
- package/drizzle-BhN5M9zt.d.cts +41 -0
- package/drizzle-bfjVzYR6.cjs +127 -0
- package/drizzle-kBULBAOa.d.mts +41 -0
- package/drizzle.cjs +5 -37
- package/drizzle.d.cts +3 -3
- package/drizzle.d.mts +3 -3
- package/drizzle.mjs +5 -38
- package/{entity-config-DoUCXtq5.d.cts → entity-config-C4Yf_fPj.d.cts} +120 -1
- package/{entity-config-DoUCXtq5.d.mts → entity-config-C4Yf_fPj.d.mts} +120 -1
- package/entity-config-CsLl-ftC.cjs +727 -0
- package/entity-config-D3LmzgLb.mjs +612 -0
- package/index.cjs +28 -2
- package/index.d.cts +6 -0
- package/index.d.mts +6 -0
- package/index.mjs +28 -2
- package/internal-B8ydhsKd.d.cts +73 -0
- package/internal-BARjyN4n.cjs +97 -0
- package/internal-DMySVbM0.mjs +68 -0
- package/internal-MBkNo3bw.d.mts +73 -0
- package/internal-drizzle.cjs +3 -1
- package/internal-drizzle.d.cts +2 -2
- package/internal-drizzle.d.mts +2 -2
- package/internal-drizzle.mjs +2 -2
- package/internal-entity-config.cjs +1 -1
- package/internal-entity-config.d.cts +2 -2
- package/internal-entity-config.d.mts +2 -2
- package/internal-entity-config.mjs +1 -1
- package/internal-entity-heuristics.cjs +1 -1
- package/internal-entity-heuristics.d.cts +2 -12
- package/internal-entity-heuristics.d.mts +2 -12
- package/internal-entity-heuristics.mjs +1 -1
- package/internal-mapping-form.d.cts +1 -1
- package/internal-mapping-form.d.mts +1 -1
- 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 -1
- 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 -1
- 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 -1
- package/internal.cjs +21 -4
- package/internal.d.cts +7 -6
- package/internal.d.mts +7 -6
- package/internal.mjs +7 -5
- package/{mapping-form-D93lhHEc.d.mts → mapping-form-43bwOTat.d.cts} +1 -1
- package/{mapping-form-lfyEE7EJ.d.cts → mapping-form-DUvWUYCo.d.mts} +1 -1
- package/{mappings-config-BsRADNRv.cjs → mappings-config-BSSwdHiq.cjs} +32 -6
- package/mappings-config-BpcR8bBo.d.mts +167 -0
- package/{mappings-config-Dbgxx3Nv.mjs → mappings-config-bJQT_gSa.mjs} +32 -6
- package/mappings-config-xsLMn3I-.d.cts +167 -0
- package/{namespace-probe-B4WE45TH.d.mts → namespace-probe-BSH_p9TK.d.cts} +10 -1
- package/{namespace-probe-DRzOtaRT.d.cts → namespace-probe-Dsp5uNkS.d.mts} +10 -1
- package/package.json +1 -1
- package/{entity-config-va2bkH5o.mjs → projection-C5244vGa.cjs} +130 -309
- package/{entity-config-D87rV-tE.cjs → projection-D7xmQP4S.mjs} +60 -381
- package/sdk.cjs +1 -1
- package/sdk.d.cts +2 -2
- package/sdk.d.mts +2 -2
- package/sdk.mjs +1 -1
- package/{sync-engine-Do5ru3WF.mjs → sync-engine-Bg6-SznL.mjs} +9 -2
- package/{sync-engine-CzEbpQGv.cjs → sync-engine-DEJvKw6E.cjs} +9 -2
- package/{sync-engine-DGk_AeHJ.d.mts → sync-engine-GNqRB8eS.d.cts} +2 -2
- package/{sync-engine-B7QIbXro.d.cts → sync-engine-ZsusW-q_.d.mts} +2 -2
- package/{view-compiler-BWz0sGdm.d.cts → view-compiler-Cin0neDO.d.mts} +1 -1
- package/{view-compiler-ChWr_Lml.mjs → view-compiler-DlTpOfZi.mjs} +81 -12
- package/{view-compiler-BIwvm-o2.cjs → view-compiler-DplczSjF.cjs} +81 -12
- package/{view-compiler-Bn_EJJMO.d.mts → view-compiler-Ll9cbIJz.d.cts} +1 -1
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
- package/drizzle-B89tLo4T.mjs +0 -31
- package/drizzle-CFOr9dU9.d.mts +0 -20
- package/drizzle-DiReZf6d.cjs +0 -36
- package/drizzle-DmeKSqeF.d.cts +0 -20
- package/mappings-config-DsUa7-1w.d.mts +0 -41
- package/mappings-config-XmzB4dag.d.cts +0 -41
|
@@ -4203,398 +4203,77 @@ function superRefine(fn, params) {
|
|
|
4203
4203
|
return /* @__PURE__ */ _superRefine(fn, params);
|
|
4204
4204
|
}
|
|
4205
4205
|
//#endregion
|
|
4206
|
-
//#region ../core/src/
|
|
4206
|
+
//#region ../core/src/projection.ts
|
|
4207
4207
|
/**
|
|
4208
|
-
*
|
|
4209
|
-
*
|
|
4208
|
+
* Projection-backed custom mappings — one custom object derived from a base
|
|
4209
|
+
* table plus explicit joins.
|
|
4210
4210
|
*
|
|
4211
|
-
* A
|
|
4212
|
-
*
|
|
4213
|
-
*
|
|
4214
|
-
*
|
|
4215
|
-
*
|
|
4211
|
+
* A projection is deliberately narrow: equality joins only, direct column
|
|
4212
|
+
* bindings only, no expressions and no aggregation. Everything a user can
|
|
4213
|
+
* express here compiles to a single read-only view whose `id` column is
|
|
4214
|
+
* provably unique per row, which is what lets the sync engine consume it
|
|
4215
|
+
* unchanged.
|
|
4216
4216
|
*
|
|
4217
|
-
*
|
|
4218
|
-
*
|
|
4219
|
-
*
|
|
4220
|
-
* the view compiler (Phase 2) and sync engine (Phase 3) consume this contract.
|
|
4217
|
+
* Refs address tables symbolically: `"base"` for the base table, or a join's
|
|
4218
|
+
* `key`. Raw table names are never accepted in a ref, so a projection can
|
|
4219
|
+
* never reach a table it did not declare.
|
|
4221
4220
|
*/
|
|
4222
|
-
/**
|
|
4223
|
-
const
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
const
|
|
4244
|
-
contact: [
|
|
4245
|
-
"name",
|
|
4246
|
-
"email",
|
|
4247
|
-
"title",
|
|
4248
|
-
"status"
|
|
4249
|
-
],
|
|
4250
|
-
company: [
|
|
4251
|
-
"name",
|
|
4252
|
-
"domain",
|
|
4253
|
-
"industry",
|
|
4254
|
-
"size"
|
|
4255
|
-
],
|
|
4256
|
-
deal: [
|
|
4257
|
-
"name",
|
|
4258
|
-
"value",
|
|
4259
|
-
"stage"
|
|
4260
|
-
]
|
|
4261
|
-
};
|
|
4262
|
-
/**
|
|
4263
|
-
* The concepts the mapping→sync pipeline can actually materialize into `crm_*`
|
|
4264
|
-
* tables. These are exactly the CANONICAL_FIELDS keys — the Drizzle sync store's
|
|
4265
|
-
* `persist()` throws for any other concept, so offering one (in the mapping
|
|
4266
|
-
* editor, in suggestions, or via the upsert API) is a broken affordance.
|
|
4267
|
-
*
|
|
4268
|
-
* The broader CRM_CONCEPTS set still validates structurally, so previously
|
|
4269
|
-
* stored rows for not-yet-materialized concepts keep rendering. When a concept
|
|
4270
|
-
* gains a sync-store path, add its canonical fields above and it joins this set
|
|
4271
|
-
* automatically (guarded by the MATERIALIZING_CONCEPTS drift test).
|
|
4272
|
-
*/
|
|
4273
|
-
const MATERIALIZING_CONCEPTS = [
|
|
4274
|
-
"contact",
|
|
4275
|
-
"company",
|
|
4276
|
-
"deal"
|
|
4277
|
-
];
|
|
4278
|
-
/**
|
|
4279
|
-
* The org-defined custom-object target. Deliberately NOT a member of
|
|
4280
|
-
* CRM_CONCEPTS / CANONICAL_FIELDS / MATERIALIZING_CONCEPTS — a custom object has
|
|
4281
|
-
* no fixed canonical columns; its mapping's fieldMap keys ARE its properties.
|
|
4282
|
-
* Handled as an explicit branch wherever concepts are switched on, so the
|
|
4283
|
-
* canonical-concept invariants (and their drift test) stay intact.
|
|
4284
|
-
*/
|
|
4285
|
-
const CUSTOM_CONCEPT = "custom";
|
|
4286
|
-
/**
|
|
4287
|
-
* Operator forms for a single column predicate. All predicates on an entity are
|
|
4288
|
-
* AND-ed together. `$raw` (see FilterExpr) is the escape hatch for anything the
|
|
4289
|
-
* operators can't express.
|
|
4290
|
-
*/
|
|
4291
|
-
const filterOperatorsSchema = union([
|
|
4292
|
-
strictObject({ eq: union([
|
|
4293
|
-
string(),
|
|
4294
|
-
number(),
|
|
4295
|
-
boolean()
|
|
4296
|
-
]) }),
|
|
4297
|
-
strictObject({ ne: union([
|
|
4298
|
-
string(),
|
|
4299
|
-
number(),
|
|
4300
|
-
boolean()
|
|
4301
|
-
]) }),
|
|
4302
|
-
strictObject({ in: array(union([
|
|
4303
|
-
string(),
|
|
4304
|
-
number(),
|
|
4305
|
-
boolean()
|
|
4306
|
-
])).min(1) }),
|
|
4307
|
-
strictObject({ notIn: array(union([
|
|
4308
|
-
string(),
|
|
4309
|
-
number(),
|
|
4310
|
-
boolean()
|
|
4311
|
-
])).min(1) }),
|
|
4312
|
-
strictObject({ isNull: literal(true) }),
|
|
4313
|
-
strictObject({ isNotNull: literal(true) })
|
|
4314
|
-
]);
|
|
4315
|
-
const filterValueSchema = union([
|
|
4316
|
-
string(),
|
|
4317
|
-
number(),
|
|
4318
|
-
boolean(),
|
|
4319
|
-
filterOperatorsSchema
|
|
4320
|
-
]);
|
|
4321
|
-
/** `$raw` is a reserved key; a column literally named `$raw` is not addressable. */
|
|
4322
|
-
const filterSchema = union([strictObject({ $raw: string().min(1) }), record(string(), filterValueSchema)]);
|
|
4323
|
-
/**
|
|
4324
|
-
* How the link between two entities is expressed in the host schema:
|
|
4325
|
-
* - `fkOn: "company"` — FK lives on the company table (e.g. organizations.owner_id)
|
|
4326
|
-
* - `fkOn: "contact"` — FK lives on the contact table (e.g. users.organization_id)
|
|
4327
|
-
* - `through` — a join table sits between them (many-to-many, role often here)
|
|
4328
|
-
* - `$raw` — opaque SQL join fragment (escape hatch; not schema-validated)
|
|
4329
|
-
*
|
|
4330
|
-
* `column` and the join-table keys are `table.column` or bare `column` strings.
|
|
4331
|
-
*/
|
|
4332
|
-
const relationshipViaSchema = union([
|
|
4221
|
+
/** The reserved ref name for the projection's base table. */
|
|
4222
|
+
const BASE_REF = "base";
|
|
4223
|
+
/** Entity keys become view names (`crm_src_<entityKey>`), so keep them slugs. */
|
|
4224
|
+
const PROJECTION_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
4225
|
+
const projectionRefSchema = strictObject({
|
|
4226
|
+
table: string().min(1),
|
|
4227
|
+
column: string().min(1)
|
|
4228
|
+
});
|
|
4229
|
+
const projectionJoinConditionSchema = strictObject({
|
|
4230
|
+
left: projectionRefSchema,
|
|
4231
|
+
op: literal("eq"),
|
|
4232
|
+
right: projectionRefSchema
|
|
4233
|
+
});
|
|
4234
|
+
const projectionJoinSchema = strictObject({
|
|
4235
|
+
/** SQL alias and ref target. Unique within the projection. */
|
|
4236
|
+
key: string().regex(PROJECTION_KEY_PATTERN),
|
|
4237
|
+
table: string().min(1),
|
|
4238
|
+
type: _enum(["inner", "left"]),
|
|
4239
|
+
on: array(projectionJoinConditionSchema).min(1)
|
|
4240
|
+
});
|
|
4241
|
+
const projectionFieldBindingSchema = strictObject({ from: projectionRefSchema });
|
|
4242
|
+
const projectionIdentitySchema = union([
|
|
4333
4243
|
strictObject({
|
|
4334
|
-
|
|
4335
|
-
column
|
|
4244
|
+
kind: literal("base_pk"),
|
|
4245
|
+
/** Defaults to the discovered single-column PK of the base table. */
|
|
4246
|
+
column: string().min(1).optional()
|
|
4336
4247
|
}),
|
|
4337
4248
|
strictObject({
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
foreignKey: string().min(1)
|
|
4249
|
+
kind: literal("column"),
|
|
4250
|
+
from: projectionRefSchema
|
|
4341
4251
|
}),
|
|
4342
|
-
strictObject({
|
|
4252
|
+
strictObject({
|
|
4253
|
+
kind: literal("composite"),
|
|
4254
|
+
parts: array(projectionRefSchema).min(2)
|
|
4255
|
+
})
|
|
4343
4256
|
]);
|
|
4344
|
-
const
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4257
|
+
const projectionSchema = strictObject({
|
|
4258
|
+
version: literal(1),
|
|
4259
|
+
kind: literal("projection"),
|
|
4260
|
+
entityKey: string().regex(PROJECTION_KEY_PATTERN),
|
|
4261
|
+
baseTable: string().min(1),
|
|
4262
|
+
joins: array(projectionJoinSchema),
|
|
4263
|
+
fieldBindings: record(string(), projectionFieldBindingSchema).refine((b) => Object.keys(b).length > 0, { message: "at least one field must be bound" }),
|
|
4264
|
+
identity: projectionIdentitySchema
|
|
4348
4265
|
});
|
|
4349
|
-
/** A named map of relationships, as stored on an entity / in the mappings row. */
|
|
4350
|
-
const relationshipsSchema = record(string(), relationshipSchema);
|
|
4351
|
-
const entitySchema = strictObject({
|
|
4352
|
-
/** Which CRM concept this entity maps onto — a canonical concept or "custom". */
|
|
4353
|
-
concept: union([_enum(CRM_CONCEPTS), literal(CUSTOM_CONCEPT)]),
|
|
4354
|
-
/** Host table (or view) this entity is derived from. */
|
|
4355
|
-
source: string().min(1),
|
|
4356
|
-
/**
|
|
4357
|
-
* Distinguishes multiple entities backed by the same table (e.g. "primary"
|
|
4358
|
-
* for owners, "secondary" for members). Free text; defaults to "primary".
|
|
4359
|
-
*/
|
|
4360
|
-
role: string().min(1).optional(),
|
|
4361
|
-
/** Predicate that narrows `source` into this entity's rows. Omit = whole table. */
|
|
4362
|
-
filter: filterSchema.optional(),
|
|
4363
|
-
/** clivlyField → sourceColumn. At least one field is required. */
|
|
4364
|
-
fields: record(string(), string()).refine((f) => Object.keys(f).length > 0, { message: "at least one field must be mapped" }),
|
|
4365
|
-
/**
|
|
4366
|
-
* Host-owned identity fields. Sync overwrites them; the CRM UI cannot edit
|
|
4367
|
-
* them. Must be a subset of `fields` keys.
|
|
4368
|
-
*/
|
|
4369
|
-
readOnly: array(string()).optional(),
|
|
4370
|
-
/** Named relationships to other entities in this config. */
|
|
4371
|
-
relationships: record(string(), relationshipSchema).optional(),
|
|
4372
|
-
/**
|
|
4373
|
-
* For a "custom" entity, the crm_object_types row this materializes into.
|
|
4374
|
-
* Required for custom (enforced at the API layer), unused for standard concepts.
|
|
4375
|
-
*/
|
|
4376
|
-
targetObjectTypeId: string().min(1).optional()
|
|
4377
|
-
});
|
|
4378
|
-
const entitiesConfigSchema = strictObject({ entities: record(string(), entitySchema).refine((e) => Object.keys(e).length > 0, { message: "at least one entity must be defined" }) });
|
|
4379
|
-
/** Thrown by `defineClivlyConfig({ strict: true })` on non-canonical field keys. */
|
|
4380
|
-
var ClivlyConfigError = class extends Error {
|
|
4381
|
-
issues;
|
|
4382
|
-
constructor(issues) {
|
|
4383
|
-
super(`Clivly config has ${issues.length} non-canonical field mapping(s) that would write empty values at sync time:\n${issues.map((issue) => ` - ${issue.path}: ${issue.message}`).join("\n")}`);
|
|
4384
|
-
this.name = "ClivlyConfigError";
|
|
4385
|
-
this.issues = issues;
|
|
4386
|
-
}
|
|
4387
|
-
};
|
|
4388
|
-
function nonCanonicalFieldKeys(entity) {
|
|
4389
|
-
const canonical = CANONICAL_FIELDS[entity.concept];
|
|
4390
|
-
if (!canonical) return [];
|
|
4391
|
-
return Object.keys(entity.fields).filter((key) => !canonical.includes(key));
|
|
4392
|
-
}
|
|
4393
|
-
function nonCanonicalMessage(entity, field) {
|
|
4394
|
-
const canonical = CANONICAL_FIELDS[entity.concept] ?? [];
|
|
4395
|
-
return `"${field}" is not a canonical ${entity.concept} field (expected one of: ${canonical.join(", ")})`;
|
|
4396
|
-
}
|
|
4397
|
-
function canonicalFieldIssues(config) {
|
|
4398
|
-
const issues = [];
|
|
4399
|
-
for (const [key, entity] of Object.entries(config.entities)) for (const field of nonCanonicalFieldKeys(entity)) issues.push({
|
|
4400
|
-
path: `entities.${key}.fields.${field}`,
|
|
4401
|
-
message: nonCanonicalMessage(entity, field)
|
|
4402
|
-
});
|
|
4403
|
-
return issues;
|
|
4404
|
-
}
|
|
4405
|
-
function defaultWarn(message) {
|
|
4406
|
-
console.warn(message);
|
|
4407
|
-
}
|
|
4408
|
-
/**
|
|
4409
|
-
* Structural helper for `clivly.config.ts`. Gives full type inference on the
|
|
4410
|
-
* literal you pass and eagerly parses it, so shape errors surface at config
|
|
4411
|
-
* load rather than at sync time.
|
|
4412
|
-
*
|
|
4413
|
-
* It also catches the silent-data-loss footgun: a non-canonical field key for a
|
|
4414
|
-
* materialised concept (e.g. `fullName` instead of `name` on a `contact`) has no
|
|
4415
|
-
* destination column, so the store would write an empty value. By default these
|
|
4416
|
-
* are reported via `onWarn` (a `console.warn`); pass `{ strict: true }` to throw
|
|
4417
|
-
* a `ClivlyConfigError` instead. Does NOT validate against the host schema — that
|
|
4418
|
-
* needs the discovered schema; see `validateEntitiesConfig`.
|
|
4419
|
-
*/
|
|
4420
|
-
function defineClivlyConfig(config, options) {
|
|
4421
|
-
const parsed = entitiesConfigSchema.parse(config);
|
|
4422
|
-
const issues = canonicalFieldIssues(parsed);
|
|
4423
|
-
if (issues.length > 0) {
|
|
4424
|
-
if (options?.strict) throw new ClivlyConfigError(issues);
|
|
4425
|
-
const warn = options?.onWarn ?? defaultWarn;
|
|
4426
|
-
for (const issue of issues) warn(`⚠ Clivly config: ${issue.message} (${issue.path}) — this field would write an empty value at sync time. Pass { strict: true } to make this throw.`);
|
|
4427
|
-
}
|
|
4428
|
-
return parsed;
|
|
4429
|
-
}
|
|
4430
|
-
/** Split a `table.column` / bare `column` ref into its parts. */
|
|
4431
|
-
function parseColumnRef(ref) {
|
|
4432
|
-
const dot = ref.indexOf(".");
|
|
4433
|
-
if (dot === -1) return { column: ref };
|
|
4434
|
-
return {
|
|
4435
|
-
table: ref.slice(0, dot),
|
|
4436
|
-
column: ref.slice(dot + 1)
|
|
4437
|
-
};
|
|
4438
|
-
}
|
|
4439
|
-
/** Shared lookup + error-collection state threaded through the validators. */
|
|
4440
|
-
var SchemaValidator = class {
|
|
4441
|
-
errors = [];
|
|
4442
|
-
columnsByTable = /* @__PURE__ */ new Map();
|
|
4443
|
-
constructor(schema) {
|
|
4444
|
-
for (const table of schema) this.columnsByTable.set(table.name, new Set(table.columns));
|
|
4445
|
-
}
|
|
4446
|
-
tableExists(name) {
|
|
4447
|
-
return this.columnsByTable.has(name);
|
|
4448
|
-
}
|
|
4449
|
-
columnExists(table, column) {
|
|
4450
|
-
return this.columnsByTable.get(table)?.has(column) ?? false;
|
|
4451
|
-
}
|
|
4452
|
-
report(path, message) {
|
|
4453
|
-
this.errors.push({
|
|
4454
|
-
path,
|
|
4455
|
-
message
|
|
4456
|
-
});
|
|
4457
|
-
}
|
|
4458
|
-
/** Report if `column` is absent from `table`. Returns whether it existed. */
|
|
4459
|
-
requireColumn(path, table, column) {
|
|
4460
|
-
if (this.columnExists(table, column)) return true;
|
|
4461
|
-
this.report(path, `column "${column}" does not exist on "${table}"`);
|
|
4462
|
-
return false;
|
|
4463
|
-
}
|
|
4464
|
-
};
|
|
4465
|
-
function validateFields(v, base, entity) {
|
|
4466
|
-
for (const [field, column] of Object.entries(entity.fields)) v.requireColumn(`${base}.fields.${field}`, entity.source, column);
|
|
4467
|
-
for (const field of nonCanonicalFieldKeys(entity)) v.report(`${base}.fields.${field}`, nonCanonicalMessage(entity, field));
|
|
4468
|
-
}
|
|
4469
|
-
function validateReadOnly(v, base, entity) {
|
|
4470
|
-
for (const field of entity.readOnly ?? []) if (!(field in entity.fields)) v.report(`${base}.readOnly`, `"${field}" is not one of this entity's fields`);
|
|
4471
|
-
}
|
|
4472
|
-
function validateFilter(v, base, entity) {
|
|
4473
|
-
if (!entity.filter || "$raw" in entity.filter) return;
|
|
4474
|
-
for (const column of Object.keys(entity.filter)) v.requireColumn(`${base}.filter.${column}`, entity.source, column);
|
|
4475
|
-
}
|
|
4476
|
-
function validateFkVia(v, relBase, via, entity, related) {
|
|
4477
|
-
const { table, column } = parseColumnRef(via.column);
|
|
4478
|
-
const fkTable = table ?? (via.fkOn === "contact" ? entity.source : related?.source);
|
|
4479
|
-
const path = `${relBase}.via.column`;
|
|
4480
|
-
if (!fkTable) {
|
|
4481
|
-
v.report(path, `cannot resolve table for FK column "${via.column}"`);
|
|
4482
|
-
return;
|
|
4483
|
-
}
|
|
4484
|
-
if (!v.tableExists(fkTable)) {
|
|
4485
|
-
v.report(path, `table "${fkTable}" is not in the discovered schema`);
|
|
4486
|
-
return;
|
|
4487
|
-
}
|
|
4488
|
-
v.requireColumn(path, fkTable, column);
|
|
4489
|
-
}
|
|
4490
|
-
function validateThroughVia(v, relBase, via) {
|
|
4491
|
-
if (!v.tableExists(via.through)) {
|
|
4492
|
-
v.report(`${relBase}.via.through`, `join table "${via.through}" is not in the discovered schema`);
|
|
4493
|
-
return;
|
|
4494
|
-
}
|
|
4495
|
-
v.requireColumn(`${relBase}.via.localKey`, via.through, via.localKey);
|
|
4496
|
-
v.requireColumn(`${relBase}.via.foreignKey`, via.through, via.foreignKey);
|
|
4497
|
-
}
|
|
4498
|
-
function validateRelationship(v, base, config, entity, relName, rel) {
|
|
4499
|
-
const relBase = `${base}.relationships.${relName}`;
|
|
4500
|
-
const related = config.entities[rel.entity];
|
|
4501
|
-
if (!related) v.report(`${relBase}.entity`, `"${rel.entity}" is not a defined entity`);
|
|
4502
|
-
const { via } = rel;
|
|
4503
|
-
if ("fkOn" in via) validateFkVia(v, relBase, via, entity, related);
|
|
4504
|
-
else if ("through" in via) validateThroughVia(v, relBase, via);
|
|
4505
|
-
}
|
|
4506
|
-
function validateEntity(v, config, key, entity) {
|
|
4507
|
-
const base = `entities.${key}`;
|
|
4508
|
-
if (!v.tableExists(entity.source)) {
|
|
4509
|
-
v.report(`${base}.source`, `table "${entity.source}" is not in the discovered schema`);
|
|
4510
|
-
return;
|
|
4511
|
-
}
|
|
4512
|
-
validateFields(v, base, entity);
|
|
4513
|
-
validateReadOnly(v, base, entity);
|
|
4514
|
-
validateFilter(v, base, entity);
|
|
4515
|
-
for (const [relName, rel] of Object.entries(entity.relationships ?? {})) validateRelationship(v, base, config, entity, relName, rel);
|
|
4516
|
-
}
|
|
4517
4266
|
/**
|
|
4518
|
-
*
|
|
4519
|
-
*
|
|
4520
|
-
* columns exist, and relationships point at real entities/tables/columns.
|
|
4521
|
-
*
|
|
4522
|
-
* `$raw` filters and `$raw` relationship joins are opaque and skipped. Returns
|
|
4523
|
-
* every error found (not just the first) so a mapping UI or CLI can show them
|
|
4524
|
-
* all at once.
|
|
4267
|
+
* Every column ref an identity depends on. `basePkColumn` is the base table's
|
|
4268
|
+
* discovered PK, used only when a `base_pk` identity omits an explicit column.
|
|
4525
4269
|
*/
|
|
4526
|
-
function
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4270
|
+
function identityRefs(identity, basePkColumn) {
|
|
4271
|
+
if (identity.kind === "base_pk") return [{
|
|
4272
|
+
table: BASE_REF,
|
|
4273
|
+
column: identity.column ?? basePkColumn
|
|
4274
|
+
}];
|
|
4275
|
+
if (identity.kind === "column") return [identity.from];
|
|
4276
|
+
return identity.parts;
|
|
4533
4277
|
}
|
|
4534
4278
|
//#endregion
|
|
4535
|
-
|
|
4536
|
-
enumerable: true,
|
|
4537
|
-
get: function() {
|
|
4538
|
-
return CANONICAL_FIELDS;
|
|
4539
|
-
}
|
|
4540
|
-
});
|
|
4541
|
-
Object.defineProperty(exports, "CRM_CONCEPTS", {
|
|
4542
|
-
enumerable: true,
|
|
4543
|
-
get: function() {
|
|
4544
|
-
return CRM_CONCEPTS;
|
|
4545
|
-
}
|
|
4546
|
-
});
|
|
4547
|
-
Object.defineProperty(exports, "CUSTOM_CONCEPT", {
|
|
4548
|
-
enumerable: true,
|
|
4549
|
-
get: function() {
|
|
4550
|
-
return CUSTOM_CONCEPT;
|
|
4551
|
-
}
|
|
4552
|
-
});
|
|
4553
|
-
Object.defineProperty(exports, "ClivlyConfigError", {
|
|
4554
|
-
enumerable: true,
|
|
4555
|
-
get: function() {
|
|
4556
|
-
return ClivlyConfigError;
|
|
4557
|
-
}
|
|
4558
|
-
});
|
|
4559
|
-
Object.defineProperty(exports, "MATERIALIZING_CONCEPTS", {
|
|
4560
|
-
enumerable: true,
|
|
4561
|
-
get: function() {
|
|
4562
|
-
return MATERIALIZING_CONCEPTS;
|
|
4563
|
-
}
|
|
4564
|
-
});
|
|
4565
|
-
Object.defineProperty(exports, "defineClivlyConfig", {
|
|
4566
|
-
enumerable: true,
|
|
4567
|
-
get: function() {
|
|
4568
|
-
return defineClivlyConfig;
|
|
4569
|
-
}
|
|
4570
|
-
});
|
|
4571
|
-
Object.defineProperty(exports, "entitiesConfigSchema", {
|
|
4572
|
-
enumerable: true,
|
|
4573
|
-
get: function() {
|
|
4574
|
-
return entitiesConfigSchema;
|
|
4575
|
-
}
|
|
4576
|
-
});
|
|
4577
|
-
Object.defineProperty(exports, "filterSchema", {
|
|
4578
|
-
enumerable: true,
|
|
4579
|
-
get: function() {
|
|
4580
|
-
return filterSchema;
|
|
4581
|
-
}
|
|
4582
|
-
});
|
|
4583
|
-
Object.defineProperty(exports, "relationshipSchema", {
|
|
4584
|
-
enumerable: true,
|
|
4585
|
-
get: function() {
|
|
4586
|
-
return relationshipSchema;
|
|
4587
|
-
}
|
|
4588
|
-
});
|
|
4589
|
-
Object.defineProperty(exports, "relationshipsSchema", {
|
|
4590
|
-
enumerable: true,
|
|
4591
|
-
get: function() {
|
|
4592
|
-
return relationshipsSchema;
|
|
4593
|
-
}
|
|
4594
|
-
});
|
|
4595
|
-
Object.defineProperty(exports, "validateEntitiesConfig", {
|
|
4596
|
-
enumerable: true,
|
|
4597
|
-
get: function() {
|
|
4598
|
-
return validateEntitiesConfig;
|
|
4599
|
-
}
|
|
4600
|
-
});
|
|
4279
|
+
export { _enum as a, literal as c, strictObject as d, string as f, projectionSchema as i, number as l, PROJECTION_KEY_PATTERN as n, array as o, union as p, identityRefs as r, boolean as s, BASE_REF as t, record as u };
|
package/sdk.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_entity_config = require("./entity-config-
|
|
2
|
+
const require_entity_config = require("./entity-config-CsLl-ftC.cjs");
|
|
3
3
|
const require_sdk = require("./sdk-Bj-ZDf4u.cjs");
|
|
4
4
|
exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
|
|
5
5
|
exports.ClivlyError = require_sdk.ClivlyError;
|
package/sdk.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClivlyEntitiesConfig,
|
|
2
|
-
import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-
|
|
1
|
+
import { a as ClivlyEntitiesConfig, y as defineClivlyConfig } from "./entity-config-C4Yf_fPj.cjs";
|
|
2
|
+
import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-BSH_p9TK.cjs";
|
|
3
3
|
//#region ../sdk/src/chat-session.d.ts
|
|
4
4
|
declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
|
|
5
5
|
//#endregion
|
package/sdk.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClivlyEntitiesConfig,
|
|
2
|
-
import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-
|
|
1
|
+
import { a as ClivlyEntitiesConfig, y as defineClivlyConfig } from "./entity-config-C4Yf_fPj.mjs";
|
|
2
|
+
import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-Dsp5uNkS.mjs";
|
|
3
3
|
//#region ../sdk/src/chat-session.d.ts
|
|
4
4
|
declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
|
|
5
5
|
//#endregion
|
package/sdk.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { o as defineClivlyConfig } from "./entity-config-
|
|
1
|
+
import { o as defineClivlyConfig } from "./entity-config-D3LmzgLb.mjs";
|
|
2
2
|
import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, t as createClivlySDK } from "./sdk-BvRD2jAp.mjs";
|
|
3
3
|
export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, defineClivlyConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as compileEntityViews } from "./view-compiler-
|
|
1
|
+
import { r as compileEntityViews } from "./view-compiler-DlTpOfZi.mjs";
|
|
2
2
|
//#region ../core/src/sync-engine.ts
|
|
3
3
|
/**
|
|
4
4
|
* Diff a view's rows against the current mirror population for one entity.
|
|
@@ -170,10 +170,17 @@ function isEmptyValue(value) {
|
|
|
170
170
|
*/
|
|
171
171
|
function computeSampleWarnings(rows, requiredFields, sourceTable) {
|
|
172
172
|
if (rows.length === 0) return [{ message: `no rows found in ${sourceTable}` }];
|
|
173
|
+
const seenRefs = /* @__PURE__ */ new Set();
|
|
174
|
+
const duplicateRefs = /* @__PURE__ */ new Set();
|
|
175
|
+
for (const row of rows) {
|
|
176
|
+
if (seenRefs.has(row.sourceRef)) duplicateRefs.add(row.sourceRef);
|
|
177
|
+
seenRefs.add(row.sourceRef);
|
|
178
|
+
}
|
|
179
|
+
const identityWarnings = duplicateRefs.size > 0 ? [{ message: `duplicate id in ${duplicateRefs.size} of ${rows.length} sampled rows — identity is not unique, so sync would collapse these into one record` }] : [];
|
|
173
180
|
const required = new Set(requiredFields);
|
|
174
181
|
const fields = new Set(requiredFields);
|
|
175
182
|
for (const row of rows) for (const key of Object.keys(row.fields)) fields.add(key);
|
|
176
|
-
const warnings = [];
|
|
183
|
+
const warnings = [...identityWarnings];
|
|
177
184
|
for (const field of [...fields].sort()) {
|
|
178
185
|
const emptyCount = rows.filter((row) => isEmptyValue(row.fields[field])).length;
|
|
179
186
|
if (required.has(field)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_view_compiler = require("./view-compiler-
|
|
1
|
+
const require_view_compiler = require("./view-compiler-DplczSjF.cjs");
|
|
2
2
|
//#region ../core/src/sync-engine.ts
|
|
3
3
|
/**
|
|
4
4
|
* Diff a view's rows against the current mirror population for one entity.
|
|
@@ -170,10 +170,17 @@ function isEmptyValue(value) {
|
|
|
170
170
|
*/
|
|
171
171
|
function computeSampleWarnings(rows, requiredFields, sourceTable) {
|
|
172
172
|
if (rows.length === 0) return [{ message: `no rows found in ${sourceTable}` }];
|
|
173
|
+
const seenRefs = /* @__PURE__ */ new Set();
|
|
174
|
+
const duplicateRefs = /* @__PURE__ */ new Set();
|
|
175
|
+
for (const row of rows) {
|
|
176
|
+
if (seenRefs.has(row.sourceRef)) duplicateRefs.add(row.sourceRef);
|
|
177
|
+
seenRefs.add(row.sourceRef);
|
|
178
|
+
}
|
|
179
|
+
const identityWarnings = duplicateRefs.size > 0 ? [{ message: `duplicate id in ${duplicateRefs.size} of ${rows.length} sampled rows — identity is not unique, so sync would collapse these into one record` }] : [];
|
|
173
180
|
const required = new Set(requiredFields);
|
|
174
181
|
const fields = new Set(requiredFields);
|
|
175
182
|
for (const row of rows) for (const key of Object.keys(row.fields)) fields.add(key);
|
|
176
|
-
const warnings = [];
|
|
183
|
+
const warnings = [...identityWarnings];
|
|
177
184
|
for (const field of [...fields].sort()) {
|
|
178
185
|
const emptyCount = rows.filter((row) => isEmptyValue(row.fields[field])).length;
|
|
179
186
|
if (required.has(field)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClivlyEntitiesConfig } from "./entity-config-
|
|
2
|
-
import { n as CompiledView, t as CompileOptions } from "./view-compiler-
|
|
1
|
+
import { a as ClivlyEntitiesConfig } from "./entity-config-C4Yf_fPj.cjs";
|
|
2
|
+
import { n as CompiledView, t as CompileOptions } from "./view-compiler-Ll9cbIJz.cjs";
|
|
3
3
|
//#region ../core/src/sync-engine.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClivlyEntitiesConfig } from "./entity-config-
|
|
2
|
-
import { n as CompiledView, t as CompileOptions } from "./view-compiler-
|
|
1
|
+
import { a as ClivlyEntitiesConfig } from "./entity-config-C4Yf_fPj.mjs";
|
|
2
|
+
import { n as CompiledView, t as CompileOptions } from "./view-compiler-Cin0neDO.mjs";
|
|
3
3
|
//#region ../core/src/sync-engine.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
|