@rebasepro/common 0.17.3 → 0.18.1

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 (58) hide show
  1. package/README.md +4 -0
  2. package/dist/collections/CollectionRegistry.d.ts +1 -1
  3. package/dist/collections/default-collections.d.ts +15 -84
  4. package/dist/data/buildRebaseData.d.ts +1 -1
  5. package/dist/data/filter-dialect.d.ts +11 -0
  6. package/dist/data/sort-dialect.d.ts +15 -3
  7. package/dist/index.es.js +375 -63
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/util/builders.d.ts +69 -24
  10. package/dist/util/callback-errors.d.ts +77 -0
  11. package/dist/util/callback-errors.test.d.ts +1 -0
  12. package/dist/util/index.d.ts +1 -0
  13. package/dist/util/policy/evaluatePolicy.d.ts +6 -0
  14. package/dist/util/relations.d.ts +41 -0
  15. package/dist/util/table-name.test.d.ts +1 -0
  16. package/package.json +26 -22
  17. package/src/collections/CollectionRegistry.ts +0 -485
  18. package/src/collections/default-collections.ts +0 -109
  19. package/src/collections/index.ts +0 -2
  20. package/src/data/buildRebaseData.ts +0 -816
  21. package/src/data/buildRoutedRebaseData.ts +0 -103
  22. package/src/data/filter-conditions.ts +0 -46
  23. package/src/data/filter-dialect.ts +0 -737
  24. package/src/data/paginate.ts +0 -334
  25. package/src/data/query_builder.ts +0 -176
  26. package/src/data/resolveDataSource.ts +0 -135
  27. package/src/data/sort-dialect.ts +0 -237
  28. package/src/index.ts +0 -11
  29. package/src/table-classification.ts +0 -109
  30. package/src/types/json-logic-js.d.ts +0 -8
  31. package/src/util/auth-default-policies.ts +0 -215
  32. package/src/util/builders.ts +0 -82
  33. package/src/util/callbacks.ts +0 -122
  34. package/src/util/collections.ts +0 -117
  35. package/src/util/common.ts +0 -2
  36. package/src/util/conditions.ts +0 -168
  37. package/src/util/email.ts +0 -32
  38. package/src/util/entities.ts +0 -282
  39. package/src/util/enums.ts +0 -26
  40. package/src/util/identity.ts +0 -202
  41. package/src/util/index.ts +0 -21
  42. package/src/util/internal-tables.test.ts +0 -188
  43. package/src/util/internal-tables.ts +0 -197
  44. package/src/util/junction-policies.ts +0 -355
  45. package/src/util/paths.ts +0 -27
  46. package/src/util/permissions.test.ts +0 -866
  47. package/src/util/permissions.ts +0 -206
  48. package/src/util/pg-column-to-property.ts +0 -377
  49. package/src/util/policy/evaluatePolicy.ts +0 -194
  50. package/src/util/policy/index.ts +0 -4
  51. package/src/util/policy/policyToPostgres.ts +0 -263
  52. package/src/util/policy/securityRuleToConditions.ts +0 -67
  53. package/src/util/policy/sqlToPolicy.ts +0 -422
  54. package/src/util/relations.ts +0 -236
  55. package/src/util/resolutions.ts +0 -534
  56. package/src/util/resolve-relation.ts +0 -243
  57. package/src/util/storage.ts +0 -177
  58. package/src/util/string-column-length.ts +0 -31
package/README.md CHANGED
@@ -8,6 +8,10 @@ Shared utilities, collection registry, data driver adapter, and fluent query bui
8
8
  pnpm add @rebasepro/common
9
9
  ```
10
10
 
11
+ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
12
+ `import`. `require()` of it resolves only on Node 22.12+, which supports
13
+ `require(esm)`.
14
+
11
15
  ## What This Package Does
12
16
 
13
17
  `@rebasepro/common` is the lowest-level shared logic layer in the Rebase frontend stack. It provides:
@@ -9,7 +9,7 @@ export declare class CollectionRegistry {
9
9
  private dataSources;
10
10
  /**
11
11
  * Global lifecycle callbacks applied to every collection.
12
- * Runs on all data paths (REST, WebSocket, `rebase.data`).
12
+ * Runs on all data paths (REST, WebSocket, `rebase.dataAsAdmin`).
13
13
  * Execution order: global → collection → property callbacks.
14
14
  */
15
15
  private _globalCallbacks?;
@@ -11,90 +11,21 @@
11
11
  * `config/collections/users.ts` carries the presentation for projects that want this
12
12
  * collection in their panel, which is also where it is editable.
13
13
  */
14
- export declare const defaultUsersCollection: import("@rebasepro/types").PostgresCollectionConfig<import("@rebasepro/types").InferEntityType<{
15
- readonly id: {
16
- readonly name: "ID";
17
- readonly type: "string";
18
- readonly isId: "uuid";
19
- };
20
- readonly email: {
21
- readonly name: "Email";
22
- readonly type: "string";
23
- readonly validation: {
24
- readonly required: true;
25
- readonly unique: true;
26
- };
27
- };
28
- readonly displayName: {
29
- readonly name: "Name";
30
- readonly type: "string";
31
- readonly columnName: "display_name";
32
- readonly validation: {
33
- readonly required: true;
34
- };
35
- };
36
- readonly photoURL: {
37
- readonly name: "Photo URL";
38
- readonly type: "string";
39
- readonly columnName: "photo_url";
40
- };
41
- readonly roles: {
42
- readonly name: "Roles";
43
- readonly type: "array";
44
- readonly columnType: "text[]";
45
- readonly of: {
46
- readonly name: "Role";
47
- readonly type: "string";
48
- readonly enum: {
49
- readonly admin: "Admin";
50
- readonly editor: "Editor";
51
- readonly viewer: "Viewer";
52
- };
53
- };
54
- };
55
- readonly passwordHash: {
56
- readonly name: "Password Hash";
57
- readonly type: "string";
58
- readonly columnName: "password_hash";
59
- readonly excludeFromApi: true;
60
- };
61
- readonly emailVerified: {
62
- readonly name: "Email Verified";
63
- readonly type: "boolean";
64
- readonly columnName: "email_verified";
65
- readonly defaultValue: false;
66
- };
67
- readonly emailVerificationToken: {
68
- readonly name: "Email Verification Token";
69
- readonly type: "string";
70
- readonly columnName: "email_verification_token";
71
- readonly excludeFromApi: true;
72
- };
73
- readonly emailVerificationSentAt: {
74
- readonly name: "Email Verification Sent At";
75
- readonly type: "date";
76
- readonly columnName: "email_verification_sent_at";
77
- };
78
- readonly metadata: {
79
- readonly name: "Metadata";
80
- readonly type: "map";
81
- readonly keyValue: true;
82
- readonly properties: {};
83
- readonly defaultValue: {};
84
- };
85
- readonly createdAt: {
86
- readonly name: "Created At";
87
- readonly type: "date";
88
- readonly columnName: "created_at";
89
- readonly autoValue: "on_create";
90
- };
91
- readonly updatedAt: {
92
- readonly name: "Updated At";
93
- readonly type: "date";
94
- readonly columnName: "updated_at";
95
- readonly autoValue: "on_update";
96
- };
97
- }>, import("@rebasepro/types").User> & {
14
+ export declare const defaultUsersCollection: import("@rebasepro/types").PostgresCollectionConfig<{
15
+ email: string;
16
+ displayName: string;
17
+ } & {
18
+ id?: string | undefined;
19
+ metadata?: import("@rebasepro/types").InferEntityType<{}> | undefined;
20
+ photoURL?: string | undefined;
21
+ roles?: string[] | undefined;
22
+ passwordHash?: string | undefined;
23
+ emailVerified?: boolean | undefined;
24
+ emailVerificationToken?: string | undefined;
25
+ emailVerificationSentAt?: Date | undefined;
26
+ createdAt?: Date | undefined;
27
+ updatedAt?: Date | undefined;
28
+ }, import("@rebasepro/types").User> & {
98
29
  properties: {
99
30
  readonly id: {
100
31
  readonly name: "ID";
@@ -57,7 +57,7 @@ export declare function wrapAsSdkData(entityData: RebaseData): RebaseSdkData;
57
57
  * Build a flat {@link RebaseSdkData} from a `DataDriver`.
58
58
  *
59
59
  * This is the developer-facing SDK data layer used by backend framework
60
- * callbacks & scripts (`context.data` / `rebase.data`). It returns flat rows —
60
+ * callbacks & scripts (`context.data` / `rebase.dataAsAdmin`). It returns flat rows —
61
61
  * identical in shape to the frontend SDK client, down to how a relation is
62
62
  * served: a foreign key stays a foreign key, and a relation named in `include`
63
63
  * arrives as the target's own columns. The `{ __type: "relation" }` envelope is
@@ -105,10 +105,21 @@ export declare function deserializeFilter(query: Record<string, unknown>): Filte
105
105
  /**
106
106
  * Serialize a `LogicalCondition` or `FilterCondition` to its wire-format string.
107
107
  *
108
+ * Leaf encoding is {@link serializeOperatorAndValue}, the same function
109
+ * `serializeTuple` uses, so `null`, the empty list and an unknown operator
110
+ * behave identically inside a group and in a query parameter.
111
+ *
112
+ * @throws {TypeError} when a leaf names an operator this dialect does not have.
113
+ * It used to fall back to `eq`, which turned `age >= 18` into `age = 18` with
114
+ * no diagnostic anywhere.
115
+ *
108
116
  * @example
109
117
  * serializeLogicalCondition({ column: "status", operator: "==", value: "active" })
110
118
  * // → "status.eq.active"
111
119
  *
120
+ * serializeLogicalCondition({ column: "deleted_at", operator: "==", value: null })
121
+ * // → "deleted_at.isnull.null"
122
+ *
112
123
  * serializeLogicalCondition({ type: "or", conditions: [...] })
113
124
  * // → "or(status.eq.active,status.eq.pending)"
114
125
  */
@@ -98,17 +98,29 @@ export declare function serializeOrderBy(orderBy?: OrderBySpec | string): string
98
98
  /**
99
99
  * Deserialize a wire-format `"field:direction"` string into an {@link OrderByTuple}.
100
100
  *
101
- * Lenient parsing (matches existing server behaviour):
101
+ * Lenient parsing:
102
102
  * - Bare field name (no colon): `"name"` → `["name", "asc"]`
103
103
  * - Unknown direction: `"name:foo"` → `["name", "asc"]`
104
- * - Empty / falsy input: → `undefined`
104
+ * - Empty / falsy input, or a blank field name: → `undefined`
105
+ *
106
+ * The leniency is this end's alone; the *server* refuses the same value. This
107
+ * used to say "matches existing server behaviour", and it stopped being true
108
+ * when `parseOrderByParam` grew a strict direction check: `?orderBy=name:foo`
109
+ * now answers `400 INVALID_ORDER_BY` ("entry 0 has direction 'foo'"). The split
110
+ * is deliberate — see {@link parseOrderBySpecStrict} — because a value this
111
+ * function is handed was produced by {@link serializeOrderBy} a moment earlier,
112
+ * and one that reaches the server came from a stranger.
113
+ *
114
+ * A blank field is `undefined` rather than `[" ", "asc"]`: whitespace is not a
115
+ * field name, and the tuple it used to produce could not be re-encoded — the
116
+ * only value in this codec that survived a decode and failed the next encode.
105
117
  *
106
118
  * Reads the single-key shorthand only. For a value that may carry several keys,
107
119
  * use {@link deserializeOrderByList} — handed a JSON array this returns the
108
120
  * whole array as one nonsensical field name.
109
121
  *
110
122
  * @param raw - The wire-format string from an HTTP query parameter.
111
- * @returns The canonical tuple, or `undefined` if the input is empty/falsy.
123
+ * @returns The canonical tuple, or `undefined` if the input names no field.
112
124
  */
113
125
  export declare function deserializeOrderBy(raw?: string): OrderByTuple | undefined;
114
126
  /**