@zeroxsolutions/db 9.2.0 → 9.3.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 9.3.1 (2026-09-29)
2
+
3
+ This was a version bump only for @zeroxsolutions/db to align it with other projects, there were no code changes.
4
+
5
+ ## 9.3.0 (2026-09-28)
6
+
7
+ ### 🚀 Features
8
+
9
+ - **db:** read a table's relationship names off the schema ([2a8045f](https://github.com/zeroxsolutions/zeroxsolutions/commit/2a8045f))
10
+
11
+ ### ❤️ Thank You
12
+
13
+ - Claude Opus 5.5 (1M context)
14
+ - Lương Văn Tú
15
+
1
16
  ## 9.2.0 (2026-09-28)
2
17
 
3
18
  ### 🚀 Features
package/README.md CHANGED
@@ -387,6 +387,10 @@ const condition = buildFilterConditions({
387
387
  `columnResolver` answers `equals` and `in` - the only two operators a relationship filter grants -
388
388
  comparing the id against the column it closes over, and throws on any other operator.
389
389
 
390
+ - `relationshipsOf(schema, '<table export>')` - the relations the schema declares on that table, as the map
391
+ `permitsFor(schema, { relationships })` takes, so a relationship filter names a relation the schema holds.
392
+ Throws on a key that is no table export (a table's SQL name is not one).
393
+
390
394
  ### Order Builder
391
395
 
392
396
  ```ts
@@ -3,5 +3,6 @@ export * from './constants.js';
3
3
  export * from './filter.js';
4
4
  export * from './include.js';
5
5
  export * from './omit.js';
6
+ export * from './relationships.js';
6
7
  export * from './table-query.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
@@ -3,4 +3,5 @@ export * from './constants.js';
3
3
  export * from './filter.js';
4
4
  export * from './include.js';
5
5
  export * from './omit.js';
6
+ export * from './relationships.js';
6
7
  export * from './table-query.js';
@@ -0,0 +1,14 @@
1
+ import { type ExtractTablesWithRelations } from 'drizzle-orm';
2
+ /** The relation names a schema declares on one table, as the map `permitsFor` takes for its relationship filters. */
3
+ export type RelationshipsOf<TSchema extends Record<string, unknown>, K extends keyof ExtractTablesWithRelations<TSchema>> = {
4
+ readonly [R in keyof ExtractTablesWithRelations<TSchema>[K]['relations'] & string]: Record<never, never>;
5
+ };
6
+ /**
7
+ * The relations `schema` declares on the table exported as `table`, read the way `drizzle({ schema })` reads them, so a
8
+ * relation added to the schema is a relationship a permit list can name without a second list to edit.
9
+ *
10
+ * @param table - the table's EXPORT name in `schema`, not its SQL name
11
+ * @throws Error when `table` is no table export of `schema`
12
+ */
13
+ export declare function relationshipsOf<TSchema extends Record<string, unknown>, K extends keyof ExtractTablesWithRelations<TSchema> & string>(schema: TSchema, table: K): RelationshipsOf<TSchema, K>;
14
+ //# sourceMappingURL=relationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../src/utils/relationships.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8D,KAAK,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE1H,qHAAqH;AACrH,MAAM,MAAM,eAAe,CACzB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,CAAC,SAAS,MAAM,0BAA0B,CAAC,OAAO,CAAC,IACjD;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;CAAE,CAAC;AAEjH;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,CAAC,SAAS,MAAM,0BAA0B,CAAC,OAAO,CAAC,GAAG,MAAM,EAC5D,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAKxD"}
@@ -0,0 +1,15 @@
1
+ import { createTableRelationsHelpers, extractTablesRelationalConfig } from 'drizzle-orm';
2
+ /**
3
+ * The relations `schema` declares on the table exported as `table`, read the way `drizzle({ schema })` reads them, so a
4
+ * relation added to the schema is a relationship a permit list can name without a second list to edit.
5
+ *
6
+ * @param table - the table's EXPORT name in `schema`, not its SQL name
7
+ * @throws Error when `table` is no table export of `schema`
8
+ */
9
+ export function relationshipsOf(schema, table) {
10
+ const { tables } = extractTablesRelationalConfig(schema, createTableRelationsHelpers);
11
+ const config = Object.hasOwn(tables, table) ? tables[table] : undefined;
12
+ if (!config)
13
+ throw new Error(`"${table}" is no table export of the schema.`);
14
+ return Object.fromEntries(Object.keys(config.relations).map((name) => [name, {}]));
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeroxsolutions/db",
3
- "version": "9.2.0",
3
+ "version": "9.3.1",
4
4
  "description": "Generic Drizzle toolkit - the id column and audit timestamps a table takes, a base repository, the unit-of-work and transactional outbox impls, and the filter/sort/pagination query helpers, for PostgreSQL (postgres-js) and Cloudflare D1; ships no domain schema. Shared across ZeroXSolutions services.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "tslib": "^2.3.0",
39
39
  "uuid": "^14.0.1",
40
- "@zeroxsolutions/cosmic": "0.3.4",
41
- "@zeroxsolutions/query": "0.7.0"
40
+ "@zeroxsolutions/query": "0.7.1",
41
+ "@zeroxsolutions/cosmic": "0.3.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@testcontainers/postgresql": "^12.1.0",