@share-crm/sharedev-cli 0.0.4-rc.27 → 0.0.4-rc.28

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.
Files changed (2) hide show
  1. package/dist/sharedev.js +300 -19
  2. package/package.json +1 -1
package/dist/sharedev.js CHANGED
@@ -9969,17 +9969,41 @@ function registerDataAuthNamespace(program, runtimeContext) {
9969
9969
  /***/ },
9970
9970
 
9971
9971
  /***/ 7170
9972
- (__unused_webpack_module, exports) {
9972
+ (__unused_webpack_module, exports, __webpack_require__) {
9973
9973
 
9974
9974
 
9975
9975
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9976
9976
  exports.registerDataNamespace = registerDataNamespace;
9977
- function registerDataNamespace(program, _runtimeContext) {
9977
+ const command_ts_1 = __webpack_require__(528);
9978
+ const index_ts_1 = __webpack_require__(3542);
9979
+ function registerDataNamespace(program, runtimeContext) {
9978
9980
  const data = program.command('data').description('Data development workspace commands');
9979
9981
  data.addHelpText('after', `
9980
9982
  Examples:
9981
- $ sharedev data <二级命名空间> <命令>
9983
+ $ sharedev data record query-by-fields --object AccountObj --fields "_id,name,owner,create_time"
9984
+ $ sharedev data record query-by-fields --object AccountObj --fields "_id,name" --limit 20 --offset 0
9985
+ $ sharedev data record query-by-fields --object AccountObj --fields "_id,name" \\
9986
+ --filter '[{"field_name":"owner","operator":"eq","field_values":["2051"]}]' \\
9987
+ --order '[{"fieldName":"create_time","isAsc":false}]'
9982
9988
  `);
9989
+ // record 子命名空间
9990
+ const record = data.command('record').description('Data record operations');
9991
+ // record query-by-fields 子命令
9992
+ record
9993
+ .command('query-by-fields')
9994
+ .description('Query data records by fields (select_fields + search_template_query)')
9995
+ .requiredOption('--object <apiName>', 'Object api_name (e.g. AccountObj)')
9996
+ .requiredOption('--fields <csv>', 'Comma-separated select_fields (e.g. "_id,name,owner")')
9997
+ .option('--filter <json>', 'Filters as JSON array: [{"field_name","operator","field_values"}]')
9998
+ .option('--order <json>', 'Orders as JSON array: [{"fieldName","isAsc"}]')
9999
+ .option('--limit <n>', 'Page size (default 20)', '20')
10000
+ .option('--offset <n>', 'Page offset (default 0)', '0')
10001
+ .option('--need-count', 'Return total count (default true)')
10002
+ .option('--no-need-count', 'Do not return total count')
10003
+ .action((0, command_ts_1.createCommandAction)('data', 'record.query-by-fields', runtimeContext, async ({ options, context }) => {
10004
+ void context;
10005
+ await (0, index_ts_1.dataRecordQueryByFieldsCommand)(options);
10006
+ }));
9983
10007
  }
9984
10008
 
9985
10009
 
@@ -13578,6 +13602,9 @@ const SHARE_CLI_COMMAND_PATH_MAP = {
13578
13602
  webCustomPageUpdate: ['interface-dev', 'web-custom-page', 'update'],
13579
13603
  mobileCustomPageUpdate: ['interface-dev', 'mobile-custom-page', 'update'],
13580
13604
  },
13605
+ data: {
13606
+ recordQueryByFields: ['data', 'record', 'query-by-fields'],
13607
+ },
13581
13608
  };
13582
13609
  function getShareCliCommandPath(namespace, key) {
13583
13610
  const raw = SHARE_CLI_COMMAND_PATH_MAP[namespace][key];
@@ -13765,6 +13792,16 @@ class RequestService {
13765
13792
  }
13766
13793
  return this.axiosInstance;
13767
13794
  }
13795
+ /**
13796
+ * 干净的 axios 实例:无 baseURL、无 Authorization、无拦截器。
13797
+ * fetch 方法使用该实例,请求除 trace 与 debug 外不经过任何处理。
13798
+ */
13799
+ get cleanInstance() {
13800
+ if (!this.cleanAxiosInstance) {
13801
+ this.cleanAxiosInstance = axios_1.default.create({ timeout: 30000 });
13802
+ }
13803
+ return this.cleanAxiosInstance;
13804
+ }
13768
13805
  async request(config, requestSettings) {
13769
13806
  const traceableConfig = config;
13770
13807
  const rawUrl = traceableConfig.url ?? '';
@@ -13793,6 +13830,76 @@ class RequestService {
13793
13830
  }
13794
13831
  return result.Value ?? result;
13795
13832
  }
13833
+ /**
13834
+ * 干净的 HTTP 请求:除 trace 与 debug 外不经过任何处理。
13835
+ *
13836
+ * 与 request/FHH 的区别:
13837
+ * - 不使用配置的 baseURL 与 Authorization(适用于公网/外部 URL)
13838
+ * - 不改写 URL(不做 EM\dH -> EMDH 替换)
13839
+ * - 不注入 traceId 查询参数
13840
+ * - 不解包 FHH 响应信封、不提取 UserInfo
13841
+ * - 仅保留 traceService 埋点与 writeDebug 调试记录
13842
+ *
13843
+ * @param url 完整请求 URL
13844
+ * @returns 原始响应体(response.data)
13845
+ */
13846
+ async fetch(url, config, requestSettings) {
13847
+ const noDebug = !!requestSettings?.noDebug;
13848
+ const noTrace = !!requestSettings?.noTrace;
13849
+ const method = (config?.method ?? 'GET').toUpperCase();
13850
+ const fullUrl = url;
13851
+ const command = resolveDebugCommand({ ...config, url, method });
13852
+ const cliCommandRaw = resolveCliCommandRaw();
13853
+ const requestSnapshot = {
13854
+ params: config?.params,
13855
+ data: config?.data,
13856
+ headers: config?.headers
13857
+ };
13858
+ if (!noTrace) {
13859
+ (0, trace_ts_1.traceService)(fullUrl);
13860
+ }
13861
+ const writeDebugLog = !noDebug && (0, debug_ts_2.isRuntimeDebugEnabled)();
13862
+ try {
13863
+ const response = await this.cleanInstance.request({
13864
+ ...config,
13865
+ url,
13866
+ method: config?.method ?? 'GET'
13867
+ });
13868
+ if (writeDebugLog) {
13869
+ void (0, debug_ts_1.writeDebug)({
13870
+ command,
13871
+ cliCommandRaw,
13872
+ version: await readCliVersion(),
13873
+ url: fullUrl,
13874
+ method,
13875
+ request: requestSnapshot,
13876
+ response: response.data,
13877
+ status: response.status,
13878
+ success: true,
13879
+ timestamp: new Date().toISOString()
13880
+ });
13881
+ }
13882
+ return response.data;
13883
+ }
13884
+ catch (error) {
13885
+ const axiosError = error;
13886
+ if (writeDebugLog) {
13887
+ void (0, debug_ts_1.writeDebug)({
13888
+ command,
13889
+ cliCommandRaw,
13890
+ version: await readCliVersion(),
13891
+ url: fullUrl,
13892
+ method,
13893
+ request: requestSnapshot,
13894
+ response: axiosError.response?.data ?? { message: axiosError.message },
13895
+ status: axiosError.response?.status,
13896
+ success: false,
13897
+ timestamp: new Date().toISOString()
13898
+ });
13899
+ }
13900
+ throw error;
13901
+ }
13902
+ }
13796
13903
  }
13797
13904
  exports.requestService = new RequestService();
13798
13905
 
@@ -18542,6 +18649,179 @@ function narrowDataAuthResponse(value) {
18542
18649
  }
18543
18650
 
18544
18651
 
18652
+ /***/ },
18653
+
18654
+ /***/ 3542
18655
+ (__unused_webpack_module, exports, __webpack_require__) {
18656
+
18657
+
18658
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
18659
+ exports.dataRecordQueryByFieldsCommand = void 0;
18660
+ var record_ts_1 = __webpack_require__(6409);
18661
+ Object.defineProperty(exports, "dataRecordQueryByFieldsCommand", ({ enumerable: true, get: function () { return record_ts_1.dataRecordQueryByFieldsCommand; } }));
18662
+
18663
+
18664
+ /***/ },
18665
+
18666
+ /***/ 6409
18667
+ (__unused_webpack_module, exports, __webpack_require__) {
18668
+
18669
+
18670
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18671
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18672
+ };
18673
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
18674
+ exports.dataRecordQueryByFieldsCommand = dataRecordQueryByFieldsCommand;
18675
+ const logger_ts_1 = __webpack_require__(3333);
18676
+ const normalize_ts_1 = __importDefault(__webpack_require__(9268));
18677
+ const record_query_by_fields_ts_1 = __webpack_require__(8537);
18678
+ /**
18679
+ * 解析逗号分隔的字段列表
18680
+ */
18681
+ function parseFields(value) {
18682
+ const raw = normalize_ts_1.default.normalizeString(value);
18683
+ if (!raw)
18684
+ return [];
18685
+ return raw
18686
+ .split(',')
18687
+ .map((item) => item.trim())
18688
+ .filter((item) => item.length > 0);
18689
+ }
18690
+ /**
18691
+ * 解析 JSON 数组
18692
+ */
18693
+ function parseJsonArray(value, field) {
18694
+ const raw = normalize_ts_1.default.normalizeString(value);
18695
+ if (!raw)
18696
+ return undefined;
18697
+ try {
18698
+ const parsed = JSON.parse(raw);
18699
+ if (!Array.isArray(parsed)) {
18700
+ throw new Error(`--${field} must be a JSON array.`);
18701
+ }
18702
+ return parsed;
18703
+ }
18704
+ catch (error) {
18705
+ throw new Error(`--${field} must be a valid JSON array: ${error instanceof Error ? error.message : String(error)}`);
18706
+ }
18707
+ }
18708
+ /**
18709
+ * data record query-by-fields 命令
18710
+ * 按字段查询数据记录
18711
+ */
18712
+ async function dataRecordQueryByFieldsCommand(options) {
18713
+ // 校验必填参数
18714
+ const objectApiName = normalize_ts_1.default.normalizeString(options.object);
18715
+ if (!objectApiName) {
18716
+ throw new Error('--object is required (object_api_name).');
18717
+ }
18718
+ const selectFields = parseFields(options.fields);
18719
+ if (selectFields.length === 0) {
18720
+ throw new Error('--fields is required (comma-separated select_fields).');
18721
+ }
18722
+ const filters = parseJsonArray(options.filter, 'filter');
18723
+ const orders = parseJsonArray(options.order, 'order');
18724
+ const limit = options.limit !== undefined ? Number(options.limit) : 20;
18725
+ const offset = options.offset !== undefined ? Number(options.offset) : 0;
18726
+ if (!Number.isFinite(limit) || limit < 0) {
18727
+ throw new Error('--limit must be a non-negative number.');
18728
+ }
18729
+ if (!Number.isFinite(offset) || offset < 0) {
18730
+ throw new Error('--offset must be a non-negative number.');
18731
+ }
18732
+ const needCount = options.needCount !== undefined ? options.needCount === true : true;
18733
+ logger_ts_1.loggerService.startLoading('Querying data records...');
18734
+ const result = await (0, record_query_by_fields_ts_1.recordQueryByFieldsService)({
18735
+ objectApiName,
18736
+ needCount,
18737
+ selectFields,
18738
+ searchTemplateQuery: {
18739
+ filters,
18740
+ orders,
18741
+ limit,
18742
+ offset,
18743
+ },
18744
+ });
18745
+ logger_ts_1.loggerService.stopLoading();
18746
+ if (!result.success) {
18747
+ throw new Error(result.errorMessage);
18748
+ }
18749
+ logger_ts_1.loggerService.printJson(result.data);
18750
+ logger_ts_1.loggerService.success(`Data record query completed: object=${objectApiName}, limit=${limit}, offset=${offset}`);
18751
+ }
18752
+
18753
+
18754
+ /***/ },
18755
+
18756
+ /***/ 8537
18757
+ (__unused_webpack_module, exports, __webpack_require__) {
18758
+
18759
+
18760
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
18761
+ exports.recordQueryByFieldsService = recordQueryByFieldsService;
18762
+ const request_execute_command_paths_ts_1 = __webpack_require__(2351);
18763
+ const request_ts_1 = __webpack_require__(6393);
18764
+ /**
18765
+ * 查询数据记录(按字段查询)
18766
+ *
18767
+ * 调用 share-cli execute 接口,commandPath = ['data', 'record', 'query-by-fields']
18768
+ * options.raw = true,aiContext.scene = 'cli'
18769
+ */
18770
+ async function recordQueryByFieldsService(options) {
18771
+ const commandPath = (0, request_execute_command_paths_ts_1.getShareCliCommandPath)('data', 'recordQueryByFields');
18772
+ const data = {
18773
+ object_api_name: options.objectApiName,
18774
+ need_count: options.needCount,
18775
+ select_fields: options.selectFields,
18776
+ search_template_query: options.searchTemplateQuery,
18777
+ };
18778
+ const others = {
18779
+ options: { raw: true },
18780
+ aiContext: { scene: 'cli' },
18781
+ };
18782
+ const response = await (0, request_ts_1.requestDataExecute)(commandPath, data, others);
18783
+ const result = await (0, request_ts_1.extractDataServiceResult)(response, (res) => {
18784
+ return res.data;
18785
+ });
18786
+ return result;
18787
+ }
18788
+
18789
+
18790
+ /***/ },
18791
+
18792
+ /***/ 6393
18793
+ (__unused_webpack_module, exports, __webpack_require__) {
18794
+
18795
+
18796
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18797
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18798
+ };
18799
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
18800
+ exports.requestDataExecute = requestDataExecute;
18801
+ exports.extractDataServiceResult = extractDataServiceResult;
18802
+ const request_execute_ts_1 = __webpack_require__(8554);
18803
+ const normalize_ts_1 = __importDefault(__webpack_require__(9268));
18804
+ async function requestDataExecute(commandPath, data, others) {
18805
+ const response = await (0, request_execute_ts_1.executeShareCliCommand)(commandPath, data, others);
18806
+ if (!response || typeof response !== 'object') {
18807
+ throw new Error('Response is not an object or is empty.');
18808
+ }
18809
+ return response;
18810
+ }
18811
+ async function extractDataServiceResult(response, dataGetter) {
18812
+ if (!response || typeof response !== 'object') {
18813
+ throw new Error('Response is not an object or is empty.');
18814
+ }
18815
+ if (response.success === true && response.code === 'OK') {
18816
+ const data = await dataGetter(response);
18817
+ return { success: true, errorMessage: '', data };
18818
+ }
18819
+ else {
18820
+ return { success: false, errorMessage: normalize_ts_1.default.normalizeText(response.message) || 'Unknown error.', data: undefined };
18821
+ }
18822
+ }
18823
+
18824
+
18545
18825
  /***/ },
18546
18826
 
18547
18827
  /***/ 707
@@ -30379,14 +30659,11 @@ async function runSpecInit(cwd, options = {}) {
30379
30659
  const showLoading = options.showLoading !== false;
30380
30660
  // 1. 读取本地 specVersion
30381
30661
  const localVersion = await (0, index_ts_1.readLocalSpecVersion)(cwd);
30382
- // 2. 版本检查:拉取远端 manifest 并比对
30662
+ // 2. 拉取远端 manifest(init 需要 manifest 本体,不走 specCheckService——
30663
+ // 后者在 currentVersion 为空时会短路返回且不拉取 manifest)
30383
30664
  let manifest;
30384
30665
  try {
30385
- const checkResult = await (0, index_ts_1.specCheckService)(localVersion ?? '');
30386
- if (!checkResult.manifest) {
30387
- throw new Error(checkResult.errorMessage || 'Failed to fetch spec manifest.');
30388
- }
30389
- manifest = checkResult.manifest;
30666
+ manifest = await (0, index_ts_1.requestSpecManifest)();
30390
30667
  }
30391
30668
  catch (error) {
30392
30669
  if (showLoading) {
@@ -30395,10 +30672,10 @@ async function runSpecInit(cwd, options = {}) {
30395
30672
  throw error;
30396
30673
  }
30397
30674
  // 3. 已是最新版本则跳过
30398
- if (!options.skipVersionCheck && localVersion && localVersion === manifest.version) {
30399
- logger_ts_1.loggerService.info(`Spec template is already up-to-date (version: ${manifest.version}).`);
30400
- return;
30401
- }
30675
+ // if (!options.skipVersionCheck && localVersion && localVersion === manifest.version) {
30676
+ // loggerService.info(`Spec template is already up-to-date (version: ${manifest.version}).`);
30677
+ // return;
30678
+ // }
30402
30679
  // 4. 解析 agent 平台
30403
30680
  const selectedAgents = await resolveAgentOptions(options.agentName);
30404
30681
  const targets = selectedAgents.map((item) => ({
@@ -30467,18 +30744,22 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
30467
30744
  exports.requestSpecArchive = exports.requestSpecManifest = void 0;
30468
30745
  const download_ts_1 = __webpack_require__(1889);
30469
30746
  const logger_ts_1 = __webpack_require__(3333);
30747
+ const request_ts_1 = __webpack_require__(2088);
30470
30748
  const spec_config_ts_1 = __webpack_require__(8102);
30471
30749
  /**
30472
30750
  * 拉取 spec 模板远端 manifest
30473
30751
  * @param signal 可选 AbortSignal,用于启动检查时加超时控制
30474
30752
  */
30475
30753
  const requestSpecManifest = async (signal) => {
30476
- const response = await fetch(spec_config_ts_1.SPEC_MANIFEST_URL, { signal });
30477
- if (!response.ok) {
30478
- throw new Error(`Failed to fetch spec manifest: ${response.status} ${response.statusText}`);
30754
+ let data;
30755
+ try {
30756
+ data = await request_ts_1.requestService.fetch(spec_config_ts_1.SPEC_MANIFEST_URL, { signal });
30757
+ }
30758
+ catch (error) {
30759
+ const message = error instanceof Error ? error.message : String(error);
30760
+ throw new Error(`Failed to fetch spec manifest: ${message}`);
30479
30761
  }
30480
- const data = (await response.json());
30481
- if (!data.version || !data.archive) {
30762
+ if (!data || !data.version || !data.archive) {
30482
30763
  throw new Error('Invalid spec manifest: missing version or archive field.');
30483
30764
  }
30484
30765
  return data;
@@ -46460,7 +46741,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
46460
46741
  /***/ 8330
46461
46742
  (module) {
46462
46743
 
46463
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@share-crm/sharedev-cli","version":"0.0.4-rc.27","private":false,"description":"sharedev command line tool","type":"module","main":"dist/sharedev.js","bin":{"sharedev":"./bin/cli.mjs"},"author":{"name":"sharecrm-npm"},"files":["dist","bin","README.md"],"scripts":{"build":"tsc --noEmit && webpack --config build/webpack/webpack.prod.cjs","build:debug":"tsc --noEmit && webpack --config build/webpack/webpack.debug.cjs","build:bin":"bun build --compile --target=bun-darwin-x64 src/cli.ts --outfile scripts/sharedev-darwin-x64 && bun build --compile --target=bun-darwin-arm64 src/cli.ts --outfile scripts/sharedev-darwin-arm64 && bun build --compile --target=bun-windows-x64 src/cli.ts --outfile scripts/sharedev-windows-x64.exe","build:all":"npm run build && npm run build:bin","dev":"tsc --noEmit --watch & webpack --config build/webpack/webpack.dev.cjs --watch","dev2":"node src/cli.ts","typecheck":"tsc --noEmit","prettier":"prettier --write ./src/**/*.ts","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage"},"dependencies":{"@clack/prompts":"^1.1.0","@mariozechner/pi-coding-agent":"^0.62.0","axios":"~1.13.0","chalk":"^5.6.2","commander":"^14.0.1","extract-zip":"^2.0.1","fast-xml-parser":"^5.2.5","fs-extra":"^11.3.2","lodash-es":"^4.18.1","ora":"^9.3.0","terser-webpack-plugin":"^5.6.1"},"devDependencies":{"@types/extract-zip":"^2.0.3","@types/fs-extra":"^11.0.4","@types/lodash-es":"^4.17.12","@types/node":"^24.3.0","@vitest/coverage-v8":"^4.1.8","ts-loader":"^9.5.4","typescript":"^5.9.2","vitest":"^3.2.6","webpack":"^5.101.3","webpack-cli":"^6.0.1","webpack-merge":"^6.0.1"},"packageManager":"pnpm@10.17.0"}');
46744
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@share-crm/sharedev-cli","version":"0.0.4-rc.28","private":false,"description":"sharedev command line tool","type":"module","main":"dist/sharedev.js","bin":{"sharedev":"./bin/cli.mjs"},"author":{"name":"sharecrm-npm"},"files":["dist","bin","README.md"],"scripts":{"build":"tsc --noEmit && webpack --config build/webpack/webpack.prod.cjs","build:debug":"tsc --noEmit && webpack --config build/webpack/webpack.debug.cjs","build:bin":"bun build --compile --target=bun-darwin-x64 src/cli.ts --outfile scripts/sharedev-darwin-x64 && bun build --compile --target=bun-darwin-arm64 src/cli.ts --outfile scripts/sharedev-darwin-arm64 && bun build --compile --target=bun-windows-x64 src/cli.ts --outfile scripts/sharedev-windows-x64.exe","build:all":"npm run build && npm run build:bin","dev":"tsc --noEmit --watch & webpack --config build/webpack/webpack.dev.cjs --watch","dev2":"node src/cli.ts","typecheck":"tsc --noEmit","prettier":"prettier --write ./src/**/*.ts","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage"},"dependencies":{"@clack/prompts":"^1.1.0","@mariozechner/pi-coding-agent":"^0.62.0","axios":"~1.13.0","chalk":"^5.6.2","commander":"^14.0.1","extract-zip":"^2.0.1","fast-xml-parser":"^5.2.5","fs-extra":"^11.3.2","lodash-es":"^4.18.1","ora":"^9.3.0","terser-webpack-plugin":"^5.6.1"},"devDependencies":{"@types/extract-zip":"^2.0.3","@types/fs-extra":"^11.0.4","@types/lodash-es":"^4.17.12","@types/node":"^24.3.0","@vitest/coverage-v8":"^4.1.8","ts-loader":"^9.5.4","typescript":"^5.9.2","vitest":"^3.2.6","webpack":"^5.101.3","webpack-cli":"^6.0.1","webpack-merge":"^6.0.1"},"packageManager":"pnpm@10.17.0"}');
46464
46745
 
46465
46746
  /***/ }
46466
46747
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@share-crm/sharedev-cli",
3
- "version": "0.0.4-rc.27",
3
+ "version": "0.0.4-rc.28",
4
4
  "private": false,
5
5
  "description": "sharedev command line tool",
6
6
  "type": "module",