rebackend-drizzle 0.1.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 +21 -0
- package/dist/drizzle/index.js +21 -0
- package/dist/drizzle/index.js.map +1 -0
- package/dist/drizzle/outbox.js +173 -0
- package/dist/drizzle/outbox.js.map +1 -0
- package/dist/drizzle/presets.js +83 -0
- package/dist/drizzle/presets.js.map +1 -0
- package/dist/drizzle/repository.js +76 -0
- package/dist/drizzle/repository.js.map +1 -0
- package/dist/drizzle/transaction.js +20 -0
- package/dist/drizzle/transaction.js.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
- package/src/drizzle/index.ts +4 -0
- package/src/drizzle/outbox.ts +387 -0
- package/src/drizzle/presets.ts +274 -0
- package/src/drizzle/repository.ts +221 -0
- package/src/drizzle/transaction.ts +31 -0
- package/src/index.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# rebackend-drizzle
|
|
2
|
+
|
|
3
|
+
Drizzle adapters for `rebackend`.
|
|
4
|
+
|
|
5
|
+
Current release line starts at `v0.1.0` and is intentionally positioned as `pre-1.0` for real project validation.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add rebackend rebackend-drizzle drizzle-orm farrow-schema
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Docs
|
|
14
|
+
|
|
15
|
+
- Repository: `https://github.com/AisonSu/Rebackend`
|
|
16
|
+
- Roadmap: `https://github.com/AisonSu/Rebackend/blob/main/roadmap.md`
|
|
17
|
+
- Workflow: `https://github.com/AisonSu/Rebackend/blob/main/workflow.md`
|
|
18
|
+
|
|
19
|
+
## Related Package
|
|
20
|
+
|
|
21
|
+
- `rebackend`: core runtime, DDD/CQRS primitives, outbox, dispatcher, UoW
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./transaction"), exports);
|
|
18
|
+
__exportStar(require("./repository"), exports);
|
|
19
|
+
__exportStar(require("./outbox"), exports);
|
|
20
|
+
__exportStar(require("./presets"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,+CAA4B;AAC5B,2CAAwB;AACxB,4CAAyB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDrizzleTableOutbox = exports.createDrizzleOutbox = exports.createJsonDrizzleOutboxCodec = void 0;
|
|
4
|
+
const transaction_1 = require("./transaction");
|
|
5
|
+
const createJsonDrizzleOutboxCodec = () => {
|
|
6
|
+
return {
|
|
7
|
+
toInsertRow(entry, now) {
|
|
8
|
+
return {
|
|
9
|
+
eventName: entry.event.name,
|
|
10
|
+
payload: JSON.stringify({
|
|
11
|
+
key: entry.event.key,
|
|
12
|
+
version: entry.event.version,
|
|
13
|
+
payload: entry.event.payload,
|
|
14
|
+
}),
|
|
15
|
+
sourceType: entry.sourceType,
|
|
16
|
+
sourceName: entry.sourceName,
|
|
17
|
+
status: 'pending',
|
|
18
|
+
attempts: 0,
|
|
19
|
+
createdAt: now,
|
|
20
|
+
dispatchedAt: null,
|
|
21
|
+
lastError: null,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
fromStoredRow(row) {
|
|
25
|
+
const envelope = JSON.parse(row.payload);
|
|
26
|
+
return {
|
|
27
|
+
id: row.id,
|
|
28
|
+
event: {
|
|
29
|
+
kind: 'DomainEventAction',
|
|
30
|
+
key: envelope.key,
|
|
31
|
+
name: row.eventName,
|
|
32
|
+
version: envelope.version,
|
|
33
|
+
payload: envelope.payload,
|
|
34
|
+
},
|
|
35
|
+
sourceType: row.sourceType,
|
|
36
|
+
sourceName: row.sourceName,
|
|
37
|
+
status: row.status,
|
|
38
|
+
attempts: row.attempts,
|
|
39
|
+
createdAt: row.createdAt,
|
|
40
|
+
dispatchedAt: row.dispatchedAt ?? undefined,
|
|
41
|
+
lastError: row.lastError ?? undefined,
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.createJsonDrizzleOutboxCodec = createJsonDrizzleOutboxCodec;
|
|
47
|
+
const createDrizzleOutbox = (options) => {
|
|
48
|
+
return {
|
|
49
|
+
async append(entries, context) {
|
|
50
|
+
if (entries.length === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db, context);
|
|
54
|
+
const now = new Date();
|
|
55
|
+
const rows = entries.map((entry) => options.codec.toInsertRow(entry, now));
|
|
56
|
+
await options.insertRows(executor, rows);
|
|
57
|
+
},
|
|
58
|
+
async list() {
|
|
59
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db);
|
|
60
|
+
const rows = await options.listRows(executor);
|
|
61
|
+
return rows.map((row) => options.codec.fromStoredRow(row));
|
|
62
|
+
},
|
|
63
|
+
async listPending(limit) {
|
|
64
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db);
|
|
65
|
+
const rows = await options.listPendingRows(executor, limit);
|
|
66
|
+
return rows.map((row) => options.codec.fromStoredRow(row));
|
|
67
|
+
},
|
|
68
|
+
async markDispatched(ids) {
|
|
69
|
+
if (ids.length === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db);
|
|
73
|
+
await options.markRowsDispatched(executor, ids, new Date());
|
|
74
|
+
},
|
|
75
|
+
async markFailed(ids, error) {
|
|
76
|
+
if (ids.length === 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db);
|
|
80
|
+
await options.markRowsFailed(executor, ids, error);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
exports.createDrizzleOutbox = createDrizzleOutbox;
|
|
85
|
+
const createDrizzleTableOutbox = (options) => {
|
|
86
|
+
const codec = {
|
|
87
|
+
toInsertRow(entry, now) {
|
|
88
|
+
const row = {
|
|
89
|
+
[options.columns.eventName]: entry.event.name,
|
|
90
|
+
[options.columns.payload]: JSON.stringify({
|
|
91
|
+
key: entry.event.key,
|
|
92
|
+
version: entry.event.version,
|
|
93
|
+
payload: entry.event.payload,
|
|
94
|
+
}),
|
|
95
|
+
[options.columns.sourceType]: entry.sourceType,
|
|
96
|
+
[options.columns.sourceName]: entry.sourceName,
|
|
97
|
+
[options.columns.status]: 'pending',
|
|
98
|
+
[options.columns.attempts]: 0,
|
|
99
|
+
[options.columns.createdAt]: now,
|
|
100
|
+
};
|
|
101
|
+
return row;
|
|
102
|
+
},
|
|
103
|
+
fromStoredRow(row) {
|
|
104
|
+
const dispatchedAtKey = options.columns.dispatchedAt;
|
|
105
|
+
const lastErrorKey = options.columns.lastError;
|
|
106
|
+
const rowRecord = row;
|
|
107
|
+
const envelope = JSON.parse(row[options.columns.payload]);
|
|
108
|
+
return {
|
|
109
|
+
id: row[options.columns.id],
|
|
110
|
+
event: {
|
|
111
|
+
kind: 'DomainEventAction',
|
|
112
|
+
key: envelope.key,
|
|
113
|
+
name: row[options.columns.eventName],
|
|
114
|
+
version: envelope.version,
|
|
115
|
+
payload: envelope.payload,
|
|
116
|
+
},
|
|
117
|
+
sourceType: row[options.columns.sourceType],
|
|
118
|
+
sourceName: row[options.columns.sourceName],
|
|
119
|
+
status: row[options.columns.status],
|
|
120
|
+
attempts: row[options.columns.attempts],
|
|
121
|
+
createdAt: row[options.columns.createdAt],
|
|
122
|
+
dispatchedAt: dispatchedAtKey
|
|
123
|
+
? rowRecord[dispatchedAtKey]
|
|
124
|
+
: undefined,
|
|
125
|
+
lastError: lastErrorKey
|
|
126
|
+
? rowRecord[lastErrorKey]
|
|
127
|
+
: undefined,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
return (0, exports.createDrizzleOutbox)({
|
|
132
|
+
db: options.db,
|
|
133
|
+
codec,
|
|
134
|
+
insertRows: (executor, rows) => options.operations.insertRows({
|
|
135
|
+
executor,
|
|
136
|
+
table: options.table,
|
|
137
|
+
rows,
|
|
138
|
+
}),
|
|
139
|
+
listRows: (executor) => options.operations.listRows({
|
|
140
|
+
executor,
|
|
141
|
+
table: options.table,
|
|
142
|
+
}),
|
|
143
|
+
listPendingRows: (executor, limit) => options.operations.listPendingRows({
|
|
144
|
+
executor,
|
|
145
|
+
table: options.table,
|
|
146
|
+
statusKey: options.columns.status,
|
|
147
|
+
pendingStatus: 'pending',
|
|
148
|
+
limit,
|
|
149
|
+
}),
|
|
150
|
+
markRowsDispatched: (executor, ids, dispatchedAt) => options.operations.markRowsDispatched({
|
|
151
|
+
executor,
|
|
152
|
+
table: options.table,
|
|
153
|
+
ids,
|
|
154
|
+
idKey: options.columns.id,
|
|
155
|
+
statusKey: options.columns.status,
|
|
156
|
+
attemptsKey: options.columns.attempts,
|
|
157
|
+
dispatchedAtKey: options.columns.dispatchedAt,
|
|
158
|
+
dispatchedAt,
|
|
159
|
+
}),
|
|
160
|
+
markRowsFailed: (executor, ids, error) => options.operations.markRowsFailed({
|
|
161
|
+
executor,
|
|
162
|
+
table: options.table,
|
|
163
|
+
ids,
|
|
164
|
+
idKey: options.columns.id,
|
|
165
|
+
statusKey: options.columns.status,
|
|
166
|
+
attemptsKey: options.columns.attempts,
|
|
167
|
+
lastErrorKey: options.columns.lastError,
|
|
168
|
+
error,
|
|
169
|
+
}),
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
exports.createDrizzleTableOutbox = createDrizzleTableOutbox;
|
|
173
|
+
//# sourceMappingURL=outbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/drizzle/outbox.ts"],"names":[],"mappings":";;;AAWA,+CAAsD;AAuD/C,MAAM,4BAA4B,GAAG,GAG1C,EAAE;IACF,OAAO;QACL,WAAW,CAAC,KAAK,EAAE,GAAG;YACpB,OAAO;gBACL,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;gBAC3B,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;oBACtB,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG;oBACpB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;oBAC5B,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;iBAC7B,CAAC;gBACF,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,CAAC;gBACX,SAAS,EAAE,GAAG;gBACd,YAAY,EAAE,IAAI;gBAClB,SAAS,EAAE,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
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBasicDrizzleTableOutbox = exports.createBasicDrizzleTableAggregateRepository = void 0;
|
|
4
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
5
|
+
const repository_1 = require("./repository");
|
|
6
|
+
const outbox_1 = require("./outbox");
|
|
7
|
+
const createBasicDrizzleTableAggregateRepository = (options) => {
|
|
8
|
+
const columns = (0, drizzle_orm_1.getTableColumns)(options.table);
|
|
9
|
+
const identityColumn = columns[options.identity.rowKey];
|
|
10
|
+
const versionRowKey = options.version?.rowKey;
|
|
11
|
+
const versionColumn = versionRowKey ? columns[versionRowKey] : undefined;
|
|
12
|
+
const repositoryOptions = {
|
|
13
|
+
...options,
|
|
14
|
+
operations: {
|
|
15
|
+
async findById({ executor, table, id }) {
|
|
16
|
+
const rows = await executor.select().from(table).where((0, drizzle_orm_1.eq)(identityColumn, id)).limit(1);
|
|
17
|
+
return rows[0] ?? null;
|
|
18
|
+
},
|
|
19
|
+
async insertOne({ executor, table, row }) {
|
|
20
|
+
await executor.insert(table).values(row);
|
|
21
|
+
},
|
|
22
|
+
async updateById({ executor, table, id, row, optimisticLock, expectedVersion }) {
|
|
23
|
+
const whereCondition = optimisticLock && versionColumn && expectedVersion !== undefined
|
|
24
|
+
? (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(identityColumn, id), (0, drizzle_orm_1.eq)(versionColumn, expectedVersion))
|
|
25
|
+
: (0, drizzle_orm_1.eq)(identityColumn, id);
|
|
26
|
+
const result = await executor.update(table).set(row).where(whereCondition);
|
|
27
|
+
return options.didUpdateSucceed(result);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
return (0, repository_1.createDrizzleTableAggregateRepository)(repositoryOptions);
|
|
32
|
+
};
|
|
33
|
+
exports.createBasicDrizzleTableAggregateRepository = createBasicDrizzleTableAggregateRepository;
|
|
34
|
+
const createBasicDrizzleTableOutbox = (options) => {
|
|
35
|
+
const columns = (0, drizzle_orm_1.getTableColumns)(options.table);
|
|
36
|
+
const idColumn = columns[options.columns.id];
|
|
37
|
+
const attemptsColumn = columns[options.columns.attempts];
|
|
38
|
+
const statusColumn = columns[options.columns.status];
|
|
39
|
+
const outboxOptions = {
|
|
40
|
+
...options,
|
|
41
|
+
operations: {
|
|
42
|
+
async insertRows({ executor, table, rows }) {
|
|
43
|
+
await executor.insert(table).values(rows);
|
|
44
|
+
},
|
|
45
|
+
async listRows({ executor, table }) {
|
|
46
|
+
return executor.select().from(table);
|
|
47
|
+
},
|
|
48
|
+
async listPendingRows({ executor, table, pendingStatus, limit }) {
|
|
49
|
+
const query = executor.select().from(table).where((0, drizzle_orm_1.eq)(statusColumn, pendingStatus));
|
|
50
|
+
return limit === undefined ? query : query.limit(limit);
|
|
51
|
+
},
|
|
52
|
+
async markRowsDispatched({ executor, table, ids, statusKey, attemptsKey, dispatchedAtKey, dispatchedAt, }) {
|
|
53
|
+
const updateRow = {
|
|
54
|
+
[statusKey]: 'dispatched',
|
|
55
|
+
[attemptsKey]: (0, drizzle_orm_1.sql) `${attemptsColumn} + 1`,
|
|
56
|
+
};
|
|
57
|
+
if (dispatchedAtKey) {
|
|
58
|
+
updateRow[dispatchedAtKey] = dispatchedAt;
|
|
59
|
+
}
|
|
60
|
+
await executor
|
|
61
|
+
.update(table)
|
|
62
|
+
.set(updateRow)
|
|
63
|
+
.where((0, drizzle_orm_1.inArray)(idColumn, [...ids]));
|
|
64
|
+
},
|
|
65
|
+
async markRowsFailed({ executor, table, ids, statusKey, attemptsKey, lastErrorKey, error }) {
|
|
66
|
+
const updateRow = {
|
|
67
|
+
[statusKey]: 'failed',
|
|
68
|
+
[attemptsKey]: (0, drizzle_orm_1.sql) `${attemptsColumn} + 1`,
|
|
69
|
+
};
|
|
70
|
+
if (lastErrorKey) {
|
|
71
|
+
updateRow[lastErrorKey] = error;
|
|
72
|
+
}
|
|
73
|
+
await executor
|
|
74
|
+
.update(table)
|
|
75
|
+
.set(updateRow)
|
|
76
|
+
.where((0, drizzle_orm_1.inArray)(idColumn, [...ids]));
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return (0, outbox_1.createDrizzleTableOutbox)(outboxOptions);
|
|
81
|
+
};
|
|
82
|
+
exports.createBasicDrizzleTableOutbox = createBasicDrizzleTableOutbox;
|
|
83
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/drizzle/presets.ts"],"names":[],"mappings":";;;AAAA,6CAQoB;AAIpB,6CAIqB;AACrB,qCAIiB;AAsDV,MAAM,0CAA0C,GAAG,CAWxD,OASC,EACD,EAAE;IACF,MAAM,OAAO,GAAG,IAAA,6BAAe,EAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvD,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAA;IAC7C,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAExE,MAAM,iBAAiB,GASnB;QACF,GAAG,OAAO;QACV,UAAU,EAAE;YACV,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAA,gBAAE,EAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBACvF,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;YACxB,CAAC;YACD,KAAK,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GA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YACD,KAAK,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE;gBACxF,MAAM,SAAS,GAA4B;oBACzC,CAAC,SAAS,CAAC,EAAE,QAAQ;oBACrB,CAAC,WAAW,CAAC,EAAE,IAAA,iBAAG,EAAA,GAAG,cAAc,MAAM;iBAC1C,CAAA;gBAED,IAAI,YAAY,EAAE,CAAC;oBACjB,SAAS,CAAC,YAAY,CAAC,GAAG,KAAK,CAAA;gBACjC,CAAC;gBAED,MAAM,QAAQ;qBACX,MAAM,CAAC,KAAK,CAAC;qBACb,GAAG,CAAC,SAAS,CAAC;qBACd,KAAK,CAAC,IAAA,qBAAO,EAAC,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;YACvC,CAAC;SACF;KACF,CAAA;IAED,OAAO,IAAA,iCAAwB,EAAC,aAAa,CAAC,CAAA;AAChD,CAAC,CAAA;AAzGY,QAAA,6BAA6B,iCAyGzC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasSameVersion = exports.createDrizzleTableAggregateRepository = exports.createDrizzleAggregateRepository = void 0;
|
|
4
|
+
const transaction_1 = require("./transaction");
|
|
5
|
+
const createDrizzleAggregateRepository = (options) => {
|
|
6
|
+
return {
|
|
7
|
+
async findById(id, context) {
|
|
8
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db, context);
|
|
9
|
+
const row = await options.load(executor, id);
|
|
10
|
+
if (row === null || row === undefined) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return options.deserialize(row);
|
|
14
|
+
},
|
|
15
|
+
async save(input, context) {
|
|
16
|
+
const executor = (0, transaction_1.resolveDrizzleExecutor)(options.db, context);
|
|
17
|
+
if (input.mode === 'create') {
|
|
18
|
+
await options.insert(executor, input.next);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (input.current === null) {
|
|
22
|
+
throw new Error('Drizzle aggregate update requires current aggregate state.');
|
|
23
|
+
}
|
|
24
|
+
return options.update({
|
|
25
|
+
executor,
|
|
26
|
+
next: input.next,
|
|
27
|
+
current: input.current,
|
|
28
|
+
optimisticLock: input.optimisticLock,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.createDrizzleAggregateRepository = createDrizzleAggregateRepository;
|
|
34
|
+
const createDrizzleTableAggregateRepository = (options) => {
|
|
35
|
+
return (0, exports.createDrizzleAggregateRepository)({
|
|
36
|
+
db: options.db,
|
|
37
|
+
load: async (executor, id) => {
|
|
38
|
+
return options.operations.findById({
|
|
39
|
+
executor,
|
|
40
|
+
table: options.table,
|
|
41
|
+
rowKey: options.identity.rowKey,
|
|
42
|
+
id,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
insert: async (executor, next) => {
|
|
46
|
+
await options.operations.insertOne({
|
|
47
|
+
executor,
|
|
48
|
+
table: options.table,
|
|
49
|
+
row: options.serialize.insert(next),
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
update: async ({ executor, next, current, optimisticLock }) => {
|
|
53
|
+
const versionRowKey = options.version?.rowKey;
|
|
54
|
+
const currentVersion = options.version
|
|
55
|
+
? current[options.version.stateKey]
|
|
56
|
+
: undefined;
|
|
57
|
+
return options.operations.updateById({
|
|
58
|
+
executor,
|
|
59
|
+
table: options.table,
|
|
60
|
+
rowKey: options.identity.rowKey,
|
|
61
|
+
id: next[options.identity.stateKey],
|
|
62
|
+
row: options.serialize.update(next),
|
|
63
|
+
optimisticLock,
|
|
64
|
+
expectedVersion: currentVersion,
|
|
65
|
+
versionRowKey,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
deserialize: options.deserialize,
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
exports.createDrizzleTableAggregateRepository = createDrizzleTableAggregateRepository;
|
|
72
|
+
const hasSameVersion = (row, state) => {
|
|
73
|
+
return row?.version === state.version;
|
|
74
|
+
};
|
|
75
|
+
exports.hasSameVersion = hasSameVersion;
|
|
76
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/drizzle/repository.ts"],"names":[],"mappings":";;;AASA,+CAAsD;AA2C/C,MAAM,gCAAgC,GAAG,CAM9C,OAA+E,EAC9C,EAAE;IACnC,OAAO;QACL,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO;YACxB,MAAM,QAAQ,GAAG,IAAA,oCAAsB,EAAoB,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;YAC/E,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;YAE5C,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtC,OAAO,IAAI,CAAA;YACb,CAAC;YAED,OAAO,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QACjC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO;YACvB,MAAM,QAAQ,GAAG,IAAA,oCAAsB,EAAoB,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;YAE/E,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;gBAC1C,OAAM;YACR,CAAC;YAED,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;YAC/E,CAAC;YAED,OAAO,OAAO,CAAC,MAAM,CAAC;gBACpB,QAAQ;gBACR,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ACpB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAC/B,EAAE,EAAE,IAAI,CACN,OAAO,CAAC,QAAQ,CAAC,QAA4C,CAC7B;gBAClC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnC,cAAc;gBACd,eAAe,EAAE,cAAc;gBAC/B,aAAa;aACd,CAAC,CAAA;QACJ,CAAC;QACD,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAA;AACJ,CAAC,CAAA;AA9DY,QAAA,qCAAqC,yCA8DjD;AAMM,MAAM,cAAc,GAAG,CAI5B,GAA4B,EAC5B,KAAa,EACJ,EAAE;IACX,OAAO,GAAG,EAAE,OAAO,KAAK,KAAK,CAAC,OAAO,CAAA;AACvC,CAAC,CAAA;AARY,QAAA,cAAc,kBAQ1B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDrizzleExecutor = exports.createDrizzleTransactionRunner = void 0;
|
|
4
|
+
const createDrizzleTransactionRunner = (db) => {
|
|
5
|
+
return {
|
|
6
|
+
async run(work) {
|
|
7
|
+
return Promise.resolve(db.transaction((transaction) => work(transaction)));
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.createDrizzleTransactionRunner = createDrizzleTransactionRunner;
|
|
12
|
+
const resolveDrizzleExecutor = (db, context) => {
|
|
13
|
+
const transaction = context?.transaction;
|
|
14
|
+
if (transaction === null || transaction === undefined) {
|
|
15
|
+
return db;
|
|
16
|
+
}
|
|
17
|
+
return transaction;
|
|
18
|
+
};
|
|
19
|
+
exports.resolveDrizzleExecutor = resolveDrizzleExecutor;
|
|
20
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/drizzle/transaction.ts"],"names":[],"mappings":";;;AAMO,MAAM,8BAA8B,GAAG,CAI5C,EAAO,EAC0B,EAAE;IACnC,OAAO;QACL,KAAK,CAAC,GAAG,CAAI,IAAoD;YAC/D,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QAC5E,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,8BAA8B,kCAW1C;AAEM,MAAM,sBAAsB,GAAG,CACpC,EAAO,EACP,OAA4B,EACR,EAAE;IACtB,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,CAAA;IAExC,IAAI,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,WAA2B,CAAA;AACpC,CAAC,CAAA;AAXY,QAAA,sBAAsB,0BAWlC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./drizzle"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rebackend-drizzle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drizzle adapters for Rebackend.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src/index.ts",
|
|
18
|
+
"src/drizzle"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"rebackend",
|
|
22
|
+
"drizzle",
|
|
23
|
+
"adapter"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/AisonSu/Rebackend.git",
|
|
33
|
+
"directory": "packages/rebackend-drizzle"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/AisonSu/Rebackend/tree/main/packages/rebackend-drizzle#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/AisonSu/Rebackend/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"drizzle-orm": "^0.45.2",
|
|
41
|
+
"farrow-schema": "^2.3.3",
|
|
42
|
+
"rebackend": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^25.5.0",
|
|
46
|
+
"@types/sql.js": "^1.4.11",
|
|
47
|
+
"sql.js": "^1.14.1",
|
|
48
|
+
"tsx": "^4.21.0",
|
|
49
|
+
"typescript": "^6.0.2"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
53
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
54
|
+
"pretest": "pnpm --filter rebackend build",
|
|
55
|
+
"predemo:drizzle-adapter": "pnpm --filter rebackend build",
|
|
56
|
+
"predemo:drizzle-table-adapter": "pnpm --filter rebackend build",
|
|
57
|
+
"predemo:drizzle-sqljs": "pnpm --filter rebackend build",
|
|
58
|
+
"test": "tsx --test --test-concurrency=1 src/tests/*.test.ts",
|
|
59
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
60
|
+
"demo:drizzle-adapter": "tsx src/examples/drizzle-adapter.demo.ts",
|
|
61
|
+
"demo:drizzle-table-adapter": "tsx src/examples/drizzle-table-adapter.demo.ts",
|
|
62
|
+
"demo:drizzle-sqljs": "tsx src/examples/drizzle-sqljs.demo.ts"
|
|
63
|
+
}
|
|
64
|
+
}
|