@ai-matrx/data 0.24.0 → 0.25.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/CHANGELOG.md +12 -0
- package/bin/generate.mjs +1 -0
- package/dist/db.cjs +10 -2
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +9 -0
- package/dist/db.d.ts +9 -0
- package/dist/db.js +10 -2
- package/dist/db.js.map +1 -1
- package/package.json +2 -2
package/dist/db.d.cts
CHANGED
|
@@ -842,6 +842,12 @@ interface TableDescriptor<Row = Record<string, unknown>, Insert = Record<string,
|
|
|
842
842
|
readonly readOnlyColumns: readonly string[];
|
|
843
843
|
readonly listScope: string | null;
|
|
844
844
|
readonly realtime: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* The table has a `created_by` column. A signed-in insert that omits it is stamped with the
|
|
847
|
+
* session's person (row security on tables like `workbench.notes` refuses an insert whose
|
|
848
|
+
* `created_by` is not `auth.uid()`). Optional: descriptors generated before 0.25.0 lack it.
|
|
849
|
+
*/
|
|
850
|
+
readonly createdBy?: boolean;
|
|
845
851
|
readonly [ROW]?: {
|
|
846
852
|
row: Row;
|
|
847
853
|
insert: Insert;
|
|
@@ -903,6 +909,9 @@ interface SupabaseLike {
|
|
|
903
909
|
data: {
|
|
904
910
|
session: {
|
|
905
911
|
access_token: string;
|
|
912
|
+
user?: {
|
|
913
|
+
id: string;
|
|
914
|
+
} | null;
|
|
906
915
|
} | null;
|
|
907
916
|
};
|
|
908
917
|
}>;
|
package/dist/db.d.ts
CHANGED
|
@@ -842,6 +842,12 @@ interface TableDescriptor<Row = Record<string, unknown>, Insert = Record<string,
|
|
|
842
842
|
readonly readOnlyColumns: readonly string[];
|
|
843
843
|
readonly listScope: string | null;
|
|
844
844
|
readonly realtime: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* The table has a `created_by` column. A signed-in insert that omits it is stamped with the
|
|
847
|
+
* session's person (row security on tables like `workbench.notes` refuses an insert whose
|
|
848
|
+
* `created_by` is not `auth.uid()`). Optional: descriptors generated before 0.25.0 lack it.
|
|
849
|
+
*/
|
|
850
|
+
readonly createdBy?: boolean;
|
|
845
851
|
readonly [ROW]?: {
|
|
846
852
|
row: Row;
|
|
847
853
|
insert: Insert;
|
|
@@ -903,6 +909,9 @@ interface SupabaseLike {
|
|
|
903
909
|
data: {
|
|
904
910
|
session: {
|
|
905
911
|
access_token: string;
|
|
912
|
+
user?: {
|
|
913
|
+
id: string;
|
|
914
|
+
} | null;
|
|
906
915
|
} | null;
|
|
907
916
|
};
|
|
908
917
|
}>;
|
package/dist/db.js
CHANGED
|
@@ -995,7 +995,10 @@ async function listAll(db, table, where, opts = {}) {
|
|
|
995
995
|
({ from: lo, to: hi }) => {
|
|
996
996
|
let q = live(from(db, table).select(selectOf(opts.columns), { count: "exact" }), table, opts.includeDeleted);
|
|
997
997
|
if (where) q = where(q);
|
|
998
|
-
return ordered(q, table, opts.orderBy).range(lo, hi)
|
|
998
|
+
return Promise.resolve(ordered(q, table, opts.orderBy).range(lo, hi)).then((res) => {
|
|
999
|
+
if (res.error) throw new DatabaseError(`listAll ${qualified(table)}`, res.error);
|
|
1000
|
+
return res;
|
|
1001
|
+
});
|
|
999
1002
|
},
|
|
1000
1003
|
{
|
|
1001
1004
|
label: `listAll ${qualified(table)}`,
|
|
@@ -1041,7 +1044,12 @@ function withOrganization(db, table, values) {
|
|
|
1041
1044
|
async function insert(db, table, values) {
|
|
1042
1045
|
assertDoor(db, table, "insert");
|
|
1043
1046
|
const many = Array.isArray(values);
|
|
1044
|
-
|
|
1047
|
+
let rows = (many ? values : [values]).map((v) => withOrganization(db, table, v));
|
|
1048
|
+
if (table.createdBy && db.role === "user" && rows.some((r) => r.created_by == null) && db.client.auth) {
|
|
1049
|
+
const { data } = await db.client.auth.getSession();
|
|
1050
|
+
const person = data.session?.user?.id;
|
|
1051
|
+
if (person) rows = rows.map((r) => r.created_by == null ? { ...r, created_by: person } : r);
|
|
1052
|
+
}
|
|
1045
1053
|
const res = await from(db, table).insert(rows).select("*");
|
|
1046
1054
|
const stored = check(`insert ${qualified(table)}`, res);
|
|
1047
1055
|
return many ? stored : stored[0];
|