@space-arch/util-drizzle 1.7.0 → 2.0.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 CHANGED
@@ -41,20 +41,20 @@ const users = await db.select().from(usersTable);
41
41
 
42
42
  ### UUIDv7 Column Types
43
43
 
44
- Drizzle column types for UUIDv7 with automatic generation.
44
+ PostgreSQL `uuid` columns auto-filled with UUIDv7 on insert. Nullable by default — chain `.notNull()` / `.primaryKey()` as you would with drizzle's built-in `uuid()`.
45
45
 
46
46
  ```typescript
47
47
  import { pgTable } from 'drizzle-orm/pg-core';
48
- import { uuidV7, uuidV7Nullable } from '@space-arch/util-drizzle';
48
+ import { uuidV7 } from '@space-arch/util-drizzle';
49
49
 
50
50
  const users = pgTable('users', {
51
- id: uuidV7('id').primaryKey(),
52
- parentId: uuidV7Nullable('parent_id')
51
+ id: uuidV7().primaryKey(), // PK, auto-filled on insert
52
+ tenantId: uuidV7('tenant_id').notNull(), // required FK
53
+ parentId: uuidV7('parent_id'), // nullable FK
53
54
  });
54
55
  ```
55
56
 
56
- - `uuidV7()` - Not null with automatic default value generation
57
- - `uuidV7Nullable()` - Nullable without default value
57
+ The default is applied at insert time by the drizzle runtime — it does NOT emit a SQL `DEFAULT` clause in migrations. For a raw nullable uuid with no auto-default, use drizzle's built-in `uuid()` directly.
58
58
 
59
59
  ## Contributing
60
60
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("drizzle-orm/pg-core"),i=require("uuid"),d=(r,s)=>{let o=null;const u=()=>(o||(o=r(s())),o);return new Proxy({},{get(t,n){const e=u(),c=e[n];return typeof c=="function"?c.bind(e):c},getPrototypeOf(){const t=u();return Object.getPrototypeOf(t)},has(t,n){const e=u();return n in e},ownKeys(){const t=u();return Reflect.ownKeys(t)},getOwnPropertyDescriptor(t,n){const e=u();return Reflect.getOwnPropertyDescriptor(e,n)}})},a=r=>l.customType({dataType:()=>"uuid"})(r).notNull().$defaultFn(()=>i.v7()),y=r=>l.customType({dataType:()=>"uuid"})(r);exports.lazyDrizzle=d;exports.uuidV7=a;exports.uuidV7Nullable=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("drizzle-orm/pg-core"),l=require("uuid"),y=(n,i)=>{let u=null;const r=()=>(u||(u=n(i())),u);return new Proxy({},{get(t,o){const e=r(),c=e[o];return typeof c=="function"?c.bind(e):c},getPrototypeOf(){const t=r();return Object.getPrototypeOf(t)},has(t,o){const e=r();return o in e},ownKeys(){const t=r();return Reflect.ownKeys(t)},getOwnPropertyDescriptor(t,o){const e=r();return Reflect.getOwnPropertyDescriptor(e,o)}})},s=d.customType({dataType:()=>"uuid"}),g=n=>(n===void 0?s():s(n)).$defaultFn(()=>l.v7());exports.lazyDrizzle=y;exports.uuidV7=g;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { lazyDrizzle } from './lib/lazy-drizzle.js';
2
- export { uuidV7, uuidV7Nullable } from './lib/uuidv7.js';
2
+ export { uuidV7 } from './lib/uuidv7.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,37 +1,34 @@
1
- import { customType as s } from "drizzle-orm/pg-core";
2
- import { v7 as l } from "uuid";
3
- const a = (r, d) => {
1
+ import { customType as i } from "drizzle-orm/pg-core";
2
+ import { v7 as p } from "uuid";
3
+ const l = (n, d) => {
4
4
  let u = null;
5
- const o = () => (u || (u = r(d())), u);
5
+ const r = () => (u || (u = n(d())), u);
6
6
  return new Proxy({}, {
7
- get(t, n) {
8
- const e = o(), c = e[n];
7
+ get(t, o) {
8
+ const e = r(), c = e[o];
9
9
  return typeof c == "function" ? c.bind(e) : c;
10
10
  },
11
11
  getPrototypeOf() {
12
- const t = o();
12
+ const t = r();
13
13
  return Object.getPrototypeOf(t);
14
14
  },
15
- has(t, n) {
16
- const e = o();
17
- return n in e;
15
+ has(t, o) {
16
+ const e = r();
17
+ return o in e;
18
18
  },
19
19
  ownKeys() {
20
- const t = o();
20
+ const t = r();
21
21
  return Reflect.ownKeys(t);
22
22
  },
23
- getOwnPropertyDescriptor(t, n) {
24
- const e = o();
25
- return Reflect.getOwnPropertyDescriptor(e, n);
23
+ getOwnPropertyDescriptor(t, o) {
24
+ const e = r();
25
+ return Reflect.getOwnPropertyDescriptor(e, o);
26
26
  }
27
27
  });
28
- }, y = (r) => s({
28
+ }, s = i({
29
29
  dataType: () => "uuid"
30
- })(r).notNull().$defaultFn(() => l()), b = (r) => s({
31
- dataType: () => "uuid"
32
- })(r);
30
+ }), b = (n) => (n === void 0 ? s() : s(n)).$defaultFn(() => p());
33
31
  export {
34
- a as lazyDrizzle,
35
- y as uuidV7,
36
- b as uuidV7Nullable
32
+ l as lazyDrizzle,
33
+ b as uuidV7
37
34
  };
@@ -1,20 +1,30 @@
1
1
  /**
2
- * A custom type for UUIDv7 columns. Not null
2
+ * Drizzle column builder for a PostgreSQL `uuid` column auto-filled with a
3
+ * UUIDv7 on insert (via `uuid.v7()` through `$defaultFn`).
4
+ *
5
+ * Nullable by default — chain `.notNull()`, `.primaryKey()`, etc. as with
6
+ * drizzle's built-in `uuid()`.
7
+ *
8
+ * The default is applied at insert time in the application layer; it does
9
+ * NOT emit a SQL `DEFAULT` clause in migrations.
10
+ *
11
+ * Nullable-FK caveat: omitting the field on insert triggers `$defaultFn` and
12
+ * produces a UUID pointing nowhere. For a truly raw nullable uuid, use
13
+ * drizzle's built-in `uuid()` from `drizzle-orm/pg-core`.
14
+ *
15
+ * @example
16
+ * const users = pgTable('users', {
17
+ * id: uuidV7().primaryKey(), // PK, auto-filled
18
+ * tenantId: uuidV7('tenant_id').notNull(), // required FK
19
+ * parentId: uuidV7('parent_id'), // nullable FK
20
+ * });
3
21
  */
4
- export declare const uuidV7: (name: string) => import('drizzle-orm').HasRuntimeDefault<import('drizzle-orm').HasDefault<import('drizzle-orm').NotNull<import('drizzle-orm/pg-core').PgCustomColumnBuilder<import('drizzle-orm/pg-core').ConvertCustomConfig<string, {
5
- data: string;
6
- notNull: true;
7
- default: true;
8
- }>>>>>;
9
- /**
10
- * A custom type for UUIDv7 columns. Nullable
11
- */
12
- export declare const uuidV7Nullable: (name: string) => import('drizzle-orm/pg-core').PgCustomColumnBuilder<{
22
+ export declare const uuidV7: (name?: string) => import('drizzle-orm').HasRuntimeDefault<import('drizzle-orm').HasDefault<import('drizzle-orm/pg-core').PgCustomColumnBuilder<{
13
23
  name: string;
14
24
  dataType: "custom";
15
25
  columnType: "PgCustomColumn";
16
26
  data: string;
17
27
  driverParam: unknown;
18
28
  enumValues: undefined;
19
- }>;
29
+ }>>>;
20
30
  //# sourceMappingURL=uuidv7.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuidv7.d.ts","sourceRoot":"","sources":["../../src/lib/uuidv7.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM;UACd,MAAM;aAAW,IAAI;aAAW,IAAI;MAI9B,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM;;;;;;;EAGjC,CAAC"}
1
+ {"version":3,"file":"uuidv7.d.ts","sourceRoot":"","sources":["../../src/lib/uuidv7.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM;;;;;;;IAC2C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@space-arch/util-drizzle",
3
- "version": "1.7.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",