@jayfong/x-server 2.1.0 → 2.1.2
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.
|
@@ -15,7 +15,7 @@ var _execa = _interopRequireDefault(require("execa"));
|
|
|
15
15
|
|
|
16
16
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _globby = _interopRequireDefault(require("globby"));
|
|
19
19
|
|
|
20
20
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
21
21
|
|
|
@@ -134,20 +134,21 @@ class BuildUtil {
|
|
|
134
134
|
const prismaSchemaFile = _nodePath.default.join(options.cwd, 'src/db/schema.prisma');
|
|
135
135
|
|
|
136
136
|
if (await _fsExtra.default.pathExists(prismaSchemaFile)) {
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
env: {
|
|
140
|
-
// https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#prisma_cli_binary_targets
|
|
141
|
-
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#binarytargets-options
|
|
142
|
-
PRISMA_CLI_BINARY_TARGETS: `${_os.default.platform() === 'darwin' ? 'darwin' : 'windows'},rhel-openssl-1.0.x,rhel-openssl-1.1.x`
|
|
143
|
-
}
|
|
144
|
-
});
|
|
137
|
+
// 复制 schema.prisma
|
|
138
|
+
const distPrismaSchemaFile = _nodePath.default.join(distDir, _nodePath.default.basename(prismaSchemaFile));
|
|
145
139
|
|
|
146
|
-
|
|
140
|
+
await _fsExtra.default.copyFile(prismaSchemaFile, distPrismaSchemaFile); // 复制查询引擎
|
|
147
141
|
|
|
148
|
-
await
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
const libqueryEngineFiles = await (0, _globby.default)('libquery_engine-*', {
|
|
143
|
+
cwd: _nodePath.default.join(options.cwd, 'node_modules/.prisma/client'),
|
|
144
|
+
ignore: ['libquery_engine-{darwin,windows}*'],
|
|
145
|
+
onlyFiles: true,
|
|
146
|
+
absolute: true
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
for (const libqueryEngineFile of libqueryEngineFiles) {
|
|
150
|
+
await _fsExtra.default.copyFile(libqueryEngineFile, _nodePath.default.join(distDir, _nodePath.default.basename(libqueryEngineFile)));
|
|
151
|
+
}
|
|
151
152
|
} // 写入 pkg
|
|
152
153
|
|
|
153
154
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { x, HttpError } from '@jayfong/x-server'
|
|
2
|
-
import { PrismaClient } from '@prisma/client'
|
|
2
|
+
import { PrismaClient, Prisma } from '@prisma/client'
|
|
3
3
|
|
|
4
4
|
export const prismaClient = new PrismaClient({
|
|
5
5
|
rejectOnNotFound: err => new HttpError.NotFound(err.message),
|
|
@@ -15,6 +15,13 @@ type ModelName =
|
|
|
15
15
|
function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
16
16
|
return class BaseModel {
|
|
17
17
|
public query = prismaClient[name]
|
|
18
|
+
|
|
19
|
+
public transactionify = (tx: Prisma.TransactionClient) => {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
return new (class extends this.constructor {
|
|
22
|
+
public query = tx[name]
|
|
23
|
+
})() as typeof this
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
|
package/lib/cli/build_util.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
2
|
import compressing from 'compressing';
|
|
3
3
|
import exec from 'execa';
|
|
4
|
-
import execa from 'execa';
|
|
5
4
|
import fs from 'fs-extra';
|
|
6
|
-
import
|
|
5
|
+
import globby from 'globby';
|
|
7
6
|
import path from 'node:path';
|
|
8
7
|
import { dedent, uniq } from 'vtils';
|
|
9
8
|
export class BuildUtil {
|
|
@@ -108,18 +107,20 @@ export class BuildUtil {
|
|
|
108
107
|
const prismaSchemaFile = path.join(options.cwd, 'src/db/schema.prisma');
|
|
109
108
|
|
|
110
109
|
if (await fs.pathExists(prismaSchemaFile)) {
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
110
|
+
// 复制 schema.prisma
|
|
111
|
+
const distPrismaSchemaFile = path.join(distDir, path.basename(prismaSchemaFile));
|
|
112
|
+
await fs.copyFile(prismaSchemaFile, distPrismaSchemaFile); // 复制查询引擎
|
|
113
|
+
|
|
114
|
+
const libqueryEngineFiles = await globby('libquery_engine-*', {
|
|
115
|
+
cwd: path.join(options.cwd, 'node_modules/.prisma/client'),
|
|
116
|
+
ignore: ['libquery_engine-{darwin,windows}*'],
|
|
117
|
+
onlyFiles: true,
|
|
118
|
+
absolute: true
|
|
118
119
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
|
|
121
|
+
for (const libqueryEngineFile of libqueryEngineFiles) {
|
|
122
|
+
await fs.copyFile(libqueryEngineFile, path.join(distDir, path.basename(libqueryEngineFile)));
|
|
123
|
+
}
|
|
123
124
|
} // 写入 pkg
|
|
124
125
|
|
|
125
126
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { x, HttpError } from '@jayfong/x-server'
|
|
2
|
-
import { PrismaClient } from '@prisma/client'
|
|
2
|
+
import { PrismaClient, Prisma } from '@prisma/client'
|
|
3
3
|
|
|
4
4
|
export const prismaClient = new PrismaClient({
|
|
5
5
|
rejectOnNotFound: err => new HttpError.NotFound(err.message),
|
|
@@ -15,6 +15,13 @@ type ModelName =
|
|
|
15
15
|
function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
16
16
|
return class BaseModel {
|
|
17
17
|
public query = prismaClient[name]
|
|
18
|
+
|
|
19
|
+
public transactionify = (tx: Prisma.TransactionClient) => {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
return new (class extends this.constructor {
|
|
22
|
+
public query = tx[name]
|
|
23
|
+
})() as typeof this
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"fastify-cors": "^6.0.3",
|
|
55
55
|
"fastify-multipart": "^5.3.1",
|
|
56
56
|
"fs-extra": "^10.0.1",
|
|
57
|
+
"globby": "^11",
|
|
57
58
|
"got": "^11.8.2",
|
|
58
59
|
"http-errors": "^1.8.1",
|
|
59
60
|
"ioredis": "^4.28.5",
|