@rebasepro/plugin-data-enhancement 0.2.3 → 0.2.5
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/admin/src/collection_editor/ConfigControllerProvider.d.ts +0 -5
- package/dist/admin/src/collection_editor/index.d.ts +0 -1
- package/dist/admin/src/collection_editor/types/collection_editor_controller.d.ts +0 -2
- package/dist/admin/src/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +3 -3
- package/dist/admin/src/components/ArrayContainer.d.ts +2 -2
- package/dist/admin/src/components/DefaultAppBar.d.ts +18 -1
- package/dist/admin/src/components/DefaultDrawer.d.ts +51 -3
- package/dist/admin/src/components/EntityCollectionTable/fields/TableStorageUpload.d.ts +2 -2
- package/dist/admin/src/components/EntityCollectionTable/internal/EntityTableCell.d.ts +2 -2
- package/dist/admin/src/components/EntityCollectionTable/table_bindings.d.ts +4 -3
- package/dist/admin/src/components/EntityCollectionView/hooks/useKanbanDragAndDrop.d.ts +4 -3
- package/dist/admin/src/components/EntityEditView.d.ts +2 -1
- package/dist/admin/src/components/HomePage/HomePageDnD.d.ts +3 -3
- package/dist/admin/src/components/PropertyCollectionView.d.ts +1 -1
- package/dist/admin/src/components/PropertyIdCopyTooltip.d.ts +1 -1
- package/dist/admin/src/components/RebaseRouteDefs.d.ts +1 -1
- package/dist/admin/src/components/SelectableTable/SelectionStore.d.ts +4 -1
- package/dist/admin/src/components/SelectableTable/filters/BooleanFilterField.d.ts +2 -2
- package/dist/admin/src/components/SelectableTable/filters/DateTimeFilterField.d.ts +2 -2
- package/dist/admin/src/components/SelectableTable/filters/ReferenceFilterField.d.ts +2 -2
- package/dist/admin/src/components/SelectableTable/filters/StringNumberFilterField.d.ts +2 -2
- package/dist/admin/src/components/app/Drawer.d.ts +8 -1
- package/dist/admin/src/data_export/export/export.d.ts +3 -3
- package/dist/admin/src/editor/components/editor-bubble.d.ts +5 -1
- package/dist/admin/src/editor/components/image-bubble.d.ts +5 -1
- package/dist/admin/src/editor/components/index.d.ts +3 -3
- package/dist/admin/src/editor/components/table-bubble.d.ts +5 -1
- package/dist/admin/src/editor/nodeViews/ReactNodeView.d.ts +4 -1
- package/dist/admin/src/editor/utils/remove_classes.d.ts +1 -1
- package/dist/admin/src/form/EntityForm.d.ts +2 -2
- package/dist/admin/src/form/components/StorageUploadProgress.d.ts +2 -2
- package/dist/admin/src/form/field_bindings/MultiSelectFieldBinding.d.ts +1 -1
- package/dist/admin/src/form/field_bindings/StorageUploadFieldBinding.d.ts +1 -1
- package/dist/admin/src/form/validation.d.ts +3 -3
- package/dist/admin/src/hooks/navigation/useBuildNavigationStateController.d.ts +1 -1
- package/dist/admin/src/hooks/navigation/useResolvedCollections.d.ts +6 -0
- package/dist/admin/src/hooks/navigation/useResolvedViews.d.ts +3 -7
- package/dist/admin/src/index.d.ts +1 -3
- package/dist/admin/src/preview/components/UrlComponentPreview.d.ts +1 -0
- package/dist/admin/src/types/components/EntityFormActionsProps.d.ts +1 -1
- package/dist/admin/src/types/components/EntityFormProps.d.ts +2 -2
- package/dist/admin/src/types/fields.d.ts +1 -1
- package/dist/common/src/collections/default-collections.d.ts +9 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/util/permissions.d.ts +1 -0
- package/dist/core/src/components/LoginView/LoginView.d.ts +25 -1
- package/dist/core/src/components/common/types.d.ts +10 -7
- package/dist/core/src/components/common/useDebouncedData.d.ts +1 -1
- package/dist/core/src/core/RebaseProps.d.ts +13 -2
- package/dist/core/src/core/RebaseRouter.d.ts +1 -1
- package/dist/core/src/hooks/data/useCollectionFetch.d.ts +12 -1
- package/dist/core/src/hooks/index.d.ts +0 -1
- package/dist/core/src/util/entity_cache.d.ts +0 -5
- package/dist/core/src/util/index.d.ts +0 -2
- package/dist/core/src/util/useStorageUploadController.d.ts +2 -2
- package/dist/formex/src/utils.d.ts +2 -2
- package/dist/index.es.js +7 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +7 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/plugin-data-enhancement/src/api.d.ts +2 -2
- package/dist/plugin-data-enhancement/src/components/DataEnhancementControllerProvider.d.ts +1 -1
- package/dist/plugin-data-enhancement/src/index.d.ts +0 -1
- package/dist/plugin-data-enhancement/src/utils/suggestions.d.ts +1 -1
- package/dist/types/src/controllers/auth.d.ts +4 -26
- package/dist/types/src/controllers/client.d.ts +25 -43
- package/dist/types/src/controllers/collection_registry.d.ts +1 -1
- package/dist/types/src/controllers/data.d.ts +4 -0
- package/dist/types/src/controllers/data_driver.d.ts +23 -0
- package/dist/types/src/controllers/registry.d.ts +5 -4
- package/dist/types/src/rebase_context.d.ts +1 -1
- package/dist/types/src/types/auth_adapter.d.ts +5 -60
- package/dist/types/src/types/backend.d.ts +2 -2
- package/dist/types/src/types/backend_hooks.d.ts +2 -17
- package/dist/types/src/types/collections.d.ts +0 -4
- package/dist/types/src/types/component_ref.d.ts +1 -1
- package/dist/types/src/types/cron.d.ts +1 -1
- package/dist/types/src/types/entity_views.d.ts +1 -0
- package/dist/types/src/types/export_import.d.ts +1 -1
- package/dist/types/src/types/formex.d.ts +2 -2
- package/dist/types/src/types/properties.d.ts +9 -7
- package/dist/types/src/types/translations.d.ts +28 -12
- package/dist/types/src/types/user_management_delegate.d.ts +22 -57
- package/dist/types/src/users/index.d.ts +0 -1
- package/dist/types/src/users/user.d.ts +0 -1
- package/dist/ui/src/components/Button.d.ts +2 -2
- package/dist/ui/src/components/ErrorBoundary.d.ts +25 -3
- package/dist/ui/src/components/VirtualTable/VirtualTable.d.ts +1 -1
- package/dist/ui/src/components/VirtualTable/VirtualTableCell.d.ts +6 -6
- package/dist/ui/src/components/VirtualTable/VirtualTableHeader.d.ts +8 -8
- package/dist/ui/src/components/VirtualTable/VirtualTableHeaderRow.d.ts +1 -1
- package/dist/ui/src/components/VirtualTable/VirtualTableProps.d.ts +11 -11
- package/dist/ui/src/components/VirtualTable/VirtualTableRow.d.ts +1 -1
- package/dist/ui/src/components/VirtualTable/types.d.ts +9 -9
- package/dist/ui/src/hooks/useDebounceCallback.d.ts +1 -1
- package/dist/ui/src/util/debounce.d.ts +1 -1
- package/package.json +7 -7
- package/src/api.ts +4 -4
- package/src/components/DataEnhancementControllerProvider.tsx +10 -7
- package/src/index.ts +0 -1
- package/src/tests/strings_counter.test.ts +101 -0
- package/src/tests/suggestions.test.ts +53 -0
- package/src/tests/values.test.ts +83 -0
- package/src/utils/properties.ts +3 -3
- package/src/utils/suggestions.ts +1 -1
- package/dist/admin/src/collection_editor/types/config_permissions.d.ts +0 -19
- package/dist/admin/src/components/admin/RoleChip.d.ts +0 -4
- package/dist/admin/src/components/admin/RolesFilterSelect.d.ts +0 -2
- package/dist/admin/src/components/admin/RolesView.d.ts +0 -4
- package/dist/admin/src/components/admin/UserRolesSelectField.d.ts +0 -2
- package/dist/admin/src/components/admin/UsersView.d.ts +0 -4
- package/dist/core/src/hooks/useValidateAuthenticator.d.ts +0 -21
- package/dist/core/src/util/icon_synonyms.d.ts +0 -1
- package/dist/core/src/util/useTraceUpdate.d.ts +0 -2
- package/dist/plugin-data-enhancement/src/types/subscriptions_message_props.d.ts +0 -3
- package/dist/types/src/users/roles.d.ts +0 -22
- package/src/types/subscriptions_message_props.tsx +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { FilterFormFieldProps } from "./VirtualTableHeader";
|
|
3
|
-
export type OnRowClickParams<T extends Record<string,
|
|
3
|
+
export type OnRowClickParams<T extends Record<string, unknown>> = {
|
|
4
4
|
rowData: T;
|
|
5
5
|
rowIndex: number;
|
|
6
6
|
event: React.SyntheticEvent;
|
|
@@ -9,7 +9,7 @@ export type OnRowClickParams<T extends Record<string, any>> = {
|
|
|
9
9
|
* @see Table
|
|
10
10
|
* @group Components
|
|
11
11
|
*/
|
|
12
|
-
export interface VirtualTableProps<T extends Record<string,
|
|
12
|
+
export interface VirtualTableProps<T extends Record<string, unknown>> {
|
|
13
13
|
/**
|
|
14
14
|
* Array of arbitrary data
|
|
15
15
|
*/
|
|
@@ -61,12 +61,12 @@ export interface VirtualTableProps<T extends Record<string, any>> {
|
|
|
61
61
|
/**
|
|
62
62
|
* In case this table should have some filters set by default
|
|
63
63
|
*/
|
|
64
|
-
filter?: VirtualTableFilterValues<
|
|
64
|
+
filter?: VirtualTableFilterValues<string>;
|
|
65
65
|
/**
|
|
66
66
|
* Callback used when filters are updated
|
|
67
67
|
* @param filter
|
|
68
68
|
*/
|
|
69
|
-
onFilterUpdate?: (filter?: VirtualTableFilterValues<
|
|
69
|
+
onFilterUpdate?: (filter?: VirtualTableFilterValues<string> | undefined) => void;
|
|
70
70
|
/**
|
|
71
71
|
* Callback when the table is scrolled
|
|
72
72
|
* @param props
|
|
@@ -111,7 +111,7 @@ export interface VirtualTableProps<T extends Record<string, any>> {
|
|
|
111
111
|
* Callback to create a filter field, displayed in the header as a dropdown
|
|
112
112
|
* @param props
|
|
113
113
|
*/
|
|
114
|
-
createFilterField?: (props: FilterFormFieldProps<
|
|
114
|
+
createFilterField?: (props: FilterFormFieldProps<unknown>) => React.ReactNode;
|
|
115
115
|
/**
|
|
116
116
|
* Class name applied to the table
|
|
117
117
|
*/
|
|
@@ -141,9 +141,9 @@ export interface VirtualTableProps<T extends Record<string, any>> {
|
|
|
141
141
|
/**
|
|
142
142
|
* Extra data passed to the cell renderer
|
|
143
143
|
*/
|
|
144
|
-
extraData?:
|
|
144
|
+
extraData?: unknown;
|
|
145
145
|
}
|
|
146
|
-
export type CellRendererParams<T =
|
|
146
|
+
export type CellRendererParams<T = unknown> = {
|
|
147
147
|
column: VirtualTableColumn;
|
|
148
148
|
columns: VirtualTableColumn[];
|
|
149
149
|
columnIndex: number;
|
|
@@ -153,17 +153,17 @@ export type CellRendererParams<T = any> = {
|
|
|
153
153
|
isScrolling?: boolean;
|
|
154
154
|
sortableNodeRef?: (node: HTMLElement | null) => void;
|
|
155
155
|
sortableStyle?: React.CSSProperties;
|
|
156
|
-
sortableAttributes?: Record<string,
|
|
156
|
+
sortableAttributes?: Record<string, unknown>;
|
|
157
157
|
isDragging?: boolean;
|
|
158
158
|
isDraggable?: boolean;
|
|
159
159
|
frozen?: boolean;
|
|
160
|
-
extraData?:
|
|
160
|
+
extraData?: unknown;
|
|
161
161
|
};
|
|
162
162
|
/**
|
|
163
163
|
* @see Table
|
|
164
164
|
* @group Components
|
|
165
165
|
*/
|
|
166
|
-
export interface VirtualTableColumn<CustomProps =
|
|
166
|
+
export interface VirtualTableColumn<CustomProps = unknown> {
|
|
167
167
|
/**
|
|
168
168
|
* Data key for the cell value, could be "a.b.c"
|
|
169
169
|
*/
|
|
@@ -233,7 +233,7 @@ export type VirtualTableSort = "asc" | "desc" | undefined;
|
|
|
233
233
|
* @see Table
|
|
234
234
|
* @group Components
|
|
235
235
|
*/
|
|
236
|
-
export type VirtualTableFilterValues<Key extends string> = Partial<Record<Key, [VirtualTableWhereFilterOp,
|
|
236
|
+
export type VirtualTableFilterValues<Key extends string> = Partial<Record<Key, [VirtualTableWhereFilterOp, unknown]>>;
|
|
237
237
|
/**
|
|
238
238
|
* Filter conditions in a `Query.where()` clause are specified using the
|
|
239
239
|
* strings `<`, `<=`, `==`, `>=`, `>`, `array-contains`, `in`, and `array-contains-any`.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { VirtualTableRowProps } from "./types";
|
|
3
|
-
export declare const VirtualTableRow: React.NamedExoticComponent<VirtualTableRowProps<
|
|
3
|
+
export declare const VirtualTableRow: React.NamedExoticComponent<VirtualTableRowProps<Record<string, unknown>>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CellRendererParams, OnRowClickParams, OnVirtualTableColumnResizeParams, VirtualTableColumn, VirtualTableFilterValues, VirtualTableWhereFilterOp } from "./VirtualTableProps";
|
|
3
3
|
import { FilterFormFieldProps } from "./VirtualTableHeader";
|
|
4
|
-
export type VirtualTableRowProps<T
|
|
5
|
-
style:
|
|
4
|
+
export type VirtualTableRowProps<T extends Record<string, unknown>> = {
|
|
5
|
+
style: React.CSSProperties;
|
|
6
6
|
rowHeight: number;
|
|
7
7
|
rowData: T;
|
|
8
8
|
rowIndex: number;
|
|
9
|
-
onRowClick?: (props: OnRowClickParams<
|
|
9
|
+
onRowClick?: (props: OnRowClickParams<Record<string, unknown>>) => void;
|
|
10
10
|
children: React.ReactNode[];
|
|
11
11
|
columns: VirtualTableColumn[];
|
|
12
12
|
hoverRow?: boolean;
|
|
@@ -19,20 +19,20 @@ export type VirtualTableContextProps<T> = {
|
|
|
19
19
|
columns: VirtualTableColumn[];
|
|
20
20
|
cellRenderer: React.ComponentType<CellRendererParams<T>>;
|
|
21
21
|
currentSort: "asc" | "desc" | undefined;
|
|
22
|
-
filter?: VirtualTableFilterValues<
|
|
23
|
-
onRowClick?: (props: OnRowClickParams<
|
|
24
|
-
onColumnSort: (key: string) =>
|
|
22
|
+
filter?: VirtualTableFilterValues<string>;
|
|
23
|
+
onRowClick?: (props: OnRowClickParams<Record<string, unknown>>) => void;
|
|
24
|
+
onColumnSort: (key: string) => void;
|
|
25
25
|
onColumnResize: (params: OnVirtualTableColumnResizeParams) => void;
|
|
26
26
|
onColumnResizeEnd: (params: OnVirtualTableColumnResizeParams) => void;
|
|
27
|
-
onFilterUpdate: (column: VirtualTableColumn, filterForProperty?: [VirtualTableWhereFilterOp,
|
|
27
|
+
onFilterUpdate: (column: VirtualTableColumn, filterForProperty?: [VirtualTableWhereFilterOp, unknown]) => void;
|
|
28
28
|
sortByProperty?: string;
|
|
29
29
|
customView?: React.ReactNode;
|
|
30
30
|
hoverRow: boolean;
|
|
31
|
-
createFilterField?: (props: FilterFormFieldProps<
|
|
31
|
+
createFilterField?: (props: FilterFormFieldProps<unknown>) => React.ReactNode;
|
|
32
32
|
rowClassName?: (rowData: T) => string | undefined;
|
|
33
33
|
endAdornment?: React.ReactNode;
|
|
34
34
|
AddColumnComponent?: React.ComponentType;
|
|
35
35
|
onColumnsOrderChange?: (columns: VirtualTableColumn[]) => void;
|
|
36
36
|
draggingColumnId?: string | null;
|
|
37
|
-
extraData?:
|
|
37
|
+
extraData?: unknown;
|
|
38
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useDebounceCallback<T extends (...args: any[]) =>
|
|
1
|
+
export declare function useDebounceCallback<T extends (...args: any[]) => unknown>(callback?: T, delay?: number): T;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @ignore
|
|
3
3
|
*/
|
|
4
|
-
export declare function debounce<T extends (...args: any[]) =>
|
|
4
|
+
export declare function debounce<T extends (...args: any[]) => unknown>(func: T, wait?: number): T & Cancelable;
|
|
5
5
|
/**
|
|
6
6
|
* @ignore
|
|
7
7
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/plugin-data-enhancement",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@rebasepro/admin": "0.2.
|
|
20
|
-
"@rebasepro/common": "0.2.
|
|
21
|
-
"@rebasepro/types": "0.2.
|
|
22
|
-
"@rebasepro/
|
|
23
|
-
"@rebasepro/
|
|
24
|
-
"@rebasepro/
|
|
19
|
+
"@rebasepro/admin": "0.2.5",
|
|
20
|
+
"@rebasepro/common": "0.2.5",
|
|
21
|
+
"@rebasepro/types": "0.2.5",
|
|
22
|
+
"@rebasepro/core": "0.2.5",
|
|
23
|
+
"@rebasepro/utils": "0.2.5",
|
|
24
|
+
"@rebasepro/ui": "0.2.5"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=19.0.0",
|
package/src/api.ts
CHANGED
|
@@ -25,8 +25,8 @@ export async function enhanceDataAPIStream<M extends Record<string, unknown>>(pr
|
|
|
25
25
|
|
|
26
26
|
instructions?: string,
|
|
27
27
|
firebaseToken: string,
|
|
28
|
-
onUpdate: (suggestions: Record<string,
|
|
29
|
-
onUpdateDelta: (propertyKey: string, partialValue:
|
|
28
|
+
onUpdate: (suggestions: Record<string, string | number>) => void;
|
|
29
|
+
onUpdateDelta: (propertyKey: string, partialValue: string) => void;
|
|
30
30
|
onError: (error: Error) => void;
|
|
31
31
|
onEnd: (result: EnhancedDataResult) => void;
|
|
32
32
|
host?: string;
|
|
@@ -89,10 +89,10 @@ export async function enhanceDataAPIStream<M extends Record<string, unknown>>(pr
|
|
|
89
89
|
props.onEnd(data.data);
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
|
-
} catch (e:
|
|
92
|
+
} catch (e: unknown) {
|
|
93
93
|
console.error("str", str);
|
|
94
94
|
console.error("Error parsing stream", e);
|
|
95
|
-
props.onError(e);
|
|
95
|
+
props.onError(e instanceof Error ? e : new Error(String(e)));
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -58,7 +58,7 @@ export function DataEnhancementControllerProvider({
|
|
|
58
58
|
path,
|
|
59
59
|
collection,
|
|
60
60
|
formContext
|
|
61
|
-
}: PropsWithChildren<DataEnhancementControllerProviderProps & PluginFormActionProps
|
|
61
|
+
}: PropsWithChildren<DataEnhancementControllerProviderProps & PluginFormActionProps>) {
|
|
62
62
|
|
|
63
63
|
const [enabled, setEnabled] = useState(false);
|
|
64
64
|
const [suggestions, setSuggestions] = useState<Record<string, string | number>>({});
|
|
@@ -193,7 +193,7 @@ export function DataEnhancementControllerProvider({
|
|
|
193
193
|
}));
|
|
194
194
|
}, [properties, formContext]);
|
|
195
195
|
|
|
196
|
-
const displayNeededSubscriptionSnackbar = useCallback((projectId:
|
|
196
|
+
const displayNeededSubscriptionSnackbar = useCallback((projectId: unknown) => {
|
|
197
197
|
snackbarController.open({
|
|
198
198
|
type: "warning",
|
|
199
199
|
message: "A valid subscription is needed in order to use this function.",
|
|
@@ -207,7 +207,7 @@ export function DataEnhancementControllerProvider({
|
|
|
207
207
|
setSuggestions({});
|
|
208
208
|
}, []);
|
|
209
209
|
|
|
210
|
-
const enhance = useCallback(async (props: EnhanceParams<
|
|
210
|
+
const enhance = useCallback(async (props: EnhanceParams<Record<string, unknown>>): Promise<EnhancedDataResult | null> => {
|
|
211
211
|
|
|
212
212
|
if (!authController.user) {
|
|
213
213
|
snackbarController.open({
|
|
@@ -232,10 +232,13 @@ export function DataEnhancementControllerProvider({
|
|
|
232
232
|
const currentValues = valuesRef.current ?? {};
|
|
233
233
|
|
|
234
234
|
return new Promise((resolve, reject) => {
|
|
235
|
-
function onError(e:
|
|
235
|
+
function onError(e: unknown) {
|
|
236
236
|
setLoadingSuggestions([]);
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
const err = e instanceof Error ? e : typeof e === "object" && e !== null ? e : new Error(String(e));
|
|
238
|
+
const errorObj = err as Record<string, unknown>;
|
|
239
|
+
if (errorObj.code === "payment-required") {
|
|
240
|
+
const data = errorObj.data as Record<string, unknown> | undefined;
|
|
241
|
+
const projectId = data?.projectId;
|
|
239
242
|
displayNeededSubscriptionSnackbar(projectId);
|
|
240
243
|
} else {
|
|
241
244
|
console.error("Enhance error", e);
|
|
@@ -286,7 +289,7 @@ export function DataEnhancementControllerProvider({
|
|
|
286
289
|
enhancingInProgress.current = false;
|
|
287
290
|
}
|
|
288
291
|
}).catch(onError);
|
|
289
|
-
} catch (e:
|
|
292
|
+
} catch (e: unknown) {
|
|
290
293
|
onError(e);
|
|
291
294
|
}
|
|
292
295
|
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { countStringCharacters } from "../utils/strings_counter";
|
|
2
|
+
import type { Properties } from "@rebasepro/types";
|
|
3
|
+
|
|
4
|
+
describe("countStringCharacters", () => {
|
|
5
|
+
it("counts characters in a string property", () => {
|
|
6
|
+
const values = { title: "Hello World" };
|
|
7
|
+
const properties: Properties = {
|
|
8
|
+
title: { name: "title", type: "string" }
|
|
9
|
+
};
|
|
10
|
+
expect(countStringCharacters(values, properties)).toBe(11);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("counts characters in a number property (stringified)", () => {
|
|
14
|
+
const values = { price: 12345 };
|
|
15
|
+
const properties: Properties = {
|
|
16
|
+
price: { name: "price", type: "number" }
|
|
17
|
+
};
|
|
18
|
+
expect(countStringCharacters(values, properties)).toBe(5);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("skips disabled properties", () => {
|
|
22
|
+
const values = { title: "Hello", hidden: "Secret" };
|
|
23
|
+
const properties: Properties = {
|
|
24
|
+
title: { name: "title", type: "string" },
|
|
25
|
+
hidden: { name: "hidden", type: "string", ui: { disabled: true } }
|
|
26
|
+
};
|
|
27
|
+
expect(countStringCharacters(values, properties)).toBe(5);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("counts array of strings", () => {
|
|
31
|
+
const values = { tags: ["hello", "world", "test"] };
|
|
32
|
+
const properties: Properties = {
|
|
33
|
+
tags: {
|
|
34
|
+
name: "tags",
|
|
35
|
+
type: "array",
|
|
36
|
+
of: { name: "tag", type: "string" }
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
// "hello" (5) + "world" (5) + "test" (4) = 14
|
|
40
|
+
expect(countStringCharacters(values, properties)).toBe(14);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("recurses into map properties", () => {
|
|
44
|
+
const values = {
|
|
45
|
+
address: { city: "New York", country: "USA" }
|
|
46
|
+
};
|
|
47
|
+
const properties: Properties = {
|
|
48
|
+
address: {
|
|
49
|
+
name: "address",
|
|
50
|
+
type: "map",
|
|
51
|
+
properties: {
|
|
52
|
+
city: { name: "city", type: "string" },
|
|
53
|
+
country: { name: "country", type: "string" }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// "New York" (8) + "USA" (3) = 11
|
|
58
|
+
expect(countStringCharacters(values, properties)).toBe(11);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("returns 0 for empty values", () => {
|
|
62
|
+
const properties: Properties = {
|
|
63
|
+
title: { name: "title", type: "string" }
|
|
64
|
+
};
|
|
65
|
+
expect(countStringCharacters({}, properties)).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("handles mixed property types", () => {
|
|
69
|
+
const values = {
|
|
70
|
+
title: "Hello",
|
|
71
|
+
count: 42,
|
|
72
|
+
active: true,
|
|
73
|
+
tags: ["a", "bb"]
|
|
74
|
+
};
|
|
75
|
+
const properties: Properties = {
|
|
76
|
+
title: { name: "title", type: "string" },
|
|
77
|
+
count: { name: "count", type: "number" },
|
|
78
|
+
active: { name: "active", type: "boolean" },
|
|
79
|
+
tags: {
|
|
80
|
+
name: "tags",
|
|
81
|
+
type: "array",
|
|
82
|
+
of: { name: "tag", type: "string" }
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// "Hello" (5) + "42" (2) + "a" (1) + "bb" (2) = 10
|
|
86
|
+
expect(countStringCharacters(values, properties)).toBe(10);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("handles null values in array gracefully", () => {
|
|
90
|
+
const values = { tags: [null, "hello", null] };
|
|
91
|
+
const properties: Properties = {
|
|
92
|
+
tags: {
|
|
93
|
+
name: "tags",
|
|
94
|
+
type: "array",
|
|
95
|
+
of: { name: "tag", type: "string" }
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// null?.length = 0, "hello" = 5, null?.length = 0
|
|
99
|
+
expect(countStringCharacters(values, properties)).toBe(5);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getAppendableSuggestion } from "../utils/suggestions";
|
|
2
|
+
|
|
3
|
+
describe("getAppendableSuggestion", () => {
|
|
4
|
+
it("returns the remaining part when suggestion starts with value", () => {
|
|
5
|
+
const result = getAppendableSuggestion("Hello World", "Hello");
|
|
6
|
+
expect(result).toBe(" World");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("returns undefined when suggestion does not start with value", () => {
|
|
10
|
+
const result = getAppendableSuggestion("Goodbye World", "Hello");
|
|
11
|
+
expect(result).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("performs case-insensitive matching", () => {
|
|
15
|
+
const result = getAppendableSuggestion("Hello World", "hello");
|
|
16
|
+
expect(result).toBe(" World");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns undefined for number suggestion", () => {
|
|
20
|
+
const result = getAppendableSuggestion(42, "4");
|
|
21
|
+
expect(result).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns undefined for undefined suggestion", () => {
|
|
25
|
+
const result = getAppendableSuggestion(undefined, "hello");
|
|
26
|
+
expect(result).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("returns undefined for non-string value", () => {
|
|
30
|
+
const result = getAppendableSuggestion("Hello", 42);
|
|
31
|
+
expect(result).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("returns full suggestion when value is empty string", () => {
|
|
35
|
+
const result = getAppendableSuggestion("Hello World", "");
|
|
36
|
+
expect(result).toBe("Hello World");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("handles whitespace trimming", () => {
|
|
40
|
+
const result = getAppendableSuggestion("Hello World", "Hello");
|
|
41
|
+
expect(result).toBe(" World");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns empty string when suggestion equals value", () => {
|
|
45
|
+
const result = getAppendableSuggestion("Hello", "Hello");
|
|
46
|
+
expect(result).toBe("");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("returns undefined when value is longer than suggestion", () => {
|
|
50
|
+
const result = getAppendableSuggestion("Hi", "Hello World");
|
|
51
|
+
expect(result).toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { flatMapEntityValues } from "../utils/values";
|
|
2
|
+
|
|
3
|
+
describe("flatMapEntityValues", () => {
|
|
4
|
+
it("returns flat object unchanged", () => {
|
|
5
|
+
const values = { name: "John", age: 30 };
|
|
6
|
+
const result = flatMapEntityValues(values);
|
|
7
|
+
expect(result).toEqual({ name: "John", age: 30 });
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("flattens nested object to dot-notation keys", () => {
|
|
11
|
+
const values = {
|
|
12
|
+
address: { city: "NYC", zip: "10001" }
|
|
13
|
+
};
|
|
14
|
+
const result = flatMapEntityValues(values);
|
|
15
|
+
expect(result).toEqual({
|
|
16
|
+
"address.city": "NYC",
|
|
17
|
+
"address.zip": "10001"
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("flattens deeply nested objects", () => {
|
|
22
|
+
const values = {
|
|
23
|
+
a: { b: { c: { d: "deep" } } }
|
|
24
|
+
};
|
|
25
|
+
const result = flatMapEntityValues(values);
|
|
26
|
+
expect(result).toEqual({ "a.b.c.d": "deep" });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("returns empty object for empty input", () => {
|
|
30
|
+
expect(flatMapEntityValues({})).toEqual({});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("returns empty object for null input", () => {
|
|
34
|
+
expect(flatMapEntityValues(null as unknown as object)).toEqual({});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("returns empty object for undefined input", () => {
|
|
38
|
+
expect(flatMapEntityValues(undefined as unknown as object)).toEqual({});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("handles mixed nested and flat values", () => {
|
|
42
|
+
const values = {
|
|
43
|
+
name: "John",
|
|
44
|
+
address: { city: "NYC" },
|
|
45
|
+
active: true
|
|
46
|
+
};
|
|
47
|
+
const result = flatMapEntityValues(values);
|
|
48
|
+
expect(result).toEqual({
|
|
49
|
+
name: "John",
|
|
50
|
+
"address.city": "NYC",
|
|
51
|
+
active: true
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("handles multiple nested objects", () => {
|
|
56
|
+
const values = {
|
|
57
|
+
home: { city: "NYC" },
|
|
58
|
+
work: { city: "SF" }
|
|
59
|
+
};
|
|
60
|
+
const result = flatMapEntityValues(values);
|
|
61
|
+
expect(result).toEqual({
|
|
62
|
+
"home.city": "NYC",
|
|
63
|
+
"work.city": "SF"
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("handles numeric values in nested objects", () => {
|
|
68
|
+
const values = {
|
|
69
|
+
stats: { visits: 100, clicks: 50 }
|
|
70
|
+
};
|
|
71
|
+
const result = flatMapEntityValues(values);
|
|
72
|
+
expect(result).toEqual({
|
|
73
|
+
"stats.visits": 100,
|
|
74
|
+
"stats.clicks": 50
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("uses custom path prefix", () => {
|
|
79
|
+
const values = { name: "John" };
|
|
80
|
+
const result = flatMapEntityValues(values, "user");
|
|
81
|
+
expect(result).toEqual({ "user.name": "John" });
|
|
82
|
+
});
|
|
83
|
+
});
|
package/src/utils/properties.ts
CHANGED
|
@@ -35,7 +35,7 @@ function getSimpleProperty(property: Property): InputProperty {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function getSimplifiedProperty(property: Property, path: string, value?:
|
|
38
|
+
function getSimplifiedProperty(property: Property, path: string, value?: unknown): Record<string, InputProperty> {
|
|
39
39
|
if (isPropertyBuilder(property)) return {};
|
|
40
40
|
if (property.type === "array") {
|
|
41
41
|
|
|
@@ -115,7 +115,7 @@ function getSimplifiedProperty(property: Property, path: string, value?: any): R
|
|
|
115
115
|
if (property.properties) {
|
|
116
116
|
const mapProperties: Record<string, InputProperty> = Object.entries(property.properties)
|
|
117
117
|
.map(([key, childProperty]) => {
|
|
118
|
-
const childValue = value
|
|
118
|
+
const childValue = value && typeof value === "object" ? (value as Record<string, unknown>)[key] : undefined;
|
|
119
119
|
return getSimplifiedProperty(childProperty, key, childValue);
|
|
120
120
|
})
|
|
121
121
|
.map(o => attachPathToKeys(o, path))
|
|
@@ -149,7 +149,7 @@ function getSimplifiedProperty(property: Property, path: string, value?: any): R
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// attach a path to every key in an object
|
|
152
|
-
function attachPathToKeys(obj: Record<string,
|
|
152
|
+
function attachPathToKeys(obj: Record<string, InputProperty>, path = ""): Record<string, InputProperty> {
|
|
153
153
|
return Object.entries(obj)
|
|
154
154
|
.map(([key, value]) => {
|
|
155
155
|
const fullKey = path ? `${path}.${key}` : key;
|
package/src/utils/suggestions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function getAppendableSuggestion(suggestion: string | number | undefined, value:
|
|
1
|
+
export function getAppendableSuggestion(suggestion: string | number | undefined, value: unknown): string | undefined {
|
|
2
2
|
const suggestionIncludesValue = typeof suggestion === "string" && typeof value === "string" && suggestion.toLowerCase().trim().startsWith(value.toLowerCase().trim());
|
|
3
3
|
return (typeof value === "string" && suggestionIncludesValue)
|
|
4
4
|
? suggestion.substring(suggestion.toLowerCase().trim().indexOf(value.toLowerCase().trim()) + value.trim().length)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { EntityCollection } from "@rebasepro/types";
|
|
2
|
-
export type CollectionEditorPermissionsBuilder<USER = any, EC extends EntityCollection = EntityCollection> = (params: {
|
|
3
|
-
user: USER | null;
|
|
4
|
-
collection?: EC;
|
|
5
|
-
}) => CollectionEditorPermissions;
|
|
6
|
-
export type CollectionEditorPermissions = {
|
|
7
|
-
/**
|
|
8
|
-
* Is the user allowed to create new collections.
|
|
9
|
-
*/
|
|
10
|
-
createCollections: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Is the user allowed to modify this collection
|
|
13
|
-
*/
|
|
14
|
-
editCollections: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Is the user allowed to delete this collection
|
|
17
|
-
*/
|
|
18
|
-
deleteCollections: boolean;
|
|
19
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AuthController, Authenticator, RebaseData, StorageSource, User } from "@rebasepro/types";
|
|
2
|
-
/**
|
|
3
|
-
* This hook is used internally for validating an authenticator.
|
|
4
|
-
*
|
|
5
|
-
* @param authController
|
|
6
|
-
* @param authentication
|
|
7
|
-
* @param storageSource
|
|
8
|
-
* @param data
|
|
9
|
-
*/
|
|
10
|
-
export declare function useValidateAuthenticator<USER extends User = any>({ disabled, authController, authenticator, storageSource, data }: {
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
authController: AuthController<USER>;
|
|
13
|
-
authenticator?: boolean | Authenticator<USER>;
|
|
14
|
-
data: RebaseData;
|
|
15
|
-
storageSource: StorageSource;
|
|
16
|
-
}): {
|
|
17
|
-
canAccessMainView: boolean;
|
|
18
|
-
authLoading: boolean;
|
|
19
|
-
notAllowedError: any;
|
|
20
|
-
authVerified: boolean;
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const iconSynonyms: Record<string, string>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type Role = {
|
|
2
|
-
/**
|
|
3
|
-
* ID of the role
|
|
4
|
-
*/
|
|
5
|
-
id: string;
|
|
6
|
-
/**
|
|
7
|
-
* Name of the role
|
|
8
|
-
*/
|
|
9
|
-
name: string;
|
|
10
|
-
/**
|
|
11
|
-
* If this flag is true, the user can perform any action
|
|
12
|
-
*/
|
|
13
|
-
isAdmin?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Permissions related to editing the collections
|
|
16
|
-
*/
|
|
17
|
-
config?: {
|
|
18
|
-
createCollections?: boolean;
|
|
19
|
-
editCollections?: boolean | "own";
|
|
20
|
-
deleteCollections?: boolean | "own";
|
|
21
|
-
};
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type SubscriptionMessageProps = { projectId: string };
|