@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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/collections/CollectionRegistry.d.ts +2 -2
  3. package/dist/data/buildRebaseData.d.ts +14 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.es.js +398 -815
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +418 -835
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/util/builders.d.ts +6 -13
  10. package/dist/util/collections.d.ts +2 -2
  11. package/dist/util/entities.d.ts +16 -8
  12. package/dist/util/index.d.ts +1 -11
  13. package/dist/util/navigation_from_path.d.ts +10 -5
  14. package/dist/util/navigation_utils.d.ts +1 -12
  15. package/dist/util/permissions.d.ts +4 -4
  16. package/dist/util/references.d.ts +1 -1
  17. package/dist/util/relations.d.ts +4 -4
  18. package/dist/util/resolutions.d.ts +10 -12
  19. package/dist/util/storage.d.ts +4 -4
  20. package/package.json +11 -16
  21. package/src/collections/CollectionRegistry.ts +96 -33
  22. package/src/data/buildRebaseData.ts +221 -0
  23. package/src/index.ts +1 -0
  24. package/src/types/json-logic-js.d.ts +8 -0
  25. package/src/util/builders.ts +8 -18
  26. package/src/util/callbacks.ts +3 -4
  27. package/src/util/collections.ts +4 -4
  28. package/src/util/conditions.ts +4 -4
  29. package/src/util/entities.ts +37 -12
  30. package/src/util/index.ts +1 -11
  31. package/src/util/navigation_from_path.ts +8 -7
  32. package/src/util/navigation_utils.ts +4 -56
  33. package/src/util/parent_references_from_path.ts +1 -1
  34. package/src/util/permissions.test.ts +24 -28
  35. package/src/util/permissions.ts +14 -14
  36. package/src/util/references.ts +16 -2
  37. package/src/util/relations.ts +23 -19
  38. package/src/util/resolutions.ts +31 -62
  39. package/src/util/storage.ts +5 -5
  40. package/dist/util/arrays.d.ts +0 -1
  41. package/dist/util/dates.d.ts +0 -1
  42. package/dist/util/entity_actions.d.ts +0 -2
  43. package/dist/util/fields.d.ts +0 -2
  44. package/dist/util/flatten_object.d.ts +0 -5
  45. package/dist/util/hash.d.ts +0 -1
  46. package/dist/util/names.d.ts +0 -22
  47. package/dist/util/objects.d.ts +0 -26
  48. package/dist/util/os.d.ts +0 -2
  49. package/dist/util/plurals.d.ts +0 -16
  50. package/dist/util/regexp.d.ts +0 -7
  51. package/dist/util/strings.d.ts +0 -7
  52. package/src/util/arrays.ts +0 -3
  53. package/src/util/dates.ts +0 -1
  54. package/src/util/entity_actions.ts +0 -28
  55. package/src/util/fields.ts +0 -28
  56. package/src/util/flatten_object.ts +0 -45
  57. package/src/util/hash.ts +0 -11
  58. package/src/util/names.ts +0 -30
  59. package/src/util/objects.ts +0 -376
  60. package/src/util/os.ts +0 -13
  61. package/src/util/plurals.ts +0 -188
  62. package/src/util/regexp.ts +0 -32
  63. package/src/util/strings.ts +0 -84
@@ -1,11 +1,11 @@
1
- import { AdditionalFieldDelegate, ArrayProperty, BooleanProperty, DateProperty, EntityCallbacks, EntityCollection, EnumValueConfig, EnumValues, GeopointProperty, MapProperty, NumberProperty, Properties, Property, PropertyConfig, ReferenceProperty, StringProperty, User } from "@rebasepro/types";
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, any> = any, USER extends User = User>(collection: EntityCollection<M, USER>): EntityCollection<M, USER>;
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, any>>(properties: Properties): Properties;
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, any>>(propertiesOrBuilder: Properties): Properties;
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, any> = any>(callbacks: EntityCallbacks<M>): EntityCallbacks<M>;
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, any>, USER extends User = User>(additionalFieldDelegate: AdditionalFieldDelegate<M, USER>): AdditionalFieldDelegate<M, USER>;
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, any>>(properties: Properties, propertiesOrder?: string[]): Properties;
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, any>>(collection: EntityCollection<M>): Extract<keyof M, string>[];
11
+ export declare function getPrimaryKeys<M extends Record<string, unknown>>(collection: EntityCollection<M>): Extract<keyof M, string>[];
@@ -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, any>>(properties: Properties): Partial<EntityValues<M>>;
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 Datasource
10
+ * @group Driver
11
11
  */
12
- export declare function updateDateAutoValues<M extends Record<string, any>>({ inputValues, properties, status, timestampNowValue }: {
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 Datasource
22
+ * @group Driver
23
23
  */
24
- export declare function sanitizeData<M extends Record<string, any>>(values: EntityValues<M>, properties: Properties): Record<string, unknown>;
25
- export declare function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference;
26
- export declare function getRelationFrom<M extends Record<string, any>>(entity: Entity<M>): EntityRelation;
27
- export declare function traverseValuesProperties<M extends Record<string, any>>(inputValues: Partial<EntityValues<M>>, properties: Properties, operation: (value: unknown, property: Property) => unknown): EntityValues<M> | undefined;
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;
@@ -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, EntityCustomView } from "@rebasepro/types";
2
- export type NavigationViewInternal<M extends Record<string, any> = any> = NavigationViewEntityInternal<M> | NavigationViewCollectionInternal<M> | NavigationViewEntityCustomInternal<M>;
3
- export interface NavigationViewEntityInternal<M extends Record<string, any>> {
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, any>> {
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, any>> {
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, CMSUrlController, SideEntityController } from "@rebasepro/types";
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, any>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>): boolean;
3
- export declare function canEditEntity<M extends Record<string, any>, 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, any>, 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, any>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>, path: string, entity: Entity<M> | null): boolean;
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 object>(collection: EntityCollection<M>): string | undefined;
2
+ export declare function getEntityImagePreviewPropertyKey<M extends Record<string, unknown>>(collection: EntityCollection<M>): string | undefined;
@@ -1,10 +1,10 @@
1
- import { EntityCollection, Property, Relation } from "@rebasepro/types";
2
- export declare function sanitizeRelation(relation: Partial<Relation>, sourceCollection: EntityCollection): Relation;
3
- export declare function resolveCollectionRelations(collection: EntityCollection): Record<string, Relation>;
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: EntityCollection;
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, CustomizationController, EntityAction, EntityCollection, EntityCustomView, EnumValueConfig, EnumValues, NumberProperty, Properties, Property, PropertyConfig, Relation, RelationProperty, StringProperty } from "@rebasepro/types";
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, any> = any> = {
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, any> = any>(props: ResolvePropertyProps<M>): Property | null;
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, any>>({ propertyKey, properties, ignoreMissingFields, ...props }: {
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 resolveEntityView(entityView: string | EntityCustomView<any>, contextEntityViews?: EntityCustomView<any>[]): EntityCustomView<any> | undefined;
68
- export declare function resolveEntityAction<M extends Record<string, any>>(entityAction: string | EntityAction<M>, contextEntityActions?: EntityAction<M>[]): EntityAction<M> | undefined;
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 {};
@@ -1,5 +1,5 @@
1
1
  import { ArrayProperty, EntityValues, StorageConfig, StringProperty, UploadedFileContext } from "@rebasepro/types";
2
- interface ResolveFilenameStringParams<M extends object> {
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 object>({ input, storage, values, entityId, path, property, file, propertyKey }: ResolveFilenameStringParams<M>): Promise<string>;
13
- interface ResolveStoragePathStringParams<M extends object> {
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 object>({ input, storage, values, entityId, path, property, file, propertyKey }: ResolveStoragePathStringParams<M>): string;
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.2",
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/rebaseco/rebase.git",
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-s build",
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": "^0.0.1-canary.2",
54
- "fast-equals": "5.3.0"
55
- },
56
- "peerDependencies": {
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": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
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, removeFunctions, resolveCollectionRelations } from "../util";
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 collectionsByDbPath = new Map<string, EntityCollection>();
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 rawCollectionsByDbPath = new Map<string, EntityCollection>();
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.collectionsByDbPath.clear();
43
+ this.collectionsByTableName.clear();
39
44
  this.collectionsBySlug.clear();
40
45
  this.rootCollections = [];
41
46
 
42
- this.rawCollectionsByDbPath.clear();
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
- normalizedCollections.forEach((c, index) => this.register(c, collections[index]));
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.collectionsByDbPath.has(collection.dbPath)) {
122
+ if (this.collectionsByTableName.has(getTableName(collection))) {
87
123
  return;
88
124
  }
89
125
 
90
126
  const normalizedCollection = this.normalizeCollection(collection);
91
- this.collectionsByDbPath.set(normalizedCollection.dbPath, normalizedCollection);
92
- this.rawCollectionsByDbPath.set(rawCollection.dbPath, rawCollection);
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 properties: Properties = this.normalizeProperties(collection.properties, collection.relations ?? []);
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
- if (newProperty.of) {
133
- newProperty.of = this.normalizeProperty(newProperty.of, relations);
134
- } else if (newProperty.oneOf && newProperty.oneOf.properties) {
135
- newProperty.oneOf.properties = this.normalizeProperties(newProperty.oneOf.properties, relations);
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 dbPath lookup
162
- return this.collectionsByDbPath.get(path);
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.rawCollectionsByDbPath.get(path);
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 || currentCollection.dbPath}'`);
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.collectionsByDbPath.values());
287
+ return Array.from(this.collectionsByTableName.values());
226
288
  }
227
289
 
228
290
  getRawCollections(): EntityCollection[] {
229
- return Array.from(this.rawCollectionsByDbPath.values());
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.subcollections?.();
271
- if (!subcollections) {
272
- throw new Error(`No subcollections found for ${currentCollection.slug || currentCollection.dbPath} in path: ${path}`);
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 || currentCollection.dbPath}`);
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
- subcollections: subcollectionsA,
309
- ...restA
310
- } = a;
311
- const {
312
- subcollections: subcollectionsB,
313
- ...restB
314
- } = b;
315
- if (!areCollectionListsEqual(subcollectionsA?.() ?? [], subcollectionsB?.() ?? [])) {
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));