@jayfong/x-server 2.51.0 → 2.52.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.
@@ -141,6 +141,13 @@ class BuildUtil {
141
141
  const distPrismaSchemaFile = _nodePath.default.join(distDir, _nodePath.default.basename(prismaSchemaFile));
142
142
  await _fsExtra.default.copyFile(prismaSchemaFile, distPrismaSchemaFile);
143
143
 
144
+ // 多 schema 文件兼容
145
+ const multipleSchemaDir = _nodePath.default.join(options.cwd, 'src/db/schema');
146
+ if (await _fsExtra.default.pathExists(multipleSchemaDir)) {
147
+ const distMultipleSchemaDir = _nodePath.default.join(distDir, _nodePath.default.basename(multipleSchemaDir));
148
+ await _fsExtra.default.copy(multipleSchemaDir, distMultipleSchemaDir);
149
+ }
150
+
144
151
  // 复制查询引擎
145
152
  const libqueryEngineFiles = await (0, _globby.default)('libquery_engine-*', {
146
153
  cwd: _nodePath.default.join(options.cwd, 'node_modules/.prisma/client'),
@@ -2,8 +2,10 @@
2
2
  "use strict";
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ var _path = _interopRequireDefault(require("path"));
5
6
  var _chokidar = _interopRequireDefault(require("chokidar"));
6
7
  var _execa = _interopRequireDefault(require("execa"));
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
7
9
  var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
8
10
  var _vtils = require("vtils");
9
11
  var _yargs = _interopRequireDefault(require("yargs"));
@@ -142,7 +144,13 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
142
144
  // 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
143
145
  // https://github.com/motdotla/dotenv#override
144
146
  process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
145
- await (0, _execa.default)('tnpx', ['prisma', ...argv._.slice(1), '--schema', 'src/db/schema.prisma'], {
147
+
148
+ // 多 schema 文件兼容
149
+ // https://www.prisma.io/docs/orm/prisma-schema/overview/location#how-to-use-existing-prisma-cli-commands-with-multiple-prisma-schema-files
150
+ const schemaDir = _path.default.join(process.cwd(), 'src/db/schema');
151
+ const isMultipleFiles = await _fsExtra.default.pathExists(schemaDir);
152
+ const schemaArg = isMultipleFiles ? 'src/db' : 'src/db/schema.prisma';
153
+ await (0, _execa.default)('tnpx', ['prisma', ...argv._.slice(1), '--schema', schemaArg], {
146
154
  cwd: process.cwd(),
147
155
  stdio: 'inherit'
148
156
  });
@@ -247,7 +247,7 @@ class CacheService {
247
247
  }
248
248
  if (this.options.memory) {
249
249
  this.memoryCache.forEach((_v, k) => {
250
- if (prefixes.some(prefix => k.startsWith(prefix))) {
250
+ if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
251
251
  this.memoryCache.delete(k);
252
252
  }
253
253
  });
@@ -135,6 +135,13 @@ export class BuildUtil {
135
135
  const distPrismaSchemaFile = path.join(distDir, path.basename(prismaSchemaFile));
136
136
  await fs.copyFile(prismaSchemaFile, distPrismaSchemaFile);
137
137
 
138
+ // 多 schema 文件兼容
139
+ const multipleSchemaDir = path.join(options.cwd, 'src/db/schema');
140
+ if (await fs.pathExists(multipleSchemaDir)) {
141
+ const distMultipleSchemaDir = path.join(distDir, path.basename(multipleSchemaDir));
142
+ await fs.copy(multipleSchemaDir, distMultipleSchemaDir);
143
+ }
144
+
138
145
  // 复制查询引擎
139
146
  const libqueryEngineFiles = await globby('libquery_engine-*', {
140
147
  cwd: path.join(options.cwd, 'node_modules/.prisma/client'),
package/lib/cli/cli.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import path from 'path';
2
3
  import chokidar from 'chokidar';
3
4
  import execa from 'execa';
5
+ import fs from 'fs-extra';
4
6
  import { generateManyIndex } from 'vscode-generate-index-standalone';
5
7
  import { castArray, debounce } from 'vtils';
6
8
  import yargs from 'yargs';
@@ -139,7 +141,13 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
139
141
  // 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
140
142
  // https://github.com/motdotla/dotenv#override
141
143
  process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
142
- await execa('tnpx', ['prisma', ...argv._.slice(1), '--schema', 'src/db/schema.prisma'], {
144
+
145
+ // 多 schema 文件兼容
146
+ // https://www.prisma.io/docs/orm/prisma-schema/overview/location#how-to-use-existing-prisma-cli-commands-with-multiple-prisma-schema-files
147
+ const schemaDir = path.join(process.cwd(), 'src/db/schema');
148
+ const isMultipleFiles = await fs.pathExists(schemaDir);
149
+ const schemaArg = isMultipleFiles ? 'src/db' : 'src/db/schema.prisma';
150
+ await execa('tnpx', ['prisma', ...argv._.slice(1), '--schema', schemaArg], {
143
151
  cwd: process.cwd(),
144
152
  stdio: 'inherit'
145
153
  });
@@ -18,11 +18,14 @@ type KeyPathForNumberValue<T extends Data> = {
18
18
  [K in keyof T]: T[K] extends (...args: infer X) => number ? IsEmptyArray<X> extends true ? K : [K, ...X] : never;
19
19
  }[keyof T];
20
20
  type Value<T extends Data, P extends KeyPath<T>> = ReturnType<T[P extends any[] ? P[0] : P]>;
21
+ type KeyPartialPath<T extends Data> = {
22
+ [K in keyof T]: T[K] extends (...args: infer X) => any ? IsEmptyArray<X> extends true ? K : [K, ...Partial<X>] : never;
23
+ }[keyof T];
21
24
  type CacheSetTTL<V> = MsValue | ((data: V, defaultTTL: MsValue) => MsValue);
22
25
  type CacheSetOptions<V> = CacheSetTTL<V> | {
23
26
  ttl?: CacheSetTTL<V>;
24
27
  };
25
- export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any> implements BaseService {
28
+ export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any, TKeyPartialPath extends KeyPartialPath<TData> = any> implements BaseService {
26
29
  options: CacheServiceOptions;
27
30
  serviceName: string;
28
31
  private prefix;
@@ -118,11 +121,11 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
118
121
  /**
119
122
  * 清空指定前缀的缓存。
120
123
  */
121
- clear<K extends TKey>(...prefixes: K[]): Promise<number>;
124
+ clear(...prefixes: Array<TKey | TKeyPartialPath>): Promise<number>;
122
125
  /**
123
126
  * 派生出一个指定类型的缓存服务。
124
127
  */
125
- fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
128
+ fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>, KeyPartialPath<TNextData>>;
126
129
  }
127
130
  declare module '../x' {
128
131
  interface X {
@@ -242,7 +242,7 @@ export class CacheService {
242
242
  }
243
243
  if (this.options.memory) {
244
244
  this.memoryCache.forEach((_v, k) => {
245
- if (prefixes.some(prefix => k.startsWith(prefix))) {
245
+ if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
246
246
  this.memoryCache.delete(k);
247
247
  }
248
248
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.51.0",
3
+ "version": "2.52.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",