@rebasepro/common 0.17.3 → 0.18.0
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/README.md +4 -0
- package/dist/collections/CollectionRegistry.d.ts +1 -1
- package/dist/collections/default-collections.d.ts +15 -84
- package/dist/data/buildRebaseData.d.ts +1 -1
- package/dist/data/filter-dialect.d.ts +11 -0
- package/dist/data/sort-dialect.d.ts +15 -3
- package/dist/index.es.js +375 -63
- package/dist/index.es.js.map +1 -1
- package/dist/util/builders.d.ts +69 -24
- package/dist/util/callback-errors.d.ts +77 -0
- package/dist/util/callback-errors.test.d.ts +1 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/policy/evaluatePolicy.d.ts +6 -0
- package/dist/util/relations.d.ts +41 -0
- package/dist/util/table-name.test.d.ts +1 -0
- package/package.json +26 -22
- package/src/collections/CollectionRegistry.ts +0 -485
- package/src/collections/default-collections.ts +0 -109
- package/src/collections/index.ts +0 -2
- package/src/data/buildRebaseData.ts +0 -816
- package/src/data/buildRoutedRebaseData.ts +0 -103
- package/src/data/filter-conditions.ts +0 -46
- package/src/data/filter-dialect.ts +0 -737
- package/src/data/paginate.ts +0 -334
- package/src/data/query_builder.ts +0 -176
- package/src/data/resolveDataSource.ts +0 -135
- package/src/data/sort-dialect.ts +0 -237
- package/src/index.ts +0 -11
- package/src/table-classification.ts +0 -109
- package/src/types/json-logic-js.d.ts +0 -8
- package/src/util/auth-default-policies.ts +0 -215
- package/src/util/builders.ts +0 -82
- package/src/util/callbacks.ts +0 -122
- package/src/util/collections.ts +0 -117
- package/src/util/common.ts +0 -2
- package/src/util/conditions.ts +0 -168
- package/src/util/email.ts +0 -32
- package/src/util/entities.ts +0 -282
- package/src/util/enums.ts +0 -26
- package/src/util/identity.ts +0 -202
- package/src/util/index.ts +0 -21
- package/src/util/internal-tables.test.ts +0 -188
- package/src/util/internal-tables.ts +0 -197
- package/src/util/junction-policies.ts +0 -355
- package/src/util/paths.ts +0 -27
- package/src/util/permissions.test.ts +0 -866
- package/src/util/permissions.ts +0 -206
- package/src/util/pg-column-to-property.ts +0 -377
- package/src/util/policy/evaluatePolicy.ts +0 -194
- package/src/util/policy/index.ts +0 -4
- package/src/util/policy/policyToPostgres.ts +0 -263
- package/src/util/policy/securityRuleToConditions.ts +0 -67
- package/src/util/policy/sqlToPolicy.ts +0 -422
- package/src/util/relations.ts +0 -236
- package/src/util/resolutions.ts +0 -534
- package/src/util/resolve-relation.ts +0 -243
- package/src/util/storage.ts +0 -177
- package/src/util/string-column-length.ts +0 -31
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { RebaseData, RebaseSdkData } from "@rebasepro/types";
|
|
2
|
-
import { toSnakeCase } from "@rebasepro/utils";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The two data-layer shapes that can be routed: the Entity-shaped admin
|
|
6
|
-
* {@link RebaseData} or the flat SDK {@link RebaseSdkData}. Both expose a
|
|
7
|
-
* `.collection(slug)` accessor, which is all the router needs.
|
|
8
|
-
*/
|
|
9
|
-
export type RoutableData = RebaseData | RebaseSdkData;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Parameters for {@link buildRoutedRebaseData}.
|
|
13
|
-
*/
|
|
14
|
-
export interface RoutedRebaseDataParams<T extends RoutableData = RebaseData> {
|
|
15
|
-
/**
|
|
16
|
-
* The default data source. Handles every collection that does not
|
|
17
|
-
* resolve to an entry in `sources` (i.e. server-transport collections,
|
|
18
|
-
* which ride the Rebase client).
|
|
19
|
-
*/
|
|
20
|
-
defaultData: T;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Per-data-source instances for direct and custom transports, keyed by
|
|
24
|
-
* data-source key (e.g. `"analytics"`). Server-mediated sources are not
|
|
25
|
-
* listed here — they fall through to `defaultData`.
|
|
26
|
-
*/
|
|
27
|
-
sources: Record<string, T>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Resolve the data-source key for a given collection slug or path.
|
|
31
|
-
* Typically backed by the collection registry + `resolveDataSource`
|
|
32
|
-
* (`resolveDataSource(registry.getCollection(path), defs).key`).
|
|
33
|
-
*
|
|
34
|
-
* Return `undefined` (or a key absent from `sources`) to route to the
|
|
35
|
-
* default data source.
|
|
36
|
-
*/
|
|
37
|
-
resolveKey: (slugOrPath: string) => string | undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Build a {@link RebaseData} that routes each collection to the right
|
|
42
|
-
* backend based on its resolved data source.
|
|
43
|
-
*
|
|
44
|
-
* `.collection(path)` (and dynamic `data.products`-style access) resolves the
|
|
45
|
-
* collection's data-source key via `resolveKey` and delegates to the matching
|
|
46
|
-
* entry in `sources`, falling back to `defaultData` when there is no match.
|
|
47
|
-
* Because routing keys off the *path being accessed*, a reference widget
|
|
48
|
-
* inside a Firestore form that points at a Postgres collection is still
|
|
49
|
-
* served by Postgres — routing follows the target, not the ancestor.
|
|
50
|
-
*
|
|
51
|
-
* When `sources` is empty this returns `defaultData` untouched, so the
|
|
52
|
-
* single-driver setup keeps identical behaviour and identity (important for
|
|
53
|
-
* effect dependencies that key off the data instance).
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const data = buildRoutedRebaseData({
|
|
57
|
-
* defaultData: client.data,
|
|
58
|
-
* sources: { analytics: buildRebaseData(firestoreDriver) },
|
|
59
|
-
* resolveKey: (path) => resolveDataSource(registry.getCollection(path), defs).key
|
|
60
|
-
* });
|
|
61
|
-
* await data.products.find(); // → default (server / Postgres)
|
|
62
|
-
* await data.events.find(); // → Firestore, if `events.dataSource === "analytics"`
|
|
63
|
-
*/
|
|
64
|
-
export function buildRoutedRebaseData<T extends RoutableData = RebaseData>({
|
|
65
|
-
defaultData,
|
|
66
|
-
sources,
|
|
67
|
-
resolveKey
|
|
68
|
-
}: RoutedRebaseDataParams<T>): T {
|
|
69
|
-
|
|
70
|
-
// Fast path: nothing to route → return the default untouched (preserves
|
|
71
|
-
// referential identity for effect dependencies).
|
|
72
|
-
if (!sources || Object.keys(sources).length === 0) {
|
|
73
|
-
return defaultData;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function resolve(slugOrPath: string): T {
|
|
77
|
-
const key = resolveKey(slugOrPath);
|
|
78
|
-
if (key && sources[key]) return sources[key];
|
|
79
|
-
return defaultData;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getAccessor(slugOrPath: string) {
|
|
83
|
-
return (resolve(slugOrPath) as RoutableData).collection(slugOrPath);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const target = {
|
|
87
|
-
collection: getAccessor
|
|
88
|
-
} as unknown as T;
|
|
89
|
-
|
|
90
|
-
return new Proxy(target as object, {
|
|
91
|
-
get(_target, prop: string | symbol) {
|
|
92
|
-
if (prop === "collection") return getAccessor;
|
|
93
|
-
// Ignore Symbol properties (e.g. Symbol.toPrimitive, Symbol.iterator)
|
|
94
|
-
if (typeof prop === "symbol") return undefined;
|
|
95
|
-
// Ignore internal JS properties
|
|
96
|
-
if (prop === "then" || prop === "toJSON" || prop === "$$typeof") return undefined;
|
|
97
|
-
|
|
98
|
-
// Convert camelCase property names to snake_case slugs, mirroring
|
|
99
|
-
// buildRebaseData so dynamic access routes consistently.
|
|
100
|
-
return getAccessor(toSnakeCase(prop));
|
|
101
|
-
}
|
|
102
|
-
}) as T;
|
|
103
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `FilterValues` grammar, one level below the wire codec.
|
|
3
|
-
*
|
|
4
|
-
* A field's filter is either one `[op, value]` tuple or an **array** of them —
|
|
5
|
-
* `{ age: [[">=", 18], ["<", 65]] }` — which is what the fluent builder produces
|
|
6
|
-
* from two `.where()` calls on the same column. Reading that shape is grammar,
|
|
7
|
-
* not a driver detail, so every compiler reads it through here.
|
|
8
|
-
*
|
|
9
|
-
* It lived only inside the Postgres compiler, and the Mongo one destructured
|
|
10
|
-
* `const [op, value] = filterParam` regardless: given the array-of-tuples form
|
|
11
|
-
* `op` bound to `[">=", 18]`, no operator matched, and the condition was
|
|
12
|
-
* dropped. Both of them. A read asking for adults under 65 returned every row
|
|
13
|
-
* of the collection with a 200.
|
|
14
|
-
*
|
|
15
|
-
* @module
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import type { WhereFilterOp } from "@rebasepro/types";
|
|
19
|
-
|
|
20
|
-
/** One `[operator, value]` condition. */
|
|
21
|
-
export type FilterTuple = [WhereFilterOp, unknown];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Read one field's filter as the list of conditions it stands for.
|
|
25
|
-
*
|
|
26
|
-
* Accepts both declared shapes and normalises them to a list:
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* toFilterTuples(["==", "active"]) // [["==", "active"]]
|
|
30
|
-
* toFilterTuples([[">=", 18], ["<", 65]]) // [[">=", 18], ["<", 65]]
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* A falsy, non-array or empty param has no conditions in it — the empty list,
|
|
34
|
-
* so a caller iterating adds nothing rather than compiling a tuple of
|
|
35
|
-
* `undefined`s and logging about an operator nobody sent.
|
|
36
|
-
*/
|
|
37
|
-
export function toFilterTuples(filterParam: unknown): FilterTuple[] {
|
|
38
|
-
if (!filterParam || !Array.isArray(filterParam) || filterParam.length === 0) return [];
|
|
39
|
-
// The first element discriminates: a condition starts with an operator
|
|
40
|
-
// string, a list of conditions starts with a condition. `["in", ["a","b"]]`
|
|
41
|
-
// is one condition whose value happens to be a list.
|
|
42
|
-
if (Array.isArray(filterParam[0])) {
|
|
43
|
-
return filterParam as FilterTuple[];
|
|
44
|
-
}
|
|
45
|
-
return [filterParam as FilterTuple];
|
|
46
|
-
}
|