@rebasepro/common 0.13.0 → 0.13.1-canary.g249daa1
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/dist/data/buildRebaseData.d.ts +10 -1
- package/dist/data/filter-dialect.d.ts +15 -1
- package/dist/data/paginate.d.ts +20 -0
- package/dist/data/query_builder.d.ts +15 -3
- package/dist/data/resolveDataSource.d.ts +36 -0
- package/dist/index.es.js +444 -48
- package/dist/index.es.js.map +1 -1
- package/dist/util/builders.d.ts +2 -2
- package/dist/util/conditions.d.ts +7 -3
- package/dist/util/entities.d.ts +8 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/internal-tables.d.ts +95 -0
- package/dist/util/policy/sqlToPolicy.d.ts +4 -4
- package/dist/util/relations.d.ts +18 -1
- package/dist/util/resolutions.d.ts +31 -0
- package/package.json +3 -3
- package/src/data/buildRebaseData.ts +147 -23
- package/src/data/filter-dialect.ts +28 -3
- package/src/data/paginate.ts +30 -0
- package/src/data/query_builder.ts +25 -3
- package/src/data/resolveDataSource.ts +56 -0
- package/src/util/builders.ts +3 -3
- package/src/util/conditions.ts +8 -3
- package/src/util/entities.ts +15 -1
- package/src/util/index.ts +1 -0
- package/src/util/internal-tables.ts +154 -0
- package/src/util/policy/policyToPostgres.ts +23 -10
- package/src/util/policy/sqlToPolicy.ts +40 -20
- package/src/util/relations.ts +31 -0
- package/src/util/resolutions.ts +77 -5
package/src/util/resolutions.ts
CHANGED
|
@@ -261,11 +261,11 @@ export function resolveArrayProperties<M>({
|
|
|
261
261
|
ignoreMissingFields,
|
|
262
262
|
...props
|
|
263
263
|
});
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
} = props;
|
|
264
|
+
// Destructured to be *excluded* from `...rest`, not to be used —
|
|
265
|
+
// see the comment below. Said explicitly so the discarded-value
|
|
266
|
+
// ratchet does not carry a finding that is working as intended.
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
268
|
+
const { values, previousValues, ...rest } = props;
|
|
269
269
|
const ofProperty = resolveProperty({ // we don't want to pass the values of the parent entity
|
|
270
270
|
property: of,
|
|
271
271
|
ignoreMissingFields,
|
|
@@ -449,6 +449,78 @@ singularName: customName } : {})
|
|
|
449
449
|
return views;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Each of `collection`'s tabs paired with the property that declared it, when a
|
|
454
|
+
* property declared it: child view key → property key.
|
|
455
|
+
*
|
|
456
|
+
* A many-relation can only be declared as a property — that is the documented
|
|
457
|
+
* and only mechanism — and {@link getEntityChildViews} promotes it to a tab. So
|
|
458
|
+
* one declaration reaches the panel twice, and neither surface knew about the
|
|
459
|
+
* other. The form rendered a relation picker beside the tab, and the collection
|
|
460
|
+
* table rendered *two* columns under one heading: the relation's own column,
|
|
461
|
+
* showing the child rows, and a jump-to-tab button carrying the same name.
|
|
462
|
+
*
|
|
463
|
+
* The pairing is what lets each surface decide which half is redundant, and it
|
|
464
|
+
* has to be a pairing rather than two sets because the two keys differ whenever
|
|
465
|
+
* a relation is named. The match is on the resolved `relationName` — the
|
|
466
|
+
* identity `getEntityChildViews` itself dedupes on — so a relation declared in
|
|
467
|
+
* `relations` and pointed at by a differently-named property is recognised too.
|
|
468
|
+
*
|
|
469
|
+
* A relation with no property of its own is absent here, which is the point: it
|
|
470
|
+
* has exactly one surface already, and nothing to weigh it against.
|
|
471
|
+
*
|
|
472
|
+
* Only top-level properties: a relation nested inside a `map` gets no tab.
|
|
473
|
+
*/
|
|
474
|
+
export function getChildViewDeclaringProperties<M extends Record<string, unknown> = Record<string, unknown>>(
|
|
475
|
+
collection: CollectionConfig<M>
|
|
476
|
+
): Map<string, string> {
|
|
477
|
+
const pairs = new Map<string, string>();
|
|
478
|
+
|
|
479
|
+
const relationProperties = Object.entries((collection.properties ?? {}) as Record<string, Property>)
|
|
480
|
+
.filter(([, property]) => property?.type === "relation");
|
|
481
|
+
if (relationProperties.length === 0) return pairs;
|
|
482
|
+
|
|
483
|
+
const relationViews = getEntityChildViews(collection)
|
|
484
|
+
.filter(view => view.source.kind === "relation");
|
|
485
|
+
if (relationViews.length === 0) return pairs;
|
|
486
|
+
|
|
487
|
+
const resolvedRelations = resolveCollectionRelations(collection);
|
|
488
|
+
const identityOf = (relationKey: string): string =>
|
|
489
|
+
resolvedRelations[relationKey]?.relationName ?? relationKey;
|
|
490
|
+
|
|
491
|
+
const declaringPropertyByIdentity = new Map<string, string>();
|
|
492
|
+
for (const [propertyKey, property] of relationProperties) {
|
|
493
|
+
const relation = (property as RelationProperty).resolvedRelation ?? resolvedRelations[propertyKey];
|
|
494
|
+
// A to-one relation is a foreign key the author edits, never a tab. No
|
|
495
|
+
// view will match it — the views here are many-relations only — but
|
|
496
|
+
// reading the cardinality says so where someone is looking.
|
|
497
|
+
if (relation?.cardinality !== "many") continue;
|
|
498
|
+
const identity = relation.relationName ?? propertyKey;
|
|
499
|
+
if (!declaringPropertyByIdentity.has(identity)) declaringPropertyByIdentity.set(identity, propertyKey);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
for (const view of relationViews) {
|
|
503
|
+
const propertyKey = declaringPropertyByIdentity.get(
|
|
504
|
+
identityOf((view.source as { relationKey: string }).relationKey));
|
|
505
|
+
if (propertyKey) pairs.set(view.key, propertyKey);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return pairs;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* The property keys of `collection` whose relation is already one of its tabs.
|
|
513
|
+
*
|
|
514
|
+
* What a form asks: the tab is the treatment for a list of child rows, so the
|
|
515
|
+
* picker beside it is the redundant half. See
|
|
516
|
+
* {@link getChildViewDeclaringProperties}.
|
|
517
|
+
*/
|
|
518
|
+
export function getChildViewRelationPropertyKeys<M extends Record<string, unknown> = Record<string, unknown>>(
|
|
519
|
+
collection: CollectionConfig<M>
|
|
520
|
+
): Set<string> {
|
|
521
|
+
return new Set(getChildViewDeclaringProperties(collection).values());
|
|
522
|
+
}
|
|
523
|
+
|
|
452
524
|
/**
|
|
453
525
|
* The child views of `collection` as bare collections.
|
|
454
526
|
*
|