@beignet/provider-db-drizzle 0.0.24 → 0.0.25

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/sqlite/schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCpB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6B1B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuB9B,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
+ export const auditLog = sqliteTable("audit_log", {
3
+ id: text("id").primaryKey(),
4
+ action: text("action").notNull(),
5
+ actorType: text("actor_type").notNull(),
6
+ actorId: text("actor_id"),
7
+ actorDisplayName: text("actor_display_name"),
8
+ tenantId: text("tenant_id"),
9
+ tenantSlug: text("tenant_slug"),
10
+ resourceType: text("resource_type"),
11
+ resourceId: text("resource_id"),
12
+ resourceName: text("resource_name"),
13
+ outcome: text("outcome").notNull().default("success"),
14
+ requestId: text("request_id"),
15
+ traceId: text("trace_id"),
16
+ message: text("message"),
17
+ metadata: text("metadata"),
18
+ actorMetadata: text("actor_metadata"),
19
+ tenantMetadata: text("tenant_metadata"),
20
+ resourceMetadata: text("resource_metadata"),
21
+ occurredAt: text("occurred_at").notNull(),
22
+ }, (table) => ({
23
+ actionIdx: index("audit_log_action_idx").on(table.action),
24
+ actorIdx: index("audit_log_actor_idx").on(table.actorType, table.actorId),
25
+ occurredAtIdx: index("audit_log_occurred_at_idx").on(table.occurredAt),
26
+ requestIdx: index("audit_log_request_idx").on(table.requestId),
27
+ resourceIdx: index("audit_log_resource_idx").on(table.resourceType, table.resourceId),
28
+ tenantIdx: index("audit_log_tenant_idx").on(table.tenantId),
29
+ }));
30
+ export const outboxMessages = sqliteTable("outbox_messages", {
31
+ id: text("id").primaryKey(),
32
+ kind: text("kind").notNull(),
33
+ name: text("name").notNull(),
34
+ payloadJson: text("payload_json").notNull(),
35
+ status: text("status").notNull(),
36
+ attempts: integer("attempts").notNull().default(0),
37
+ maxAttempts: integer("max_attempts").notNull().default(3),
38
+ availableAt: text("available_at").notNull(),
39
+ claimedAt: text("claimed_at"),
40
+ lockedUntil: text("locked_until"),
41
+ claimToken: text("claim_token"),
42
+ deliveredAt: text("delivered_at"),
43
+ lastErrorJson: text("last_error_json"),
44
+ createdAt: text("created_at").notNull(),
45
+ updatedAt: text("updated_at").notNull(),
46
+ }, (table) => ({
47
+ availableIdx: index("outbox_messages_available_idx").on(table.status, table.availableAt),
48
+ lockedIdx: index("outbox_messages_locked_idx").on(table.status, table.lockedUntil),
49
+ }));
50
+ export const idempotencyRecords = sqliteTable("idempotency_records", {
51
+ storageKey: text("storage_key").primaryKey(),
52
+ namespace: text("namespace").notNull(),
53
+ idempotencyKey: text("idempotency_key").notNull(),
54
+ scopeKey: text("scope_key").notNull(),
55
+ fingerprint: text("fingerprint").notNull(),
56
+ status: text("status").notNull(),
57
+ resultJson: text("result_json"),
58
+ reservedAt: text("reserved_at").notNull(),
59
+ completedAt: text("completed_at"),
60
+ expiresAt: text("expires_at"),
61
+ updatedAt: text("updated_at").notNull(),
62
+ }, (table) => ({
63
+ lookupIdx: index("idempotency_records_lookup_idx").on(table.namespace, table.scopeKey, table.idempotencyKey),
64
+ expiresIdx: index("idempotency_records_expires_idx").on(table.expiresAt),
65
+ }));
66
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/sqlite/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE5E,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CACjC,WAAW,EACX;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAChC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IACvC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC;IACzB,gBAAgB,EAAE,IAAI,CAAC,oBA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AA4B,CAAC,CAAC,EAAE,CAC/C,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,WAAW,CAClB;CACF,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAC3C,qBAAqB,EACrB;IACE,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,UAAU,EAAE;IAC5C,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IACtC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IACrC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;IAC1C,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAChC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;IAC/B,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;IACzC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC;IACjC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;IAC7B,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CACxC,EACD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACV,SAAS,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC,EAAE,CACnD,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,cAAc,CACrB;IACD,UAAU,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;CACzE,CAAC,CACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beignet/provider-db-drizzle",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "description": "Drizzle ORM database providers for Beignet — typed DbPort, unit of work, audit logs, outbox, and idempotency for SQLite (libSQL/Turso), Postgres, and MySQL.",
6
6
  "exports": {
@@ -8,13 +8,25 @@
8
8
  "types": "./dist/sqlite/index.d.ts",
9
9
  "default": "./dist/sqlite/index.js"
10
10
  },
11
+ "./sqlite/schema": {
12
+ "types": "./dist/sqlite/schema.d.ts",
13
+ "default": "./dist/sqlite/schema.js"
14
+ },
11
15
  "./postgres": {
12
16
  "types": "./dist/postgres/index.d.ts",
13
17
  "default": "./dist/postgres/index.js"
14
18
  },
19
+ "./postgres/schema": {
20
+ "types": "./dist/postgres/schema.d.ts",
21
+ "default": "./dist/postgres/schema.js"
22
+ },
15
23
  "./mysql": {
16
24
  "types": "./dist/mysql/index.d.ts",
17
25
  "default": "./dist/mysql/index.js"
26
+ },
27
+ "./mysql/schema": {
28
+ "types": "./dist/mysql/schema.d.ts",
29
+ "default": "./dist/mysql/schema.js"
18
30
  }
19
31
  },
20
32
  "files": [
@@ -0,0 +1,99 @@
1
+ import {
2
+ index,
3
+ int,
4
+ longtext,
5
+ mysqlTable,
6
+ varchar,
7
+ } from "drizzle-orm/mysql-core";
8
+
9
+ export const auditLog = mysqlTable(
10
+ "audit_log",
11
+ {
12
+ id: varchar("id", { length: 255 }).primaryKey(),
13
+ action: varchar("action", { length: 255 }).notNull(),
14
+ actorType: varchar("actor_type", { length: 32 }).notNull(),
15
+ actorId: varchar("actor_id", { length: 255 }),
16
+ actorDisplayName: varchar("actor_display_name", { length: 255 }),
17
+ tenantId: varchar("tenant_id", { length: 255 }),
18
+ tenantSlug: varchar("tenant_slug", { length: 255 }),
19
+ resourceType: varchar("resource_type", { length: 255 }),
20
+ resourceId: varchar("resource_id", { length: 255 }),
21
+ resourceName: varchar("resource_name", { length: 255 }),
22
+ outcome: varchar("outcome", { length: 16 }).notNull().default("success"),
23
+ requestId: varchar("request_id", { length: 255 }),
24
+ traceId: varchar("trace_id", { length: 255 }),
25
+ message: longtext("message"),
26
+ metadata: longtext("metadata"),
27
+ actorMetadata: longtext("actor_metadata"),
28
+ tenantMetadata: longtext("tenant_metadata"),
29
+ resourceMetadata: longtext("resource_metadata"),
30
+ occurredAt: varchar("occurred_at", { length: 32 }).notNull(),
31
+ },
32
+ (table) => ({
33
+ actionIdx: index("audit_log_action_idx").on(table.action),
34
+ actorIdx: index("audit_log_actor_idx").on(table.actorType, table.actorId),
35
+ occurredAtIdx: index("audit_log_occurred_at_idx").on(table.occurredAt),
36
+ requestIdx: index("audit_log_request_idx").on(table.requestId),
37
+ resourceIdx: index("audit_log_resource_idx").on(
38
+ table.resourceType,
39
+ table.resourceId,
40
+ ),
41
+ tenantIdx: index("audit_log_tenant_idx").on(table.tenantId),
42
+ }),
43
+ );
44
+
45
+ export const outboxMessages = mysqlTable(
46
+ "outbox_messages",
47
+ {
48
+ id: varchar("id", { length: 255 }).primaryKey(),
49
+ kind: varchar("kind", { length: 32 }).notNull(),
50
+ name: varchar("name", { length: 255 }).notNull(),
51
+ payloadJson: longtext("payload_json").notNull(),
52
+ status: varchar("status", { length: 32 }).notNull(),
53
+ attempts: int("attempts").notNull().default(0),
54
+ maxAttempts: int("max_attempts").notNull().default(3),
55
+ availableAt: varchar("available_at", { length: 32 }).notNull(),
56
+ claimedAt: varchar("claimed_at", { length: 32 }),
57
+ lockedUntil: varchar("locked_until", { length: 32 }),
58
+ claimToken: varchar("claim_token", { length: 64 }),
59
+ deliveredAt: varchar("delivered_at", { length: 32 }),
60
+ lastErrorJson: longtext("last_error_json"),
61
+ createdAt: varchar("created_at", { length: 32 }).notNull(),
62
+ updatedAt: varchar("updated_at", { length: 32 }).notNull(),
63
+ },
64
+ (table) => ({
65
+ availableIdx: index("outbox_messages_available_idx").on(
66
+ table.status,
67
+ table.availableAt,
68
+ ),
69
+ lockedIdx: index("outbox_messages_locked_idx").on(
70
+ table.status,
71
+ table.lockedUntil,
72
+ ),
73
+ }),
74
+ );
75
+
76
+ export const idempotencyRecords = mysqlTable(
77
+ "idempotency_records",
78
+ {
79
+ storageKey: varchar("storage_key", { length: 512 }).primaryKey(),
80
+ namespace: varchar("namespace", { length: 255 }).notNull(),
81
+ idempotencyKey: varchar("idempotency_key", { length: 255 }).notNull(),
82
+ scopeKey: varchar("scope_key", { length: 255 }).notNull(),
83
+ fingerprint: varchar("fingerprint", { length: 255 }).notNull(),
84
+ status: varchar("status", { length: 16 }).notNull(),
85
+ resultJson: longtext("result_json"),
86
+ reservedAt: varchar("reserved_at", { length: 32 }).notNull(),
87
+ completedAt: varchar("completed_at", { length: 32 }),
88
+ expiresAt: varchar("expires_at", { length: 32 }),
89
+ updatedAt: varchar("updated_at", { length: 32 }).notNull(),
90
+ },
91
+ (table) => ({
92
+ lookupIdx: index("idempotency_records_lookup_idx").on(
93
+ table.namespace,
94
+ table.scopeKey,
95
+ table.idempotencyKey,
96
+ ),
97
+ expiresIdx: index("idempotency_records_expires_idx").on(table.expiresAt),
98
+ }),
99
+ );
@@ -0,0 +1,93 @@
1
+ import { index, integer, pgTable, text } from "drizzle-orm/pg-core";
2
+
3
+ export const auditLog = pgTable(
4
+ "audit_log",
5
+ {
6
+ id: text("id").primaryKey(),
7
+ action: text("action").notNull(),
8
+ actorType: text("actor_type").notNull(),
9
+ actorId: text("actor_id"),
10
+ actorDisplayName: text("actor_display_name"),
11
+ tenantId: text("tenant_id"),
12
+ tenantSlug: text("tenant_slug"),
13
+ resourceType: text("resource_type"),
14
+ resourceId: text("resource_id"),
15
+ resourceName: text("resource_name"),
16
+ outcome: text("outcome").notNull().default("success"),
17
+ requestId: text("request_id"),
18
+ traceId: text("trace_id"),
19
+ message: text("message"),
20
+ metadata: text("metadata"),
21
+ actorMetadata: text("actor_metadata"),
22
+ tenantMetadata: text("tenant_metadata"),
23
+ resourceMetadata: text("resource_metadata"),
24
+ occurredAt: text("occurred_at").notNull(),
25
+ },
26
+ (table) => ({
27
+ actionIdx: index("audit_log_action_idx").on(table.action),
28
+ actorIdx: index("audit_log_actor_idx").on(table.actorType, table.actorId),
29
+ occurredAtIdx: index("audit_log_occurred_at_idx").on(table.occurredAt),
30
+ requestIdx: index("audit_log_request_idx").on(table.requestId),
31
+ resourceIdx: index("audit_log_resource_idx").on(
32
+ table.resourceType,
33
+ table.resourceId,
34
+ ),
35
+ tenantIdx: index("audit_log_tenant_idx").on(table.tenantId),
36
+ }),
37
+ );
38
+
39
+ export const outboxMessages = pgTable(
40
+ "outbox_messages",
41
+ {
42
+ id: text("id").primaryKey(),
43
+ kind: text("kind").notNull(),
44
+ name: text("name").notNull(),
45
+ payloadJson: text("payload_json").notNull(),
46
+ status: text("status").notNull(),
47
+ attempts: integer("attempts").notNull().default(0),
48
+ maxAttempts: integer("max_attempts").notNull().default(3),
49
+ availableAt: text("available_at").notNull(),
50
+ claimedAt: text("claimed_at"),
51
+ lockedUntil: text("locked_until"),
52
+ claimToken: text("claim_token"),
53
+ deliveredAt: text("delivered_at"),
54
+ lastErrorJson: text("last_error_json"),
55
+ createdAt: text("created_at").notNull(),
56
+ updatedAt: text("updated_at").notNull(),
57
+ },
58
+ (table) => ({
59
+ availableIdx: index("outbox_messages_available_idx").on(
60
+ table.status,
61
+ table.availableAt,
62
+ ),
63
+ lockedIdx: index("outbox_messages_locked_idx").on(
64
+ table.status,
65
+ table.lockedUntil,
66
+ ),
67
+ }),
68
+ );
69
+
70
+ export const idempotencyRecords = pgTable(
71
+ "idempotency_records",
72
+ {
73
+ storageKey: text("storage_key").primaryKey(),
74
+ namespace: text("namespace").notNull(),
75
+ idempotencyKey: text("idempotency_key").notNull(),
76
+ scopeKey: text("scope_key").notNull(),
77
+ fingerprint: text("fingerprint").notNull(),
78
+ status: text("status").notNull(),
79
+ resultJson: text("result_json"),
80
+ reservedAt: text("reserved_at").notNull(),
81
+ completedAt: text("completed_at"),
82
+ expiresAt: text("expires_at"),
83
+ updatedAt: text("updated_at").notNull(),
84
+ },
85
+ (table) => ({
86
+ lookupIdx: index("idempotency_records_lookup_idx").on(
87
+ table.namespace,
88
+ table.scopeKey,
89
+ table.idempotencyKey,
90
+ ),
91
+ expiresIdx: index("idempotency_records_expires_idx").on(table.expiresAt),
92
+ }),
93
+ );
@@ -0,0 +1,93 @@
1
+ import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
+
3
+ export const auditLog = sqliteTable(
4
+ "audit_log",
5
+ {
6
+ id: text("id").primaryKey(),
7
+ action: text("action").notNull(),
8
+ actorType: text("actor_type").notNull(),
9
+ actorId: text("actor_id"),
10
+ actorDisplayName: text("actor_display_name"),
11
+ tenantId: text("tenant_id"),
12
+ tenantSlug: text("tenant_slug"),
13
+ resourceType: text("resource_type"),
14
+ resourceId: text("resource_id"),
15
+ resourceName: text("resource_name"),
16
+ outcome: text("outcome").notNull().default("success"),
17
+ requestId: text("request_id"),
18
+ traceId: text("trace_id"),
19
+ message: text("message"),
20
+ metadata: text("metadata"),
21
+ actorMetadata: text("actor_metadata"),
22
+ tenantMetadata: text("tenant_metadata"),
23
+ resourceMetadata: text("resource_metadata"),
24
+ occurredAt: text("occurred_at").notNull(),
25
+ },
26
+ (table) => ({
27
+ actionIdx: index("audit_log_action_idx").on(table.action),
28
+ actorIdx: index("audit_log_actor_idx").on(table.actorType, table.actorId),
29
+ occurredAtIdx: index("audit_log_occurred_at_idx").on(table.occurredAt),
30
+ requestIdx: index("audit_log_request_idx").on(table.requestId),
31
+ resourceIdx: index("audit_log_resource_idx").on(
32
+ table.resourceType,
33
+ table.resourceId,
34
+ ),
35
+ tenantIdx: index("audit_log_tenant_idx").on(table.tenantId),
36
+ }),
37
+ );
38
+
39
+ export const outboxMessages = sqliteTable(
40
+ "outbox_messages",
41
+ {
42
+ id: text("id").primaryKey(),
43
+ kind: text("kind").notNull(),
44
+ name: text("name").notNull(),
45
+ payloadJson: text("payload_json").notNull(),
46
+ status: text("status").notNull(),
47
+ attempts: integer("attempts").notNull().default(0),
48
+ maxAttempts: integer("max_attempts").notNull().default(3),
49
+ availableAt: text("available_at").notNull(),
50
+ claimedAt: text("claimed_at"),
51
+ lockedUntil: text("locked_until"),
52
+ claimToken: text("claim_token"),
53
+ deliveredAt: text("delivered_at"),
54
+ lastErrorJson: text("last_error_json"),
55
+ createdAt: text("created_at").notNull(),
56
+ updatedAt: text("updated_at").notNull(),
57
+ },
58
+ (table) => ({
59
+ availableIdx: index("outbox_messages_available_idx").on(
60
+ table.status,
61
+ table.availableAt,
62
+ ),
63
+ lockedIdx: index("outbox_messages_locked_idx").on(
64
+ table.status,
65
+ table.lockedUntil,
66
+ ),
67
+ }),
68
+ );
69
+
70
+ export const idempotencyRecords = sqliteTable(
71
+ "idempotency_records",
72
+ {
73
+ storageKey: text("storage_key").primaryKey(),
74
+ namespace: text("namespace").notNull(),
75
+ idempotencyKey: text("idempotency_key").notNull(),
76
+ scopeKey: text("scope_key").notNull(),
77
+ fingerprint: text("fingerprint").notNull(),
78
+ status: text("status").notNull(),
79
+ resultJson: text("result_json"),
80
+ reservedAt: text("reserved_at").notNull(),
81
+ completedAt: text("completed_at"),
82
+ expiresAt: text("expires_at"),
83
+ updatedAt: text("updated_at").notNull(),
84
+ },
85
+ (table) => ({
86
+ lookupIdx: index("idempotency_records_lookup_idx").on(
87
+ table.namespace,
88
+ table.scopeKey,
89
+ table.idempotencyKey,
90
+ ),
91
+ expiresIdx: index("idempotency_records_expires_idx").on(table.expiresAt),
92
+ }),
93
+ );