@rebasepro/sdk-generator 0.2.1 → 0.2.4
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/common/src/collections/default-collections.d.ts +12 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/query_builder.d.ts +51 -0
- package/dist/common/src/index.d.ts +1 -0
- package/dist/common/src/util/permissions.d.ts +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +3 -0
- package/dist/index.es.js.map +1 -1
- package/dist/types/src/controllers/auth.d.ts +2 -24
- package/dist/types/src/controllers/client.d.ts +0 -3
- package/dist/types/src/controllers/collection_registry.d.ts +1 -1
- package/dist/types/src/controllers/data.d.ts +21 -0
- package/dist/types/src/controllers/data_driver.d.ts +18 -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 +2 -4
- 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 +2 -2
- package/dist/types/src/types/translations.d.ts +28 -12
- package/dist/types/src/types/user_management_delegate.d.ts +6 -4
- package/dist/types/src/users/roles.d.ts +0 -8
- package/package.json +11 -6
- package/src/generate-types.ts +5 -5
- package/src/utils.ts +3 -0
- package/test/sdk-generator.test.ts +456 -40
- package/src/json-logic-js.d.ts +0 -8
|
@@ -105,6 +105,12 @@ export interface RebaseTranslations {
|
|
|
105
105
|
navigation_drawer: string;
|
|
106
106
|
collapse: string;
|
|
107
107
|
expand: string;
|
|
108
|
+
/** Tooltip for the language switcher in the drawer footer */
|
|
109
|
+
change_language?: string;
|
|
110
|
+
/** Tooltip for the theme toggle in the drawer footer */
|
|
111
|
+
toggle_theme?: string;
|
|
112
|
+
/** Aria label for the user menu trigger in the drawer footer */
|
|
113
|
+
user_menu?: string;
|
|
108
114
|
error: string;
|
|
109
115
|
error_uploading_file: string;
|
|
110
116
|
error_deleting: string;
|
|
@@ -426,18 +432,28 @@ export interface RebaseTranslations {
|
|
|
426
432
|
deleted: string;
|
|
427
433
|
select_reference: string;
|
|
428
434
|
select_references: string;
|
|
429
|
-
account_settings
|
|
430
|
-
profile
|
|
431
|
-
sessions
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
435
|
+
account_settings?: string;
|
|
436
|
+
profile?: string;
|
|
437
|
+
sessions?: string;
|
|
438
|
+
security?: string;
|
|
439
|
+
change_password?: string;
|
|
440
|
+
current_password?: string;
|
|
441
|
+
new_password?: string;
|
|
442
|
+
confirm_password?: string;
|
|
443
|
+
password_changed?: string;
|
|
444
|
+
passwords_dont_match?: string;
|
|
445
|
+
password_too_short?: string;
|
|
446
|
+
password_change_not_available?: string;
|
|
447
|
+
changing_password?: string;
|
|
448
|
+
display_name?: string;
|
|
449
|
+
photo_url?: string;
|
|
450
|
+
save_profile?: string;
|
|
451
|
+
saving?: string;
|
|
452
|
+
no_active_sessions?: string;
|
|
453
|
+
revoking?: string;
|
|
454
|
+
revoke_all_sessions?: string;
|
|
455
|
+
unknown_device?: string;
|
|
456
|
+
current?: string;
|
|
441
457
|
role_id: string;
|
|
442
458
|
role_name: string;
|
|
443
459
|
add_reference: string;
|
|
@@ -104,15 +104,17 @@ export interface UserManagementDelegate<USER extends User = User> {
|
|
|
104
104
|
* If true, the UI will allow the user to create the default roles (admin, editor, viewer).
|
|
105
105
|
*/
|
|
106
106
|
allowDefaultRolesCreation?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Should collection config permissions be included?
|
|
109
|
-
*/
|
|
110
|
-
includeCollectionConfigPermissions?: boolean;
|
|
111
107
|
/**
|
|
112
108
|
* Optionally define roles for a given user. This is useful when the roles
|
|
113
109
|
* are coming from a separate provider than the one issuing the tokens.
|
|
114
110
|
*/
|
|
115
111
|
defineRolesFor?: (user: USER) => Promise<Role[] | undefined> | Role[] | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Whether any admin users exist. Used by the bootstrap banner to decide
|
|
114
|
+
* whether to prompt. Populated via a lightweight check (e.g. `limit=1`
|
|
115
|
+
* query) instead of loading all users.
|
|
116
|
+
*/
|
|
117
|
+
hasAdminUsers?: boolean;
|
|
116
118
|
/**
|
|
117
119
|
* Optional function to bootstrap an admin user.
|
|
118
120
|
* Often used when the database is empty.
|
|
@@ -11,12 +11,4 @@ export type Role = {
|
|
|
11
11
|
* If this flag is true, the user can perform any action
|
|
12
12
|
*/
|
|
13
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
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/sdk-generator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Generate a typed JS SDK from Rebase collection definitions",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "rebase.pro",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@rebasepro/common": "0.2.
|
|
23
|
-
"@rebasepro/types": "0.2.
|
|
22
|
+
"@rebasepro/common": "0.2.4",
|
|
23
|
+
"@rebasepro/types": "0.2.4"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@jest/globals": "^29.7.0",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"ts-jest": "^29.4.10",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vite": "^7.3.3",
|
|
33
|
-
"@rebasepro/common": "0.2.
|
|
34
|
-
"@rebasepro/types": "0.2.
|
|
33
|
+
"@rebasepro/common": "0.2.4",
|
|
34
|
+
"@rebasepro/types": "0.2.4"
|
|
35
35
|
},
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
@@ -42,7 +42,12 @@
|
|
|
42
42
|
},
|
|
43
43
|
"gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@rebasepro/client": "0.2.
|
|
45
|
+
"@rebasepro/client": "0.2.4"
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/rebasepro/rebase.git",
|
|
50
|
+
"directory": "packages/sdk-generator"
|
|
46
51
|
},
|
|
47
52
|
"scripts": {
|
|
48
53
|
"test": "jest --config jest.config.cjs",
|
package/src/generate-types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityCollection, PostgresCollection, Property, Properties, MapProperty, ArrayProperty, RelationProperty, StringProperty, NumberProperty } from "@rebasepro/types";
|
|
1
|
+
import { EntityCollection, PostgresCollection, Property, Properties, MapProperty, ArrayProperty, Relation, RelationProperty, StringProperty, NumberProperty } from "@rebasepro/types";
|
|
2
2
|
import { resolveCollectionRelations } from "@rebasepro/common";
|
|
3
3
|
import { toPascalCase, toSafeIdentifier } from "./utils";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ function propertyToTypeScriptType(prop: Property): string {
|
|
|
8
8
|
const sp = prop as StringProperty;
|
|
9
9
|
if (sp.enum) {
|
|
10
10
|
const ids = Array.isArray(sp.enum)
|
|
11
|
-
? sp.enum.map((e:
|
|
11
|
+
? sp.enum.map((e: string | number | { id: string | number }) => typeof e === "object" ? String(e.id) : String(e))
|
|
12
12
|
: Object.keys(sp.enum);
|
|
13
13
|
return ids.map(v => `"${v}"`).join(" | ");
|
|
14
14
|
}
|
|
@@ -18,7 +18,7 @@ function propertyToTypeScriptType(prop: Property): string {
|
|
|
18
18
|
const np = prop as NumberProperty;
|
|
19
19
|
if (np.enum) {
|
|
20
20
|
const ids = Array.isArray(np.enum)
|
|
21
|
-
? np.enum.map((e:
|
|
21
|
+
? np.enum.map((e: string | number | { id: string | number }) => typeof e === "object" ? String(e.id) : String(e))
|
|
22
22
|
: Object.keys(np.enum);
|
|
23
23
|
return ids.join(" | ");
|
|
24
24
|
}
|
|
@@ -75,7 +75,7 @@ export function generateTypedefs(collections: EntityCollection[]): string {
|
|
|
75
75
|
const properties = (collection.properties ?? {}) as Properties;
|
|
76
76
|
|
|
77
77
|
// Resolve relations
|
|
78
|
-
let resolvedRelations: Record<string,
|
|
78
|
+
let resolvedRelations: Record<string, Relation> = {};
|
|
79
79
|
try {
|
|
80
80
|
resolvedRelations = resolveCollectionRelations(collection);
|
|
81
81
|
} catch { /* ignore */ }
|
|
@@ -110,7 +110,7 @@ export function generateTypedefs(collections: EntityCollection[]): string {
|
|
|
110
110
|
target = target.default || target;
|
|
111
111
|
}
|
|
112
112
|
if (target && target.properties) {
|
|
113
|
-
const idProp = Object.entries(target.properties).find(([_, p]
|
|
113
|
+
const idProp = Object.entries(target.properties).find(([_, p]) => (p as Record<string, unknown>).isId);
|
|
114
114
|
if (idProp) {
|
|
115
115
|
fkType = (idProp[1] as Property).type === "number" ? "number" : "string";
|
|
116
116
|
}
|
package/src/utils.ts
CHANGED
|
@@ -18,6 +18,9 @@ export function toPascalCase(str: string): string {
|
|
|
18
18
|
* e.g. "private_notes" → "privateNotes"
|
|
19
19
|
*/
|
|
20
20
|
export function toCamelCase(str: string): string {
|
|
21
|
+
if (!/[_\-\s]/.test(str)) {
|
|
22
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
23
|
+
}
|
|
21
24
|
const pascal = toPascalCase(str);
|
|
22
25
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
23
26
|
}
|