@rebasepro/common 0.0.1-canary.2 → 0.0.1-canary.4d4fb3e
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 +1 -1
- package/dist/collections/CollectionRegistry.d.ts +2 -2
- package/dist/data/buildRebaseData.d.ts +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +398 -815
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +418 -835
- package/dist/index.umd.js.map +1 -1
- package/dist/util/builders.d.ts +6 -13
- package/dist/util/collections.d.ts +2 -2
- package/dist/util/entities.d.ts +16 -8
- package/dist/util/index.d.ts +1 -11
- package/dist/util/navigation_from_path.d.ts +10 -5
- package/dist/util/navigation_utils.d.ts +1 -12
- package/dist/util/permissions.d.ts +4 -4
- package/dist/util/references.d.ts +1 -1
- package/dist/util/relations.d.ts +4 -4
- package/dist/util/resolutions.d.ts +10 -12
- package/dist/util/storage.d.ts +4 -4
- package/package.json +11 -16
- package/src/collections/CollectionRegistry.ts +96 -33
- package/src/data/buildRebaseData.ts +221 -0
- package/src/index.ts +1 -0
- package/src/types/json-logic-js.d.ts +8 -0
- package/src/util/builders.ts +8 -18
- package/src/util/callbacks.ts +3 -4
- package/src/util/collections.ts +4 -4
- package/src/util/conditions.ts +4 -4
- package/src/util/entities.ts +37 -12
- package/src/util/index.ts +1 -11
- package/src/util/navigation_from_path.ts +8 -7
- package/src/util/navigation_utils.ts +4 -56
- package/src/util/parent_references_from_path.ts +1 -1
- package/src/util/permissions.test.ts +24 -28
- package/src/util/permissions.ts +14 -14
- package/src/util/references.ts +16 -2
- package/src/util/relations.ts +23 -19
- package/src/util/resolutions.ts +31 -62
- package/src/util/storage.ts +5 -5
- package/dist/util/arrays.d.ts +0 -1
- package/dist/util/dates.d.ts +0 -1
- package/dist/util/entity_actions.d.ts +0 -2
- package/dist/util/fields.d.ts +0 -2
- package/dist/util/flatten_object.d.ts +0 -5
- package/dist/util/hash.d.ts +0 -1
- package/dist/util/names.d.ts +0 -22
- package/dist/util/objects.d.ts +0 -26
- package/dist/util/os.d.ts +0 -2
- package/dist/util/plurals.d.ts +0 -16
- package/dist/util/regexp.d.ts +0 -7
- package/dist/util/strings.d.ts +0 -7
- package/src/util/arrays.ts +0 -3
- package/src/util/dates.ts +0 -1
- package/src/util/entity_actions.ts +0 -28
- package/src/util/fields.ts +0 -28
- package/src/util/flatten_object.ts +0 -45
- package/src/util/hash.ts +0 -11
- package/src/util/names.ts +0 -30
- package/src/util/objects.ts +0 -376
- package/src/util/os.ts +0 -13
- package/src/util/plurals.ts +0 -188
- package/src/util/regexp.ts +0 -32
- package/src/util/strings.ts +0 -84
package/dist/util/builders.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AdditionalFieldDelegate, ArrayProperty, BooleanProperty, DateProperty, EntityCallbacks, EntityCollection, EnumValueConfig, EnumValues, GeopointProperty, MapProperty, NumberProperty, Properties, Property,
|
|
1
|
+
import { AdditionalFieldDelegate, ArrayProperty, BooleanProperty, DateProperty, EntityCallbacks, EntityCollection, EnumValueConfig, EnumValues, GeopointProperty, MapProperty, NumberProperty, Properties, Property, ReferenceProperty, StringProperty, User } from "@rebasepro/types";
|
|
2
2
|
/**
|
|
3
3
|
* Identity function we use to defeat the type system of Typescript and build
|
|
4
4
|
* collection views with all its properties
|
|
5
5
|
* @param collection
|
|
6
6
|
* @group Builder
|
|
7
7
|
*/
|
|
8
|
-
export declare function buildCollection<M extends Record<string,
|
|
8
|
+
export declare function buildCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): EntityCollection<M, USER>;
|
|
9
9
|
/**
|
|
10
10
|
* Identity function we use to defeat the type system of Typescript and preserve
|
|
11
11
|
* the property keys.
|
|
@@ -19,14 +19,14 @@ export declare function buildProperty<T, P extends Property = Property>(property
|
|
|
19
19
|
* @param properties
|
|
20
20
|
* @group Builder
|
|
21
21
|
*/
|
|
22
|
-
export declare function buildProperties<M extends Record<string,
|
|
22
|
+
export declare function buildProperties<M extends Record<string, unknown>>(properties: Properties): Properties;
|
|
23
23
|
/**
|
|
24
24
|
* Identity function we use to defeat the type system of Typescript and preserve
|
|
25
25
|
* the properties keys.
|
|
26
26
|
* @param propertiesOrBuilder
|
|
27
27
|
* @group Builder
|
|
28
28
|
*/
|
|
29
|
-
export declare function buildPropertiesOrBuilder<M extends Record<string,
|
|
29
|
+
export declare function buildPropertiesOrBuilder<M extends Record<string, unknown>>(propertiesOrBuilder: Properties): Properties;
|
|
30
30
|
/**
|
|
31
31
|
* Identity function we use to defeat the type system of Typescript and preserve
|
|
32
32
|
* the properties keys.
|
|
@@ -47,18 +47,11 @@ export declare function buildEnumValueConfig(enumValueConfig: EnumValueConfig):
|
|
|
47
47
|
* @param callbacks
|
|
48
48
|
* @group Builder
|
|
49
49
|
*/
|
|
50
|
-
export declare function buildEntityCallbacks<M extends Record<string,
|
|
50
|
+
export declare function buildEntityCallbacks<M extends Record<string, unknown> = Record<string, unknown>>(callbacks: EntityCallbacks<M>): EntityCallbacks<M>;
|
|
51
51
|
/**
|
|
52
52
|
* Identity function we use to defeat the type system of Typescript and build
|
|
53
53
|
* additional field delegates views with all its properties
|
|
54
54
|
* @param additionalFieldDelegate
|
|
55
55
|
* @group Builder
|
|
56
56
|
*/
|
|
57
|
-
export declare function buildAdditionalFieldDelegate<M extends Record<string,
|
|
58
|
-
/**
|
|
59
|
-
* Identity function we use to defeat the type system of Typescript and build
|
|
60
|
-
* additional field delegates views with all its properties
|
|
61
|
-
* @param propertyConfig
|
|
62
|
-
* @group Builder
|
|
63
|
-
*/
|
|
64
|
-
export declare function buildFieldConfig(propertyConfig: PropertyConfig): PropertyConfig;
|
|
57
|
+
export declare function buildAdditionalFieldDelegate<M extends Record<string, unknown>, USER extends User = User>(additionalFieldDelegate: AdditionalFieldDelegate<M, USER>): AdditionalFieldDelegate<M, USER>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DefaultSelectedViewBuilder, DefaultSelectedViewParams, EntityCollection, Properties } from "@rebasepro/types";
|
|
2
|
-
export declare function sortProperties<M extends Record<string,
|
|
2
|
+
export declare function sortProperties<M extends Record<string, unknown>>(properties: Properties, propertiesOrder?: string[]): Properties;
|
|
3
3
|
export declare function resolveDefaultSelectedView(defaultSelectedView: string | DefaultSelectedViewBuilder | undefined, params: DefaultSelectedViewParams): string | undefined;
|
|
4
4
|
export declare function getLocalChangesBackup(collection: EntityCollection): "manual_apply" | "auto_apply";
|
|
5
5
|
/**
|
|
@@ -8,4 +8,4 @@ export declare function getLocalChangesBackup(collection: EntityCollection): "ma
|
|
|
8
8
|
* Fallbacks to `["id"]` if no properties are marked as `isId: true`.
|
|
9
9
|
* @param collection
|
|
10
10
|
*/
|
|
11
|
-
export declare function getPrimaryKeys<M extends Record<string,
|
|
11
|
+
export declare function getPrimaryKeys<M extends Record<string, unknown>>(collection: EntityCollection<M>): Extract<keyof M, string>[];
|
package/dist/util/entities.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { DataType, Entity, EntityReference, EntityRelation, EntityStatus, Entity
|
|
|
2
2
|
export declare function isReadOnly(property: Property): boolean;
|
|
3
3
|
export declare function isHidden(property: Property): boolean;
|
|
4
4
|
export declare function isPropertyBuilder(property?: Property): boolean;
|
|
5
|
-
export declare function getDefaultValuesFor<M extends Record<string,
|
|
5
|
+
export declare function getDefaultValuesFor<M extends Record<string, unknown>>(properties: Properties): Partial<EntityValues<M>>;
|
|
6
6
|
export declare function getDefaultValueFor(property?: Property): {} | null | undefined;
|
|
7
7
|
export declare function getDefaultValueFortype(type: DataType): {} | null;
|
|
8
8
|
/**
|
|
9
9
|
* Update the automatic values in an entity before save
|
|
10
|
-
* @group
|
|
10
|
+
* @group Driver
|
|
11
11
|
*/
|
|
12
|
-
export declare function updateDateAutoValues<M extends Record<string,
|
|
12
|
+
export declare function updateDateAutoValues<M extends Record<string, unknown>>({ inputValues, properties, status, timestampNowValue }: {
|
|
13
13
|
inputValues: Partial<EntityValues<M>>;
|
|
14
14
|
properties: Properties;
|
|
15
15
|
status: EntityStatus;
|
|
@@ -19,10 +19,18 @@ export declare function updateDateAutoValues<M extends Record<string, any>>({ in
|
|
|
19
19
|
* Add missing required fields, expected in the collection, to the values of an entity
|
|
20
20
|
* @param values
|
|
21
21
|
* @param properties
|
|
22
|
-
* @group
|
|
22
|
+
* @group Driver
|
|
23
23
|
*/
|
|
24
|
-
export declare function sanitizeData<M extends Record<string,
|
|
25
|
-
export declare function getReferenceFrom<M extends Record<string,
|
|
26
|
-
export declare function getRelationFrom<M extends Record<string,
|
|
27
|
-
|
|
24
|
+
export declare function sanitizeData<M extends Record<string, unknown>>(values: EntityValues<M>, properties: Properties): Record<string, unknown>;
|
|
25
|
+
export declare function getReferenceFrom<M extends Record<string, unknown>>(entity: Entity<M>): EntityReference;
|
|
26
|
+
export declare function getRelationFrom<M extends Record<string, unknown>>(entity: Entity<M>): EntityRelation;
|
|
27
|
+
/**
|
|
28
|
+
* Normalize a value into a proper EntityRelation instance.
|
|
29
|
+
* Handles EntityRelation class instances, and plain objects
|
|
30
|
+
* with `__type === "relation"` or an `isEntityRelation()` method.
|
|
31
|
+
*
|
|
32
|
+
* Returns null if the value cannot be coerced.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeToEntityRelation(value: unknown): EntityRelation | null;
|
|
35
|
+
export declare function traverseValuesProperties<M extends Record<string, unknown>>(inputValues: Partial<EntityValues<M>>, properties: Properties, operation: (value: unknown, property: Property) => unknown): EntityValues<M> | undefined;
|
|
28
36
|
export declare function traverseValueProperty(inputValue: unknown, property: Property, operation: (value: unknown, property: Property) => unknown): unknown;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
export * from "./collections";
|
|
2
2
|
export * from "./common";
|
|
3
3
|
export * from "./entities";
|
|
4
|
-
export * from "./strings";
|
|
5
|
-
export * from "./dates";
|
|
6
4
|
export * from "./enums";
|
|
7
|
-
export * from "./objects";
|
|
8
5
|
export * from "./paths";
|
|
9
|
-
export * from "./regexp";
|
|
10
|
-
export * from "./navigation_utils";
|
|
11
|
-
export * from "./entity_actions";
|
|
12
|
-
export * from "./fields";
|
|
13
6
|
export * from "./resolutions";
|
|
14
7
|
export * from "./permissions";
|
|
15
|
-
export * from "./plurals";
|
|
16
8
|
export * from "./references";
|
|
17
|
-
export * from "./flatten_object";
|
|
18
9
|
export * from "./navigation_from_path";
|
|
19
10
|
export * from "./parent_references_from_path";
|
|
20
11
|
export * from "./builders";
|
|
21
12
|
export * from "./storage";
|
|
22
|
-
export * from "./arrays";
|
|
23
13
|
export * from "./callbacks";
|
|
24
|
-
export * from "./hash";
|
|
25
14
|
export * from "./relations";
|
|
26
15
|
export * from "./conditions";
|
|
16
|
+
export * from "./navigation_utils";
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { EntityCollection
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { EntityCollection } from "@rebasepro/types";
|
|
2
|
+
type EntityCustomView<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
3
|
+
key: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export type NavigationViewInternal<M extends Record<string, unknown> = Record<string, unknown>> = NavigationViewEntityInternal<M> | NavigationViewCollectionInternal<M> | NavigationViewEntityCustomInternal<M>;
|
|
7
|
+
export interface NavigationViewEntityInternal<M extends Record<string, unknown>> {
|
|
4
8
|
type: "entity";
|
|
5
9
|
entityId: string | number;
|
|
6
10
|
slug: string;
|
|
7
11
|
path: string;
|
|
8
12
|
parentCollection: EntityCollection<M>;
|
|
9
13
|
}
|
|
10
|
-
export interface NavigationViewCollectionInternal<M extends Record<string,
|
|
14
|
+
export interface NavigationViewCollectionInternal<M extends Record<string, unknown>> {
|
|
11
15
|
type: "collection";
|
|
12
16
|
id: string;
|
|
13
17
|
slug: string;
|
|
14
18
|
path: string;
|
|
15
19
|
collection: EntityCollection<M>;
|
|
16
20
|
}
|
|
17
|
-
export interface NavigationViewEntityCustomInternal<M extends Record<string,
|
|
21
|
+
export interface NavigationViewEntityCustomInternal<M extends Record<string, unknown>> {
|
|
18
22
|
type: "custom_view";
|
|
19
23
|
slug: string;
|
|
20
24
|
path: string;
|
|
@@ -27,3 +31,4 @@ export declare function getNavigationEntriesFromPath(props: {
|
|
|
27
31
|
currentFullPath?: string;
|
|
28
32
|
contextEntityViews?: EntityCustomView[];
|
|
29
33
|
}): NavigationViewInternal[];
|
|
34
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityCollection
|
|
1
|
+
import { EntityCollection } from "@rebasepro/types";
|
|
2
2
|
export declare function removeInitialAndTrailingSlashes(s: string): string;
|
|
3
3
|
export declare function removeInitialSlash(s: string): string;
|
|
4
4
|
export declare function removeTrailingSlash(s: string): string;
|
|
@@ -18,14 +18,3 @@ export declare function getCollectionBySlugWithin(slugOrPath: string, collection
|
|
|
18
18
|
* @param subpaths
|
|
19
19
|
*/
|
|
20
20
|
export declare function getCollectionPathsCombinations(subpaths: string[]): string[];
|
|
21
|
-
export declare function navigateToEntity({ openEntityMode, collection, entityId, copy, path, selectedTab, sideEntityController, onClose, navigation }: {
|
|
22
|
-
openEntityMode: "side_panel" | "full_screen";
|
|
23
|
-
collection?: EntityCollection;
|
|
24
|
-
entityId?: string | number;
|
|
25
|
-
selectedTab?: string;
|
|
26
|
-
copy?: boolean;
|
|
27
|
-
path: string;
|
|
28
|
-
sideEntityController: SideEntityController;
|
|
29
|
-
onClose?: () => void;
|
|
30
|
-
navigation: CMSUrlController;
|
|
31
|
-
}): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthController, Entity, EntityCollection, User } from "@rebasepro/types";
|
|
2
|
-
export declare function canReadCollection<M extends Record<string,
|
|
3
|
-
export declare function canEditEntity<M extends Record<string,
|
|
4
|
-
export declare function canCreateEntity<M extends Record<string,
|
|
5
|
-
export declare function canDeleteEntity<M extends Record<string,
|
|
2
|
+
export declare function canReadCollection<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>): boolean;
|
|
3
|
+
export declare function canEditEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>, path: string, entity: Entity<M> | null): boolean;
|
|
4
|
+
export declare function canCreateEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>, path: string, entity: Entity<M> | null): boolean;
|
|
5
|
+
export declare function canDeleteEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>, path: string, entity: Entity<M> | null): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { EntityCollection } from "@rebasepro/types";
|
|
2
|
-
export declare function getEntityImagePreviewPropertyKey<M extends
|
|
2
|
+
export declare function getEntityImagePreviewPropertyKey<M extends Record<string, unknown>>(collection: EntityCollection<M>): string | undefined;
|
package/dist/util/relations.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EntityCollection, Property, Relation } from "@rebasepro/types";
|
|
2
|
-
export declare function sanitizeRelation(relation: Partial<Relation>, sourceCollection:
|
|
3
|
-
export declare function resolveCollectionRelations(collection:
|
|
1
|
+
import { EntityCollection, PostgresCollection, Property, Relation } from "@rebasepro/types";
|
|
2
|
+
export declare function sanitizeRelation(relation: Partial<Relation>, sourceCollection: PostgresCollection): Relation;
|
|
3
|
+
export declare function resolveCollectionRelations(collection: PostgresCollection): Record<string, Relation>;
|
|
4
4
|
export declare function resolvePropertyRelation({ propertyKey, property, sourceCollection }: {
|
|
5
5
|
propertyKey: string;
|
|
6
6
|
property: Property;
|
|
7
|
-
sourceCollection:
|
|
7
|
+
sourceCollection: PostgresCollection;
|
|
8
8
|
}): Relation | undefined;
|
|
9
9
|
export declare function getTableName(collection: EntityCollection): string;
|
|
10
10
|
export declare function getTableVarName(tableName: string): string;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { ArrayProperty, AuthController,
|
|
1
|
+
import { ArrayProperty, AuthController, EntityCollection, EnumValueConfig, EnumValues, NumberProperty, Properties, Property, Relation, RelationProperty, StringProperty } from "@rebasepro/types";
|
|
2
|
+
type PropertyConfig = {
|
|
3
|
+
property: unknown;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Resolve property builders, enums and arrays.
|
|
4
8
|
*/
|
|
5
|
-
export type ResolvePropertyProps<M extends Record<string,
|
|
9
|
+
export type ResolvePropertyProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
6
10
|
property: Property;
|
|
7
11
|
propertyKey?: string;
|
|
8
12
|
values?: Partial<M>;
|
|
@@ -14,7 +18,7 @@ export type ResolvePropertyProps<M extends Record<string, any> = any> = {
|
|
|
14
18
|
ignoreMissingFields?: boolean;
|
|
15
19
|
authController: AuthController;
|
|
16
20
|
};
|
|
17
|
-
export declare function resolveProperty<M extends Record<string,
|
|
21
|
+
export declare function resolveProperty<M extends Record<string, unknown> = Record<string, unknown>>(props: ResolvePropertyProps<M>): Property | null;
|
|
18
22
|
export declare function resolveRelationProperty(property: RelationProperty, relations: Relation[]): RelationProperty;
|
|
19
23
|
/**
|
|
20
24
|
* Resolve enum aliases for a string or number property
|
|
@@ -26,7 +30,7 @@ export declare function resolvePropertyEnum(property: StringProperty | NumberPro
|
|
|
26
30
|
* @param properties
|
|
27
31
|
* @param value
|
|
28
32
|
*/
|
|
29
|
-
export declare function resolveProperties<M extends Record<string,
|
|
33
|
+
export declare function resolveProperties<M extends Record<string, unknown>>({ propertyKey, properties, ignoreMissingFields, ...props }: {
|
|
30
34
|
propertyKey?: string;
|
|
31
35
|
properties: Properties;
|
|
32
36
|
values?: Partial<M>;
|
|
@@ -64,11 +68,5 @@ export declare function getArrayResolvedProperties({ propertyKey, propertyValue,
|
|
|
64
68
|
authController: AuthController;
|
|
65
69
|
}): Property[];
|
|
66
70
|
export declare function resolveEnumValues(input: EnumValues): EnumValueConfig[] | undefined;
|
|
67
|
-
export declare function
|
|
68
|
-
export
|
|
69
|
-
export declare function resolvedSelectedEntityView<M extends Record<string, any>>(customViews: (string | EntityCustomView<M>)[] | undefined, customizationController: CustomizationController, selectedTab?: string, canEdit?: boolean): {
|
|
70
|
-
resolvedEntityViews: EntityCustomView<M>[];
|
|
71
|
-
selectedEntityView: EntityCustomView<M> | undefined;
|
|
72
|
-
selectedSecondaryForm: EntityCustomView<M> | undefined;
|
|
73
|
-
};
|
|
74
|
-
export declare function getSubcollections<M extends Record<string, any> = any>(collection: EntityCollection<M>): EntityCollection<any, any>[];
|
|
71
|
+
export declare function getSubcollections<M extends Record<string, unknown> = Record<string, unknown>>(collection: EntityCollection<M>): EntityCollection<Record<string, unknown>>[];
|
|
72
|
+
export {};
|
package/dist/util/storage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArrayProperty, EntityValues, StorageConfig, StringProperty, UploadedFileContext } from "@rebasepro/types";
|
|
2
|
-
interface ResolveFilenameStringParams<M extends
|
|
2
|
+
interface ResolveFilenameStringParams<M extends Record<string, unknown>> {
|
|
3
3
|
input: string | ((context: UploadedFileContext) => (Promise<string> | string));
|
|
4
4
|
storage: StorageConfig;
|
|
5
5
|
values: EntityValues<M>;
|
|
@@ -9,8 +9,8 @@ interface ResolveFilenameStringParams<M extends object> {
|
|
|
9
9
|
file: File;
|
|
10
10
|
propertyKey: string;
|
|
11
11
|
}
|
|
12
|
-
export declare function resolveStorageFilenameString<M extends
|
|
13
|
-
interface ResolveStoragePathStringParams<M extends
|
|
12
|
+
export declare function resolveStorageFilenameString<M extends Record<string, unknown>>({ input, storage, values, entityId, path, property, file, propertyKey }: ResolveFilenameStringParams<M>): Promise<string>;
|
|
13
|
+
interface ResolveStoragePathStringParams<M extends Record<string, unknown>> {
|
|
14
14
|
input: string | ((context: UploadedFileContext) => string);
|
|
15
15
|
storage: StorageConfig;
|
|
16
16
|
values: EntityValues<M>;
|
|
@@ -20,5 +20,5 @@ interface ResolveStoragePathStringParams<M extends object> {
|
|
|
20
20
|
file: File;
|
|
21
21
|
propertyKey: string;
|
|
22
22
|
}
|
|
23
|
-
export declare function resolveStoragePathString<M extends
|
|
23
|
+
export declare function resolveStoragePathString<M extends Record<string, unknown>>({ input, storage, values, entityId, path, property, file, propertyKey }: ResolveStoragePathStringParams<M>): string;
|
|
24
24
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/common",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1-canary.
|
|
4
|
+
"version": "0.0.1-canary.4d4fb3e",
|
|
5
5
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/rebasepro/rebase.git",
|
|
14
14
|
"directory": "packages/common"
|
|
15
15
|
},
|
|
16
16
|
"main": "./dist/index.umd.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"watch": "vite build --watch",
|
|
36
36
|
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
37
|
-
"prepublishOnly": "run
|
|
37
|
+
"prepublishOnly": "pnpm run build",
|
|
38
38
|
"test:lint": "eslint \"src/**\" --quiet",
|
|
39
39
|
"test": "jest --passWithNoTests",
|
|
40
40
|
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f",
|
|
@@ -42,28 +42,25 @@
|
|
|
42
42
|
},
|
|
43
43
|
"exports": {
|
|
44
44
|
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
45
46
|
"development": "./src/index.ts",
|
|
46
47
|
"import": "./dist/index.es.js",
|
|
47
|
-
"require": "./dist/index.umd.js"
|
|
48
|
-
"types": "./dist/index.d.ts"
|
|
48
|
+
"require": "./dist/index.umd.js"
|
|
49
49
|
},
|
|
50
50
|
"./package.json": "./package.json"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@rebasepro/types": "
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"react": ">=19.0.0",
|
|
58
|
-
"react-dom": ">=19.0.0",
|
|
59
|
-
"react-router": "^6.28.0",
|
|
60
|
-
"react-router-dom": "^6.28.0"
|
|
53
|
+
"@rebasepro/types": "0.0.1-canary.4d4fb3e",
|
|
54
|
+
"@rebasepro/utils": "0.0.1-canary.4d4fb3e",
|
|
55
|
+
"fast-equals": "5.3.0",
|
|
56
|
+
"json-logic-js": "^2.0.5"
|
|
61
57
|
},
|
|
62
58
|
"devDependencies": {
|
|
63
59
|
"@jest/globals": "^29.7.0",
|
|
64
60
|
"@testing-library/react": "^16.3.0",
|
|
65
61
|
"@testing-library/user-event": "^14.6.1",
|
|
66
62
|
"@types/jest": "^29.5.14",
|
|
63
|
+
"@types/lodash": "4.17.24",
|
|
67
64
|
"@types/node": "^20.17.14",
|
|
68
65
|
"@types/object-hash": "^3.0.6",
|
|
69
66
|
"@types/react": "^19.0.8",
|
|
@@ -75,8 +72,6 @@
|
|
|
75
72
|
"eslint-plugin-react-compiler": "beta",
|
|
76
73
|
"jest": "^29.7.0",
|
|
77
74
|
"npm-run-all": "^4.1.5",
|
|
78
|
-
"react-router": "^7.13.1",
|
|
79
|
-
"react-router-dom": "^7.13.1",
|
|
80
75
|
"ts-jest": "^29.3.1",
|
|
81
76
|
"ts-node": "^10.9.2",
|
|
82
77
|
"tsd": "^0.31.2",
|
|
@@ -87,7 +82,7 @@
|
|
|
87
82
|
"dist",
|
|
88
83
|
"src"
|
|
89
84
|
],
|
|
90
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "71bcef3c51a458cd054f7924cc18efbbe515dcc8",
|
|
91
86
|
"publishConfig": {
|
|
92
87
|
"access": "public"
|
|
93
88
|
},
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ArrayProperty,
|
|
2
3
|
EntityCollection,
|
|
4
|
+
isPostgresCollection,
|
|
5
|
+
isFirebaseCollection,
|
|
3
6
|
NumberProperty,
|
|
7
|
+
PostgresCollection,
|
|
4
8
|
Properties,
|
|
5
9
|
Property,
|
|
6
10
|
Relation,
|
|
@@ -9,18 +13,19 @@ import {
|
|
|
9
13
|
} from "@rebasepro/types";
|
|
10
14
|
import { deepEqual } from "fast-equals";
|
|
11
15
|
|
|
12
|
-
import { enumToObjectEntries, getSubcollections,
|
|
16
|
+
import { enumToObjectEntries, getSubcollections, getTableName, resolveCollectionRelations } from "../util";
|
|
13
17
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
18
|
+
import { removeFunctions, mergeDeep } from "@rebasepro/utils";
|
|
14
19
|
|
|
15
20
|
export class CollectionRegistry {
|
|
16
21
|
|
|
17
22
|
// Normalized runtime layer (used by Data Grid / UI)
|
|
18
|
-
private
|
|
23
|
+
private collectionsByTableName = new Map<string, EntityCollection>();
|
|
19
24
|
private collectionsBySlug = new Map<string, EntityCollection>();
|
|
20
25
|
private rootCollections: EntityCollection[] = [];
|
|
21
26
|
|
|
22
27
|
// Raw configuration layer (used by Collection Editor AST generator)
|
|
23
|
-
private
|
|
28
|
+
private rawCollectionsByTableName = new Map<string, EntityCollection>();
|
|
24
29
|
private rawCollectionsBySlug = new Map<string, EntityCollection>();
|
|
25
30
|
private rawRootCollections: EntityCollection[] = [];
|
|
26
31
|
|
|
@@ -35,11 +40,11 @@ export class CollectionRegistry {
|
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
reset() {
|
|
38
|
-
this.
|
|
43
|
+
this.collectionsByTableName.clear();
|
|
39
44
|
this.collectionsBySlug.clear();
|
|
40
45
|
this.rootCollections = [];
|
|
41
46
|
|
|
42
|
-
this.
|
|
47
|
+
this.rawCollectionsByTableName.clear();
|
|
43
48
|
this.rawCollectionsBySlug.clear();
|
|
44
49
|
this.rawRootCollections = [];
|
|
45
50
|
}
|
|
@@ -65,7 +70,38 @@ export class CollectionRegistry {
|
|
|
65
70
|
this.reset();
|
|
66
71
|
|
|
67
72
|
const normalizedCollections = collections.map(c => this.normalizeCollection({ ...c }));
|
|
68
|
-
|
|
73
|
+
|
|
74
|
+
// Phase 1: Register all top-level collections first (without recursion).
|
|
75
|
+
// This ensures that injected entityViews (e.g. History tab) are preserved.
|
|
76
|
+
// Without this, _registerRecursively could register a relation-target collection
|
|
77
|
+
// (e.g. Tags from Posts.relations) using the raw module object (without injected views)
|
|
78
|
+
// before the top-level Tags collection (with injected views) gets its turn.
|
|
79
|
+
normalizedCollections.forEach((c, index) => {
|
|
80
|
+
const raw = cloneDeep(collections[index]);
|
|
81
|
+
this.rootCollections.push(c);
|
|
82
|
+
this.rawRootCollections.push(raw);
|
|
83
|
+
|
|
84
|
+
const normalized = this.normalizeCollection(c);
|
|
85
|
+
this.collectionsByTableName.set(getTableName(normalized), normalized);
|
|
86
|
+
this.rawCollectionsByTableName.set(getTableName(raw), raw);
|
|
87
|
+
if (normalized.slug) {
|
|
88
|
+
this.collectionsBySlug.set(normalized.slug, normalized);
|
|
89
|
+
}
|
|
90
|
+
if (raw.slug) {
|
|
91
|
+
this.rawCollectionsBySlug.set(raw.slug, raw);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Phase 2: Now recurse into subcollections (relations, etc.)
|
|
96
|
+
normalizedCollections.forEach((c, index) => {
|
|
97
|
+
const subcollections = getSubcollections(c);
|
|
98
|
+
const rawSubcollections = getSubcollections(collections[index]);
|
|
99
|
+
if (subcollections && rawSubcollections) {
|
|
100
|
+
subcollections.forEach((subCollection, subIndex) => {
|
|
101
|
+
this._registerRecursively(this.normalizeCollection(subCollection), cloneDeep(rawSubcollections[subIndex]));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
69
105
|
|
|
70
106
|
// Store the snapshot for future comparisons
|
|
71
107
|
this.lastRawInputSnapshot = rawSnapshot;
|
|
@@ -83,13 +119,13 @@ export class CollectionRegistry {
|
|
|
83
119
|
}
|
|
84
120
|
|
|
85
121
|
private _registerRecursively(collection: EntityCollection, rawCollection: EntityCollection) {
|
|
86
|
-
if (this.
|
|
122
|
+
if (this.collectionsByTableName.has(getTableName(collection))) {
|
|
87
123
|
return;
|
|
88
124
|
}
|
|
89
125
|
|
|
90
126
|
const normalizedCollection = this.normalizeCollection(collection);
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
127
|
+
this.collectionsByTableName.set(getTableName(normalizedCollection), normalizedCollection);
|
|
128
|
+
this.rawCollectionsByTableName.set(getTableName(rawCollection), rawCollection);
|
|
93
129
|
|
|
94
130
|
if (normalizedCollection.slug) {
|
|
95
131
|
this.collectionsBySlug.set(normalizedCollection.slug, normalizedCollection);
|
|
@@ -109,9 +145,26 @@ export class CollectionRegistry {
|
|
|
109
145
|
}
|
|
110
146
|
|
|
111
147
|
public normalizeCollection(collection: EntityCollection): EntityCollection {
|
|
112
|
-
const
|
|
148
|
+
const relations = isPostgresCollection(collection) ? (collection.relations ?? []) : [];
|
|
149
|
+
const properties: Properties = this.normalizeProperties(collection.properties, relations);
|
|
113
150
|
|
|
114
151
|
collection.properties = properties;
|
|
152
|
+
|
|
153
|
+
// Populate childCollections from driver-specific fields
|
|
154
|
+
if (!collection.childCollections) {
|
|
155
|
+
if (isFirebaseCollection(collection) && collection.subcollections) {
|
|
156
|
+
collection.childCollections = collection.subcollections;
|
|
157
|
+
} else if (isPostgresCollection(collection) && collection.relations) {
|
|
158
|
+
const manyRelations = collection.relations.filter(r => r.cardinality === "many");
|
|
159
|
+
if (manyRelations.length > 0) {
|
|
160
|
+
collection.childCollections = () => manyRelations.map(r => {
|
|
161
|
+
const target = r.target();
|
|
162
|
+
return r.overrides ? mergeDeep(target, r.overrides) : target;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
115
168
|
return collection;
|
|
116
169
|
}
|
|
117
170
|
|
|
@@ -129,10 +182,16 @@ export class CollectionRegistry {
|
|
|
129
182
|
if (newProperty.type === "map" && newProperty.properties) {
|
|
130
183
|
newProperty.properties = this.normalizeProperties(newProperty.properties, relations);
|
|
131
184
|
} else if (newProperty.type === "array") {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
185
|
+
// Cast via unknown to get a properly typed mutable reference
|
|
186
|
+
const arrayProp = newProperty as unknown as ArrayProperty;
|
|
187
|
+
if (arrayProp.of) {
|
|
188
|
+
if (Array.isArray(arrayProp.of)) {
|
|
189
|
+
(arrayProp as { of: Property | Property[] }).of = arrayProp.of.map(p => this.normalizeProperty(p, relations));
|
|
190
|
+
} else {
|
|
191
|
+
arrayProp.of = this.normalizeProperty(arrayProp.of, relations);
|
|
192
|
+
}
|
|
193
|
+
} else if (arrayProp.oneOf && arrayProp.oneOf.properties) {
|
|
194
|
+
arrayProp.oneOf.properties = this.normalizeProperties(arrayProp.oneOf.properties, relations);
|
|
136
195
|
}
|
|
137
196
|
} else if ((newProperty.type === "string" || newProperty.type === "number") && newProperty.enum) {
|
|
138
197
|
const stringOrNumberProperty = newProperty as StringProperty | NumberProperty;
|
|
@@ -158,8 +217,8 @@ export class CollectionRegistry {
|
|
|
158
217
|
const bySlug = this.collectionsBySlug.get(path);
|
|
159
218
|
if (bySlug) return bySlug;
|
|
160
219
|
|
|
161
|
-
// Fallback to
|
|
162
|
-
return this.
|
|
220
|
+
// Fallback to table name lookup
|
|
221
|
+
return this.collectionsByTableName.get(path);
|
|
163
222
|
}
|
|
164
223
|
|
|
165
224
|
/**
|
|
@@ -169,7 +228,7 @@ export class CollectionRegistry {
|
|
|
169
228
|
getRaw(path: string): EntityCollection | undefined {
|
|
170
229
|
const bySlug = this.rawCollectionsBySlug.get(path);
|
|
171
230
|
if (bySlug) return bySlug;
|
|
172
|
-
return this.
|
|
231
|
+
return this.rawCollectionsByTableName.get(path);
|
|
173
232
|
}
|
|
174
233
|
|
|
175
234
|
/**
|
|
@@ -202,11 +261,14 @@ export class CollectionRegistry {
|
|
|
202
261
|
const relationKey = pathSegments[i];
|
|
203
262
|
|
|
204
263
|
// Get relations for current collection
|
|
264
|
+
if (!isPostgresCollection(currentCollection)) {
|
|
265
|
+
throw new Error(`Relation path navigation requires a PostgreSQL collection, but '${currentCollection.slug}' uses driver '${currentCollection.driver}'`);
|
|
266
|
+
}
|
|
205
267
|
const resolvedRelations = resolveCollectionRelations(currentCollection);
|
|
206
268
|
const relation = resolvedRelations[relationKey];
|
|
207
269
|
|
|
208
270
|
if (!relation) {
|
|
209
|
-
throw new Error(`Relation '${relationKey}' not found in collection '${currentCollection.slug
|
|
271
|
+
throw new Error(`Relation '${relationKey}' not found in collection '${currentCollection.slug}'`);
|
|
210
272
|
}
|
|
211
273
|
|
|
212
274
|
// Move to the target collection
|
|
@@ -222,11 +284,11 @@ export class CollectionRegistry {
|
|
|
222
284
|
}
|
|
223
285
|
|
|
224
286
|
getCollections(): EntityCollection[] {
|
|
225
|
-
return Array.from(this.
|
|
287
|
+
return Array.from(this.collectionsByTableName.values());
|
|
226
288
|
}
|
|
227
289
|
|
|
228
290
|
getRawCollections(): EntityCollection[] {
|
|
229
|
-
return Array.from(this.
|
|
291
|
+
return Array.from(this.rawCollectionsByTableName.values());
|
|
230
292
|
}
|
|
231
293
|
|
|
232
294
|
/**
|
|
@@ -267,14 +329,14 @@ export class CollectionRegistry {
|
|
|
267
329
|
|
|
268
330
|
if (i + 1 < pathSegments.length) {
|
|
269
331
|
const subcollectionSlug = pathSegments[i + 1];
|
|
270
|
-
const subcollections: EntityCollection[] | undefined = currentCollection
|
|
271
|
-
if (!subcollections) {
|
|
272
|
-
throw new Error(`No subcollections found for ${currentCollection.slug
|
|
332
|
+
const subcollections: EntityCollection[] | undefined = getSubcollections(currentCollection);
|
|
333
|
+
if (!subcollections || subcollections.length === 0) {
|
|
334
|
+
throw new Error(`No subcollections found for ${currentCollection.slug} in path: ${path}`);
|
|
273
335
|
}
|
|
274
336
|
|
|
275
337
|
const subcollection: EntityCollection | undefined = subcollections.find(c => c.slug === subcollectionSlug);
|
|
276
338
|
if (!subcollection) {
|
|
277
|
-
throw new Error(`Subcollection '${subcollectionSlug}' not found in ${currentCollection.slug
|
|
339
|
+
throw new Error(`Subcollection '${subcollectionSlug}' not found in ${currentCollection.slug}`);
|
|
278
340
|
}
|
|
279
341
|
currentCollection = subcollection;
|
|
280
342
|
collections.push(currentCollection);
|
|
@@ -304,15 +366,16 @@ function areCollectionListsEqual(a: EntityCollection[], b: EntityCollection[]) {
|
|
|
304
366
|
}
|
|
305
367
|
|
|
306
368
|
function areCollectionsEqual(a: EntityCollection, b: EntityCollection) {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
} =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
369
|
+
const subcollectionsA = getSubcollections(a);
|
|
370
|
+
const subcollectionsB = getSubcollections(b);
|
|
371
|
+
const { driver: _dA, ...restA } = a as unknown as Record<string, unknown>;
|
|
372
|
+
const { driver: _dB, ...restB } = b as unknown as Record<string, unknown>;
|
|
373
|
+
// Remove subcollections/relations from comparison objects (already handled above)
|
|
374
|
+
delete restA.subcollections;
|
|
375
|
+
delete restB.subcollections;
|
|
376
|
+
delete restA.relations;
|
|
377
|
+
delete restB.relations;
|
|
378
|
+
if (!areCollectionListsEqual(subcollectionsA, subcollectionsB)) {
|
|
316
379
|
return false;
|
|
317
380
|
}
|
|
318
381
|
return deepEqual(removeFunctions(restA), removeFunctions(restB));
|