@rebasepro/common 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/collections/default-collections.d.ts +9 -0
- package/dist/collections/index.d.ts +1 -0
- package/dist/index.es.js +141 -0
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +141 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/util/permissions.d.ts +1 -0
- package/package.json +3 -3
- package/src/collections/default-collections.ts +106 -0
- package/src/collections/index.ts +1 -0
- package/src/data/buildRebaseData.ts +7 -1
- package/src/util/permissions.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AuthController, Entity, EntityCollection, User } from "@rebasepro/types";
|
|
2
|
+
export declare function checkOperation<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>, entity: Entity<M> | null, targetOperation: "select" | "insert" | "update" | "delete"): boolean;
|
|
2
3
|
export declare function canReadCollection<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authController: AuthController<USER>): boolean;
|
|
3
4
|
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
5
|
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;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/common",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"fast-equals": "6.0.0",
|
|
43
43
|
"json-logic-js": "^2.0.5",
|
|
44
|
-
"@rebasepro/types": "0.2.
|
|
45
|
-
"@rebasepro/utils": "0.2.
|
|
44
|
+
"@rebasepro/types": "0.2.5",
|
|
45
|
+
"@rebasepro/utils": "0.2.5"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@jest/globals": "^29.7.0",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { PostgresCollection } from "@rebasepro/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default users collection.
|
|
5
|
+
*
|
|
6
|
+
* Prepended to the developer's collections array by the admin and server.
|
|
7
|
+
* Slug-based dedup (Map keyed by slug, last-write-wins) lets developers
|
|
8
|
+
* override by defining their own collection with `slug: "users"`.
|
|
9
|
+
*/
|
|
10
|
+
export const defaultUsersCollection: PostgresCollection = {
|
|
11
|
+
name: "Users",
|
|
12
|
+
singularName: "User",
|
|
13
|
+
slug: "users",
|
|
14
|
+
table: "users",
|
|
15
|
+
schema: "rebase",
|
|
16
|
+
icon: "Users",
|
|
17
|
+
group: "Settings",
|
|
18
|
+
openEntityMode: "dialog",
|
|
19
|
+
disableDefaultActions: ["copy"],
|
|
20
|
+
sort: ["createdAt", "desc"],
|
|
21
|
+
properties: {
|
|
22
|
+
id: {
|
|
23
|
+
name: "ID",
|
|
24
|
+
type: "string",
|
|
25
|
+
isId: "uuid",
|
|
26
|
+
ui: { readOnly: true }
|
|
27
|
+
},
|
|
28
|
+
email: {
|
|
29
|
+
name: "Email",
|
|
30
|
+
type: "string",
|
|
31
|
+
validation: { required: true, unique: true }
|
|
32
|
+
},
|
|
33
|
+
displayName: {
|
|
34
|
+
name: "Name",
|
|
35
|
+
type: "string",
|
|
36
|
+
columnName: "display_name",
|
|
37
|
+
validation: { required: true }
|
|
38
|
+
},
|
|
39
|
+
photoURL: {
|
|
40
|
+
name: "Photo URL",
|
|
41
|
+
type: "string",
|
|
42
|
+
columnName: "photo_url",
|
|
43
|
+
url: "image"
|
|
44
|
+
},
|
|
45
|
+
roles: {
|
|
46
|
+
name: "Roles",
|
|
47
|
+
type: "array",
|
|
48
|
+
columnType: "text[]",
|
|
49
|
+
of: {
|
|
50
|
+
name: "Role",
|
|
51
|
+
type: "string",
|
|
52
|
+
enum: {
|
|
53
|
+
admin: "Admin",
|
|
54
|
+
editor: "Editor",
|
|
55
|
+
viewer: "Viewer"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
passwordHash: {
|
|
60
|
+
name: "Password Hash",
|
|
61
|
+
type: "string",
|
|
62
|
+
columnName: "password_hash",
|
|
63
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
64
|
+
},
|
|
65
|
+
emailVerified: {
|
|
66
|
+
name: "Email Verified",
|
|
67
|
+
type: "boolean",
|
|
68
|
+
columnName: "email_verified",
|
|
69
|
+
defaultValue: false,
|
|
70
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
71
|
+
},
|
|
72
|
+
emailVerificationToken: {
|
|
73
|
+
name: "Email Verification Token",
|
|
74
|
+
type: "string",
|
|
75
|
+
columnName: "email_verification_token",
|
|
76
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
77
|
+
},
|
|
78
|
+
emailVerificationSentAt: {
|
|
79
|
+
name: "Email Verification Sent At",
|
|
80
|
+
type: "date",
|
|
81
|
+
columnName: "email_verification_sent_at",
|
|
82
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
83
|
+
},
|
|
84
|
+
metadata: {
|
|
85
|
+
name: "Metadata",
|
|
86
|
+
type: "map",
|
|
87
|
+
defaultValue: {},
|
|
88
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
89
|
+
},
|
|
90
|
+
createdAt: {
|
|
91
|
+
name: "Created At",
|
|
92
|
+
type: "date",
|
|
93
|
+
columnName: "created_at",
|
|
94
|
+
ui: { readOnly: true }
|
|
95
|
+
},
|
|
96
|
+
updatedAt: {
|
|
97
|
+
name: "Updated At",
|
|
98
|
+
type: "date",
|
|
99
|
+
columnName: "updated_at",
|
|
100
|
+
autoValue: "on_update",
|
|
101
|
+
ui: { hideFromCollection: true, disabled: { hidden: true } }
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
listProperties: ["displayName", "email", "roles", "createdAt"],
|
|
105
|
+
propertiesOrder: ["id", "email", "displayName", "roles", "createdAt"]
|
|
106
|
+
};
|
package/src/collections/index.ts
CHANGED
|
@@ -190,6 +190,12 @@ values: {} as Record<string, unknown> }
|
|
|
190
190
|
});
|
|
191
191
|
},
|
|
192
192
|
|
|
193
|
+
deleteAll: driver.deleteAll
|
|
194
|
+
? async (): Promise<void> => {
|
|
195
|
+
return driver.deleteAll!(slug);
|
|
196
|
+
}
|
|
197
|
+
: undefined,
|
|
198
|
+
|
|
193
199
|
count: driver.countEntities
|
|
194
200
|
? async (params?: FindParams): Promise<number> => {
|
|
195
201
|
return driver.countEntities!({
|
|
@@ -238,7 +244,7 @@ values: {} as Record<string, unknown> }
|
|
|
238
244
|
} : undefined,
|
|
239
245
|
|
|
240
246
|
// Fluent Query Builder
|
|
241
|
-
where(column: keyof M & string, operator:
|
|
247
|
+
where(column: keyof M & string, operator: WhereFilterOp, value: unknown) {
|
|
242
248
|
return new QueryBuilder<M>(accessor).where(column, operator, value);
|
|
243
249
|
},
|
|
244
250
|
orderBy(column: keyof M & string, ascending?: "asc" | "desc") {
|
package/src/util/permissions.ts
CHANGED
|
@@ -135,7 +135,7 @@ function evaluateRule<USER extends User, M extends Record<string, unknown>>(rule
|
|
|
135
135
|
return true;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
function checkOperation<M extends Record<string, unknown>, USER extends User>(
|
|
138
|
+
export function checkOperation<M extends Record<string, unknown>, USER extends User>(
|
|
139
139
|
collection: EntityCollection<M>,
|
|
140
140
|
authController: AuthController<USER>,
|
|
141
141
|
entity: Entity<M> | null,
|