@rebasepro/sdk-generator 0.0.1-canary.000dc36

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 (89) hide show
  1. package/LICENSE +6 -0
  2. package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
  3. package/dist/common/src/collections/index.d.ts +1 -0
  4. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  5. package/dist/common/src/index.d.ts +3 -0
  6. package/dist/common/src/util/builders.d.ts +57 -0
  7. package/dist/common/src/util/callbacks.d.ts +6 -0
  8. package/dist/common/src/util/collections.d.ts +11 -0
  9. package/dist/common/src/util/common.d.ts +2 -0
  10. package/dist/common/src/util/conditions.d.ts +26 -0
  11. package/dist/common/src/util/entities.d.ts +58 -0
  12. package/dist/common/src/util/enums.d.ts +3 -0
  13. package/dist/common/src/util/index.d.ts +16 -0
  14. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  15. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  16. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  17. package/dist/common/src/util/paths.d.ts +14 -0
  18. package/dist/common/src/util/permissions.d.ts +5 -0
  19. package/dist/common/src/util/references.d.ts +2 -0
  20. package/dist/common/src/util/relations.d.ts +22 -0
  21. package/dist/common/src/util/resolutions.d.ts +72 -0
  22. package/dist/common/src/util/storage.d.ts +24 -0
  23. package/dist/index.cjs +232 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.es.js +229 -0
  26. package/dist/index.es.js.map +1 -0
  27. package/dist/sdk-generator/src/generate-types.d.ts +2 -0
  28. package/dist/sdk-generator/src/index.d.ts +19 -0
  29. package/dist/sdk-generator/src/utils.d.ts +22 -0
  30. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  31. package/dist/types/src/controllers/auth.d.ts +119 -0
  32. package/dist/types/src/controllers/client.d.ts +170 -0
  33. package/dist/types/src/controllers/collection_registry.d.ts +46 -0
  34. package/dist/types/src/controllers/customization_controller.d.ts +60 -0
  35. package/dist/types/src/controllers/data.d.ts +168 -0
  36. package/dist/types/src/controllers/data_driver.d.ts +195 -0
  37. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  38. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  39. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  40. package/dist/types/src/controllers/email.d.ts +34 -0
  41. package/dist/types/src/controllers/index.d.ts +18 -0
  42. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  43. package/dist/types/src/controllers/navigation.d.ts +213 -0
  44. package/dist/types/src/controllers/registry.d.ts +54 -0
  45. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  46. package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
  47. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  48. package/dist/types/src/controllers/storage.d.ts +171 -0
  49. package/dist/types/src/index.d.ts +4 -0
  50. package/dist/types/src/rebase_context.d.ts +105 -0
  51. package/dist/types/src/types/backend.d.ts +536 -0
  52. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  53. package/dist/types/src/types/builders.d.ts +15 -0
  54. package/dist/types/src/types/chips.d.ts +5 -0
  55. package/dist/types/src/types/collections.d.ts +857 -0
  56. package/dist/types/src/types/cron.d.ts +102 -0
  57. package/dist/types/src/types/data_source.d.ts +64 -0
  58. package/dist/types/src/types/entities.d.ts +145 -0
  59. package/dist/types/src/types/entity_actions.d.ts +98 -0
  60. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  61. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  62. package/dist/types/src/types/entity_overrides.d.ts +10 -0
  63. package/dist/types/src/types/entity_views.d.ts +59 -0
  64. package/dist/types/src/types/export_import.d.ts +21 -0
  65. package/dist/types/src/types/formex.d.ts +40 -0
  66. package/dist/types/src/types/index.d.ts +25 -0
  67. package/dist/types/src/types/locales.d.ts +4 -0
  68. package/dist/types/src/types/modify_collections.d.ts +5 -0
  69. package/dist/types/src/types/plugins.d.ts +282 -0
  70. package/dist/types/src/types/properties.d.ts +1148 -0
  71. package/dist/types/src/types/property_config.d.ts +70 -0
  72. package/dist/types/src/types/relations.d.ts +336 -0
  73. package/dist/types/src/types/slots.d.ts +262 -0
  74. package/dist/types/src/types/translations.d.ts +874 -0
  75. package/dist/types/src/types/user_management_delegate.d.ts +121 -0
  76. package/dist/types/src/types/websockets.d.ts +78 -0
  77. package/dist/types/src/users/index.d.ts +2 -0
  78. package/dist/types/src/users/roles.d.ts +22 -0
  79. package/dist/types/src/users/user.d.ts +46 -0
  80. package/jest.config.cjs +13 -0
  81. package/package.json +51 -0
  82. package/src/generate-types.ts +199 -0
  83. package/src/index.ts +71 -0
  84. package/src/json-logic-js.d.ts +8 -0
  85. package/src/utils.ts +42 -0
  86. package/test/sdk-generator.test.ts +88 -0
  87. package/test_output.log +197 -0
  88. package/tsconfig.json +26 -0
  89. package/vite.config.ts +49 -0
@@ -0,0 +1,88 @@
1
+ import { describe, it, expect } from "@jest/globals";
2
+ import { toPascalCase, toCamelCase, toSafeIdentifier, indent } from "../src/utils";
3
+ import { generateTypedefs } from "../src/generate-types";
4
+ import { generateSDK } from "../src/index";
5
+ import { EntityCollection } from "@rebasepro/types";
6
+
7
+ // ─── Test Fixtures ─────────────────────────────────────────────────
8
+
9
+ const authorsCollection = {
10
+ name: "Authors",
11
+ singularName: "Author",
12
+ slug: "authors",
13
+ table: "authors",
14
+ properties: {
15
+ id: { name: "ID",
16
+ type: "number",
17
+ isId: "increment",
18
+ validation: { required: true } },
19
+ name: { name: "Name",
20
+ type: "string",
21
+ validation: { required: true } },
22
+ email: { name: "Email",
23
+ type: "string" }
24
+ }
25
+ } as unknown as EntityCollection;
26
+
27
+ describe("Utils", () => {
28
+ describe("toPascalCase", () => {
29
+ it("converts snake_case to PascalCase", () => {
30
+ expect(toPascalCase("private_notes")).toBe("PrivateNotes");
31
+ });
32
+ it("handles already PascalCase input", () => {
33
+ expect(toPascalCase("TestEntities")).toBe("Testentities");
34
+ });
35
+ });
36
+
37
+ describe("toCamelCase", () => {
38
+ it("converts snake_case to camelCase", () => {
39
+ expect(toCamelCase("private_notes")).toBe("privateNotes");
40
+ });
41
+ });
42
+
43
+ describe("toSafeIdentifier", () => {
44
+ it("converts slugs to camelCase", () => {
45
+ expect(toSafeIdentifier("private-notes")).toBe("privateNotes");
46
+ });
47
+ });
48
+ });
49
+
50
+ describe("generateTypedefs", () => {
51
+ it("generates a typescript interface for a collection", () => {
52
+ const ts = generateTypedefs([authorsCollection]);
53
+
54
+ expect(ts).toContain("export interface Database {");
55
+ expect(ts).toContain("authors: {");
56
+
57
+ // Row Type
58
+ expect(ts).toContain("Row: {");
59
+ expect(ts).toContain("id: number;");
60
+ expect(ts).toContain("name: string;");
61
+ expect(ts).toContain("email?: string;");
62
+
63
+ // Insert Type
64
+ expect(ts).toContain("Insert: {");
65
+ expect(ts).toContain("id?: number;");
66
+ expect(ts).toContain("name: string;");
67
+ expect(ts).toContain("email?: string;");
68
+
69
+ // Update Type
70
+ expect(ts).toContain("Update: {");
71
+ expect(ts).toContain("id?: number;");
72
+ expect(ts).toContain("name?: string;");
73
+ expect(ts).toContain("email?: string;");
74
+
75
+ // Dictionary
76
+ expect(ts).toContain("export const collectionsDictionary = {");
77
+ expect(ts).toContain("authors: \"authors\",");
78
+ });
79
+ });
80
+
81
+ describe("generateSDK", () => {
82
+ it("returns an array of generated files including database.types.ts and README.md", () => {
83
+ const files = generateSDK([authorsCollection]);
84
+ expect(files.length).toBe(2);
85
+ expect(files[0].path).toBe("database.types.ts");
86
+ expect(files[1].path).toBe("README.md");
87
+ });
88
+ });
@@ -0,0 +1,197 @@
1
+
2
+ > @rebasepro/sdk-generator@0.0.1-canary.4d4fb3e test /Users/francesco/rebase/packages/sdk-generator
3
+ > jest --config jest.config.cjs -- sdk-generator.test.ts
4
+
5
+ console.log
6
+ GENERATED TS:
7
+ /**
8
+ * This file was auto-generated by Rebase.
9
+ * Do not make direct changes to the file.
10
+ */
11
+
12
+ export interface Database {
13
+ authors: {
14
+ Row: {
15
+ id: number;
16
+ name: string;
17
+ email?: string;
18
+ };
19
+ Insert: {
20
+ id?: number;
21
+ name: string;
22
+ email?: string;
23
+ };
24
+ Update: {
25
+ id?: number;
26
+ name?: string;
27
+ email?: string;
28
+ };
29
+ };
30
+ posts: {
31
+ Row: {
32
+ id: string;
33
+ title: string;
34
+ status?: "draft" | "published" | "archived";
35
+ views?: 0 | 1;
36
+ isPublished?: boolean;
37
+ createdAt?: string;
38
+ location?: { latitude: number; longitude: number; };
39
+ metadata?: { seoTitle: string; keywords: Array<string>; };
40
+ tags?: Array<string>;
41
+ author?: { id: string | number; path: string; __type: "relation"; data?: any };
42
+ };
43
+ Insert: {
44
+ id?: string;
45
+ title: string;
46
+ status?: "draft" | "published" | "archived";
47
+ views?: 0 | 1;
48
+ isPublished?: boolean;
49
+ createdAt?: string;
50
+ location?: { latitude: number; longitude: number; };
51
+ metadata?: { seoTitle: string; keywords: Array<string>; };
52
+ tags?: Array<string>;
53
+ };
54
+ Update: {
55
+ id?: string;
56
+ title?: string;
57
+ status?: "draft" | "published" | "archived";
58
+ views?: 0 | 1;
59
+ isPublished?: boolean;
60
+ createdAt?: string;
61
+ location?: { latitude: number; longitude: number; };
62
+ metadata?: { seoTitle: string; keywords: Array<string>; };
63
+ tags?: Array<string>;
64
+ };
65
+ };
66
+ }
67
+
68
+ export type CollectionName = keyof Database;
69
+ export type CollectionsDictionary = { [K in CollectionName]: K };
70
+
71
+ export const collectionsDictionary = {
72
+ authors: "authors",
73
+ posts: "posts",
74
+ } as const;
75
+
76
+ at Object.<anonymous> (test/sdk-generator.test.ts:119:17)
77
+
78
+ FAIL test/sdk-generator.test.ts
79
+ Utils
80
+ toPascalCase
81
+ ✓ converts snake_case to PascalCase (1 ms)
82
+ ✕ handles already PascalCase input (2 ms)
83
+ toCamelCase
84
+ ✓ converts snake_case to camelCase
85
+ toSafeIdentifier
86
+ ✓ converts slugs to camelCase
87
+ generateTypedefs
88
+ ✓ generates a typescript interface for a collection (1 ms)
89
+ ✕ generates correctly for all property types in a complex collection (14 ms)
90
+ generateSDK
91
+ ✓ returns an array of generated files including database.types.ts and README.md (1 ms)
92
+
93
+ ● Utils › toPascalCase › handles already PascalCase input
94
+
95
+ expect(received).toBe(expected) // Object.is equality
96
+
97
+ Expected: "Testentities"
98
+ Received: "TestEntities"
99
+
100
+ 68 | });
101
+ 69 | it("handles already PascalCase input", () => {
102
+ > 70 | expect(toPascalCase("TestEntities")).toBe("Testentities");
103
+ | ^
104
+ 71 | });
105
+ 72 | });
106
+ 73 |
107
+
108
+ at Object.<anonymous> (test/sdk-generator.test.ts:70:50)
109
+
110
+ ● generateTypedefs › generates correctly for all property types in a complex collection
111
+
112
+ expect(received).toContain(expected) // indexOf
113
+
114
+ Expected substring: "author_id: number;"
115
+ Received string: "/**
116
+ * This file was auto-generated by Rebase.
117
+ * Do not make direct changes to the file.
118
+ */·
119
+ export interface Database {
120
+ authors: {
121
+ Row: {
122
+ id: number;
123
+ name: string;
124
+ email?: string;
125
+ };
126
+ Insert: {
127
+ id?: number;
128
+ name: string;
129
+ email?: string;
130
+ };
131
+ Update: {
132
+ id?: number;
133
+ name?: string;
134
+ email?: string;
135
+ };
136
+ };
137
+ posts: {
138
+ Row: {
139
+ id: string;
140
+ title: string;
141
+ status?: \"draft\" | \"published\" | \"archived\";
142
+ views?: 0 | 1;
143
+ isPublished?: boolean;
144
+ createdAt?: string;
145
+ location?: { latitude: number; longitude: number; };
146
+ metadata?: { seoTitle: string; keywords: Array<string>; };
147
+ tags?: Array<string>;
148
+ author?: { id: string | number; path: string; __type: \"relation\"; data?: any };
149
+ };
150
+ Insert: {
151
+ id?: string;
152
+ title: string;
153
+ status?: \"draft\" | \"published\" | \"archived\";
154
+ views?: 0 | 1;
155
+ isPublished?: boolean;
156
+ createdAt?: string;
157
+ location?: { latitude: number; longitude: number; };
158
+ metadata?: { seoTitle: string; keywords: Array<string>; };
159
+ tags?: Array<string>;
160
+ };
161
+ Update: {
162
+ id?: string;
163
+ title?: string;
164
+ status?: \"draft\" | \"published\" | \"archived\";
165
+ views?: 0 | 1;
166
+ isPublished?: boolean;
167
+ createdAt?: string;
168
+ location?: { latitude: number; longitude: number; };
169
+ metadata?: { seoTitle: string; keywords: Array<string>; };
170
+ tags?: Array<string>;
171
+ };
172
+ };
173
+
174
+ export type CollectionName = keyof Database;
175
+ export type CollectionsDictionary = { [K in CollectionName]: K };·
176
+ export const collectionsDictionary = {
177
+ authors: \"authors\",
178
+ posts: \"posts\",
179
+ } as const;
180
+ "
181
+
182
+ 131 | expect(ts).toContain("metadata?: { seoTitle: string; keywords: Array<string>; };");
183
+ 132 | expect(ts).toContain("tags?: Array<string>;");
184
+ > 133 | expect(ts).toContain("author_id: number;");
185
+ | ^
186
+ 134 | expect(ts).toContain("author?: { id: string | number; path: string; __type: \"relation\"; data?: any };");
187
+ 135 |
188
+ 136 | // Insert Type
189
+
190
+ at Object.<anonymous> (test/sdk-generator.test.ts:133:20)
191
+
192
+ Test Suites: 1 failed, 1 total
193
+ Tests: 2 failed, 5 passed, 7 total
194
+ Snapshots: 0 total
195
+ Time: 0.971 s, estimated 2 s
196
+ Ran all test suites matching /sdk-generator.test.ts/i.
197
+  ELIFECYCLE  Test failed. See above for more details.
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "lib": ["ESNext"],
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "declarationDir": "./dist",
9
+ "outDir": "./dist",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "moduleResolution": "bundler",
15
+ "resolveJsonModule": true,
16
+ "jsx": "react-jsx",
17
+ "baseUrl": ".",
18
+ "paths": {
19
+ "@rebasepro/types": ["../types/src"],
20
+ "@rebasepro/common": ["../common/src"],
21
+ "@rebasepro/client": ["../client/src"]
22
+ }
23
+ },
24
+ "include": ["src/**/*"],
25
+ "exclude": ["node_modules", "dist"]
26
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,49 @@
1
+ // @ts-ignore
2
+ import path from "path";
3
+ import { defineConfig } from "vite";
4
+
5
+ const isExternal = (id: string) => {
6
+ if (id.startsWith(".") || path.isAbsolute(id)) return false;
7
+
8
+ return true;
9
+ };
10
+
11
+ export default defineConfig(() => ({
12
+ esbuild: {
13
+ logOverride: { "this-is-undefined-in-esm": "silent" }
14
+ },
15
+ build: {
16
+ lib: {
17
+ entry: path.resolve(__dirname, "src/index.ts"),
18
+ name: "RebaseSDKGenerator",
19
+ fileName: (format) => {
20
+ if (format === "es")
21
+ return `index.${format}.js`;
22
+ else if (format === "umd")
23
+ return "index.cjs";
24
+ throw new Error("Unexpected format");
25
+ }
26
+ },
27
+ minify: false,
28
+ target: "ESNEXT",
29
+ sourcemap: true,
30
+ rollupOptions: {
31
+ external: isExternal,
32
+ output: {
33
+ globals: {
34
+ "json-logic-js": "jsonLogic",
35
+ "fast-equals": "fastEquals",
36
+ "lodash/cloneDeep.js": "cloneDeep"
37
+ }
38
+ }
39
+ }
40
+ },
41
+ resolve: {
42
+ alias: {
43
+ "@rebasepro/client": path.resolve(__dirname, "../client/src"),
44
+ "@rebasepro/common": path.resolve(__dirname, "../common/src"),
45
+ "@rebasepro/types": path.resolve(__dirname, "../types/src")
46
+ }
47
+ },
48
+ plugins: []
49
+ }));