@rebasepro/server-postgresql 0.0.1-canary.f81da60 → 0.1.2

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 (52) hide show
  1. package/dist/index.es.js +383 -1080
  2. package/dist/index.es.js.map +1 -1
  3. package/dist/index.umd.js +314 -1011
  4. package/dist/index.umd.js.map +1 -1
  5. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +2 -1
  6. package/dist/server-postgresql/src/schema/introspect-db-inference.d.ts +5 -0
  7. package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +44 -9
  8. package/dist/server-postgresql/src/services/EntityPersistService.d.ts +9 -0
  9. package/dist/types/src/controllers/auth.d.ts +8 -2
  10. package/dist/types/src/controllers/client.d.ts +13 -0
  11. package/dist/types/src/controllers/navigation.d.ts +18 -6
  12. package/dist/types/src/controllers/registry.d.ts +9 -1
  13. package/dist/types/src/controllers/side_entity_controller.d.ts +7 -0
  14. package/dist/types/src/rebase_context.d.ts +17 -0
  15. package/dist/types/src/types/collections.d.ts +20 -1
  16. package/dist/types/src/types/component_ref.d.ts +47 -0
  17. package/dist/types/src/types/entity_views.d.ts +2 -1
  18. package/dist/types/src/types/index.d.ts +1 -0
  19. package/dist/types/src/types/properties.d.ts +15 -3
  20. package/dist/types/src/types/translations.d.ts +2 -0
  21. package/package.json +5 -5
  22. package/src/PostgresBackendDriver.ts +23 -6
  23. package/src/cli.ts +10 -2
  24. package/src/data-transformer.ts +84 -1
  25. package/src/schema/doctor.ts +14 -2
  26. package/src/schema/generate-drizzle-schema-logic.ts +52 -5
  27. package/src/schema/introspect-db-inference.ts +238 -0
  28. package/src/schema/introspect-db-logic.ts +365 -61
  29. package/src/schema/introspect-db.ts +66 -23
  30. package/src/services/EntityFetchService.ts +16 -0
  31. package/src/services/EntityPersistService.ts +88 -12
  32. package/test/generate-drizzle-schema.test.ts +295 -0
  33. package/test/introspect-db-generation.test.ts +32 -10
  34. package/test/property-ordering.test.ts +395 -0
  35. package/jest-all.log +0 -3128
  36. package/jest.log +0 -49
  37. package/scratch.ts +0 -41
  38. package/test-drizzle-bug.ts +0 -18
  39. package/test-drizzle-out/0000_cultured_freak.sql +0 -7
  40. package/test-drizzle-out/0001_tiresome_professor_monster.sql +0 -1
  41. package/test-drizzle-out/meta/0000_snapshot.json +0 -55
  42. package/test-drizzle-out/meta/0001_snapshot.json +0 -63
  43. package/test-drizzle-out/meta/_journal.json +0 -20
  44. package/test-drizzle-prompt.sh +0 -2
  45. package/test-policy-prompt.sh +0 -3
  46. package/test-programmatic.ts +0 -30
  47. package/test-programmatic2.ts +0 -59
  48. package/test-schema-no-policies.ts +0 -12
  49. package/test_drizzle_mock.js +0 -3
  50. package/test_find_changed.mjs +0 -32
  51. package/test_hash.js +0 -14
  52. package/test_output.txt +0 -3145
package/jest.log DELETED
@@ -1,49 +0,0 @@
1
-
2
- > @rebasepro/server-postgresql@0.0.1 test /Users/francesco/rebase/packages/server-postgresql
3
- > jest --passWithNoTests test/entityService.subcollection-search.test.ts
4
-
5
- console.warn
6
- Unrecognized relation format for property 'posts' in collection 'tags'
7
-
8
- 186 | const relation = (sourceCollection.relations ?? []).find((rel: Relation) => rel.relationName === property.relationName)
9
- 187 | if (!relation) {
10
- > 188 | console.warn(`Unrecognized relation format for property '${propertyKey}' in collection '${sourceCollection.slug}'`);
11
- | ^
12
- 189 | return undefined;
13
- 190 | }
14
- 191 |
15
-
16
- at resolvePropertyRelation (../common/src/util/relations.ts:188:17)
17
- at ../common/src/util/relations.ts:154:30
18
- at Array.forEach (<anonymous>)
19
- at resolveCollectionRelations (../common/src/util/relations.ts:153:47)
20
- at EntityFetchService.fetchCollectionFromPath (src/services/EntityFetchService.ts:775:65)
21
- at EntityFetchService.fetchCollection (src/services/EntityFetchService.ts:722:25)
22
- at EntityService.fetchCollection (src/services/entityService.ts:70:34)
23
- at Object.<anonymous> (test/entityService.subcollection-search.test.ts:450:40)
24
-
25
- PASS test/entityService.subcollection-search.test.ts
26
- EntityService - Subcollection Search Tests
27
- fetchCollection with subcollection search
28
- ✓ should handle search in one-to-many inverse relation subcollection (3 ms)
29
- ✓ should handle search in many-to-one owning relation subcollection (1 ms)
30
- ✓ should handle search in nested subcollection (posts/123/comments)
31
- ✓ should combine search conditions with existing filters (1 ms)
32
- ✓ should handle empty search results gracefully
33
- ✓ should handle search with ordering and pagination (1 ms)
34
- searchEntities with subcollection paths
35
- ✓ should handle direct search on subcollection using searchEntities method (1 ms)
36
- fetchRelatedEntities with search
37
- ✓ should pass search parameters correctly to fetchEntitiesUsingJoins
38
- Edge cases and error handling
39
- ✓ should handle invalid subcollection paths gracefully (15 ms)
40
- ✓ should handle missing relations gracefully (20 ms)
41
- ✓ should handle search in collection with no searchable properties
42
- Performance and optimization
43
- ✓ should use proper limit when searching (default 50 for search) (1 ms)
44
-
45
- Test Suites: 1 passed, 1 total
46
- Tests: 12 passed, 12 total
47
- Snapshots: 0 total
48
- Time: 0.276 s, estimated 1 s
49
- Ran all test suites matching /test\/entityService.subcollection-search.test.ts/i.
package/scratch.ts DELETED
@@ -1,41 +0,0 @@
1
- import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
2
- import { eq } from "drizzle-orm";
3
- import { drizzle } from "drizzle-orm/node-postgres";
4
- import { Client } from "pg";
5
- import { config } from "dotenv";
6
- config({ path: "../../.env" });
7
-
8
- const authors = pgTable("authors", {
9
- id: integer("id").primaryKey(),
10
- name: varchar("name")
11
- });
12
- const posts = pgTable("posts", {
13
- id: integer("id").primaryKey(),
14
- author_id: integer("author_id")
15
- });
16
- const profiles = pgTable("profiles", {
17
- id: integer("id").primaryKey(),
18
- author_id: integer("author_id")
19
- });
20
-
21
- async function main() {
22
- const client = new Client({
23
- connectionString: process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/postgres"
24
- });
25
- await client.connect();
26
- const db = drizzle(client);
27
-
28
- let query = db.select().from(posts);
29
- // @ts-expect-error
30
- query = query.innerJoin(authors, eq(posts.author_id, authors.id));
31
- // @ts-expect-error
32
- query = query.innerJoin(profiles, eq(authors.id, profiles.author_id));
33
-
34
- const results = await query;
35
- console.log("Drizzle Inner Join Results:");
36
- console.log(JSON.stringify(results, null, 2));
37
-
38
- await client.end();
39
- }
40
-
41
- main().catch(console.error);
@@ -1,18 +0,0 @@
1
- import { pgTable, varchar, pgPolicy } from "drizzle-orm/pg-core";
2
-
3
- export const jobs = pgTable("jobs", {
4
- id: varchar("id").primaryKey()
5
- }, (table) => ({
6
- authenticated_access: pgPolicy("authenticated_access", { as: "permissive",
7
- for: "all",
8
- to: ["public"],
9
- using: undefined }),
10
- company_insert_pending: pgPolicy("company_insert_pending3", { as: "permissive",
11
- for: "insert",
12
- to: ["public"],
13
- withCheck: undefined }),
14
- new_policy: pgPolicy("new_policy", { as: "permissive",
15
- for: "select",
16
- to: ["public"],
17
- using: undefined })
18
- }));
@@ -1,7 +0,0 @@
1
- CREATE TABLE "jobs" (
2
- "id" varchar PRIMARY KEY NOT NULL
3
- );
4
- --> statement-breakpoint
5
- ALTER TABLE "jobs" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
6
- CREATE POLICY "authenticated_access" ON "jobs" AS PERMISSIVE FOR ALL TO public;--> statement-breakpoint
7
- CREATE POLICY "company_insert_pending" ON "jobs" AS PERMISSIVE FOR INSERT TO public;
@@ -1 +0,0 @@
1
- CREATE POLICY "new_policy" ON "jobs" AS PERMISSIVE FOR SELECT TO public;
@@ -1,55 +0,0 @@
1
- {
2
- "id": "b70a1cb0-4483-4a50-a177-894a0a408be2",
3
- "prevId": "00000000-0000-0000-0000-000000000000",
4
- "version": "7",
5
- "dialect": "postgresql",
6
- "tables": {
7
- "public.jobs": {
8
- "name": "jobs",
9
- "schema": "",
10
- "columns": {
11
- "id": {
12
- "name": "id",
13
- "type": "varchar",
14
- "primaryKey": true,
15
- "notNull": true
16
- }
17
- },
18
- "indexes": {},
19
- "foreignKeys": {},
20
- "compositePrimaryKeys": {},
21
- "uniqueConstraints": {},
22
- "policies": {
23
- "authenticated_access": {
24
- "name": "authenticated_access",
25
- "as": "PERMISSIVE",
26
- "for": "ALL",
27
- "to": [
28
- "public"
29
- ]
30
- },
31
- "company_insert_pending": {
32
- "name": "company_insert_pending",
33
- "as": "PERMISSIVE",
34
- "for": "INSERT",
35
- "to": [
36
- "public"
37
- ]
38
- }
39
- },
40
- "checkConstraints": {},
41
- "isRLSEnabled": false
42
- }
43
- },
44
- "enums": {},
45
- "schemas": {},
46
- "sequences": {},
47
- "roles": {},
48
- "policies": {},
49
- "views": {},
50
- "_meta": {
51
- "columns": {},
52
- "schemas": {},
53
- "tables": {}
54
- }
55
- }
@@ -1,63 +0,0 @@
1
- {
2
- "id": "78f11b92-632c-41bd-b98a-a5429ffb2fe1",
3
- "prevId": "b70a1cb0-4483-4a50-a177-894a0a408be2",
4
- "version": "7",
5
- "dialect": "postgresql",
6
- "tables": {
7
- "public.jobs": {
8
- "name": "jobs",
9
- "schema": "",
10
- "columns": {
11
- "id": {
12
- "name": "id",
13
- "type": "varchar",
14
- "primaryKey": true,
15
- "notNull": true
16
- }
17
- },
18
- "indexes": {},
19
- "foreignKeys": {},
20
- "compositePrimaryKeys": {},
21
- "uniqueConstraints": {},
22
- "policies": {
23
- "authenticated_access": {
24
- "name": "authenticated_access",
25
- "as": "PERMISSIVE",
26
- "for": "ALL",
27
- "to": [
28
- "public"
29
- ]
30
- },
31
- "company_insert_pending": {
32
- "name": "company_insert_pending",
33
- "as": "PERMISSIVE",
34
- "for": "INSERT",
35
- "to": [
36
- "public"
37
- ]
38
- },
39
- "new_policy": {
40
- "name": "new_policy",
41
- "as": "PERMISSIVE",
42
- "for": "SELECT",
43
- "to": [
44
- "public"
45
- ]
46
- }
47
- },
48
- "checkConstraints": {},
49
- "isRLSEnabled": false
50
- }
51
- },
52
- "enums": {},
53
- "schemas": {},
54
- "sequences": {},
55
- "roles": {},
56
- "policies": {},
57
- "views": {},
58
- "_meta": {
59
- "columns": {},
60
- "schemas": {},
61
- "tables": {}
62
- }
63
- }
@@ -1,20 +0,0 @@
1
- {
2
- "version": "7",
3
- "dialect": "postgresql",
4
- "entries": [
5
- {
6
- "idx": 0,
7
- "version": "7",
8
- "when": 1777412039268,
9
- "tag": "0000_cultured_freak",
10
- "breakpoints": true
11
- },
12
- {
13
- "idx": 1,
14
- "version": "7",
15
- "when": 1777412067030,
16
- "tag": "0001_tiresome_professor_monster",
17
- "breakpoints": true
18
- }
19
- ]
20
- }
@@ -1,2 +0,0 @@
1
- cd /Users/francesco/rebase/packages/server-postgresql
2
- pnpm drizzle-kit generate
@@ -1,3 +0,0 @@
1
- cd /Users/francesco/rebase/packages/server-postgresql
2
- # Try to run db generate
3
- npx tsx src/cli.ts db generate
@@ -1,30 +0,0 @@
1
- import { generateDrizzleJson, generateMigration } from "drizzle-kit/api";
2
- import { pgTable, text } from "drizzle-orm/pg-core";
3
-
4
- const users = pgTable("users", {
5
- id: text("id").primaryKey()
6
- });
7
-
8
- async function run() {
9
- const curJson = generateDrizzleJson({ users });
10
- console.log("curJson version:", curJson.version);
11
-
12
- const prevJson = {
13
- "version": "7",
14
- "dialect": "postgresql",
15
- "tables": {},
16
- "enums": {},
17
- "schemas": {},
18
- "sequences": {},
19
- "_meta": {
20
- "schemas": {},
21
- "tables": {},
22
- "columns": {}
23
- }
24
- };
25
-
26
- const sql = await generateMigration(prevJson as any, curJson as any);
27
- console.log("SQL statements:", sql);
28
- }
29
-
30
- run().catch(console.error);
@@ -1,59 +0,0 @@
1
- import { generateDrizzleJson, generateMigration } from "drizzle-kit/api";
2
- import { pgTable, text } from "drizzle-orm/pg-core";
3
-
4
- const users = pgTable("users", {
5
- id: text("id").primaryKey()
6
- });
7
- const users2 = pgTable("users2", {
8
- id: text("id").primaryKey()
9
- });
10
-
11
- async function run() {
12
- const curJson = generateDrizzleJson({ users,
13
- users2 });
14
-
15
- const prevJson = {
16
- "id": "mock-prev",
17
- "prevId": "mock-prev-prev",
18
- "version": "7",
19
- "dialect": "postgresql",
20
- "tables": {
21
- "users": {
22
- "name": "users",
23
- "schema": "",
24
- "columns": {
25
- "id": {
26
- "name": "id",
27
- "type": "text",
28
- "primaryKey": true,
29
- "notNull": true
30
- }
31
- },
32
- "indexes": {},
33
- "foreignKeys": {},
34
- "compositePrimaryKeys": {},
35
- "uniqueConstraints": {}
36
- }
37
- },
38
- "enums": {},
39
- "schemas": {},
40
- "sequences": {},
41
- "roles": {},
42
- "policies": {},
43
- "views": {},
44
- "_meta": {
45
- "schemas": {},
46
- "tables": {},
47
- "columns": {}
48
- }
49
- };
50
-
51
- try {
52
- const sql = await generateMigration(prevJson as any, curJson as any);
53
- console.log("SQL statements:", sql);
54
- } catch (e) {
55
- console.error("Error:", e);
56
- }
57
- }
58
-
59
- run().catch(console.error);
@@ -1,12 +0,0 @@
1
- import { pgTable, varchar, integer, pgPolicy } from "drizzle-orm/pg-core";
2
- import { sql } from "drizzle-orm";
3
-
4
- export const users = pgTable("users", {
5
- id: integer("id").primaryKey(),
6
- name: varchar("name")
7
- }, (table) => ([
8
- pgPolicy("test_policy_renamed", { as: "permissive",
9
- for: "all",
10
- to: ["public"],
11
- using: sql`true` })
12
- ])).enableRLS();
@@ -1,3 +0,0 @@
1
- const { sql } = require("drizzle-orm");
2
- const q = sql`ARRAY[${sql.join(["a", "b"].map(f => sql`${f}`), sql`, `)}]::text[]`;
3
- console.log(JSON.stringify(q, null, 2));
@@ -1,32 +0,0 @@
1
- function findChangedFields(oldValues, newValues) {
2
- const changed = [];
3
- const allKeys = new Set([
4
- ...Object.keys(oldValues),
5
- ...Object.keys(newValues)
6
- ]);
7
-
8
- for (const key of allKeys) {
9
- const oldVal = oldValues[key];
10
- const newVal = newValues[key];
11
-
12
- if (key.startsWith("__")) continue;
13
-
14
- if (oldVal !== newVal) {
15
- if (
16
- typeof oldVal === "object" && oldVal !== null &&
17
- typeof newVal === "object" && newVal !== null
18
- ) {
19
- if (JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
20
- changed.push(key);
21
- }
22
- } else {
23
- changed.push(key);
24
- }
25
- }
26
- }
27
- return changed;
28
- }
29
-
30
- console.log(findChangedFields({ title: "old",
31
- tags: [{ id: 1 }] }, { title: "new",
32
- tags: [{ id: 2 }] }));
package/test_hash.js DELETED
@@ -1,14 +0,0 @@
1
- const { generateSchema } = require("./dist/schema/generate-drizzle-schema-logic");
2
-
3
- const collections1 = [{
4
- slug: "test1",
5
- table: "test_hash",
6
- name: "Test",
7
- properties: { data: { type: "string" } },
8
- securityRules: [
9
- { operation: "select",
10
- roles: ["admin", "user"] }
11
- ]
12
- }];
13
-
14
- generateSchema(collections1).then(console.log).catch(console.error);