@ldsg/utils 0.3.31 → 0.3.33

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/dist/browser.cjs CHANGED
@@ -68,13 +68,13 @@ const external_lodash_namespaceObject = require("lodash");
68
68
  var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
69
69
  const replaceResourceIdsInString = (params)=>{
70
70
  const { jsonString, oldResourceIdToNewResourceIdMap } = params;
71
- const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
72
- if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
71
+ const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || "(empty)");
72
+ if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(", ")}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
73
73
  let result = jsonString;
74
74
  const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
75
75
  for (const [oldResourceId, newResourceId] of entries){
76
- const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
77
- const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
76
+ const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
77
+ const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, "g");
78
78
  result = result.replace(regex, newResourceId);
79
79
  }
80
80
  const res = {
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * 浏览器安全入口 - 仅导出纯函数,不依赖 Node.js 包
3
3
  */
4
- export { getTreeResourceRecords } from './get-tree-resource-records';
5
- export { replaceResourceIds } from './replace-resource-ids';
4
+ export { getTreeResourceRecords } from "./get-tree-resource-records";
5
+ export { replaceResourceIds } from "./replace-resource-ids";
package/dist/browser.js CHANGED
@@ -29,13 +29,13 @@ const getTreeResourceRecords = (params)=>{
29
29
  };
30
30
  const replaceResourceIdsInString = (params)=>{
31
31
  const { jsonString, oldResourceIdToNewResourceIdMap } = params;
32
- const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
33
- if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
32
+ const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || "(empty)");
33
+ if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(", ")}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
34
34
  let result = jsonString;
35
35
  const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
36
36
  for (const [oldResourceId, newResourceId] of entries){
37
- const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
- const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
37
+ const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
38
+ const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, "g");
39
39
  result = result.replace(regex, newResourceId);
40
40
  }
41
41
  const res = {
@@ -1,2 +1,2 @@
1
- export * from './types';
2
- export * from './utils';
1
+ export * from "./types";
2
+ export * from "./utils";
@@ -1,2 +1,2 @@
1
- export * from './handler-service-settings';
2
- export * from './service-record';
1
+ export * from "./handler-service-settings";
2
+ export * from "./service-record";
@@ -1,4 +1,4 @@
1
- import { Service, Settings } from '@ldsg/core';
1
+ import { Service, Settings } from "@ldsg/core";
2
2
  export interface ServiceRecord {
3
3
  id: string;
4
4
  parentId?: string;
@@ -1,4 +1,4 @@
1
- export * from './instantiate-service';
2
- export * from './instantiate-services';
3
- export * from './sync-rush-projects';
4
- export * from './zip-app-data';
1
+ export * from "./instantiate-service";
2
+ export * from "./instantiate-services";
3
+ export * from "./sync-rush-projects";
4
+ export * from "./zip-app-data";
@@ -1,5 +1,5 @@
1
- import { Service, ServiceProperties } from '@ldsg/core';
2
- import { ServiceRecords, ServiceTypeMap } from '../types';
1
+ import { Service, ServiceProperties } from "@ldsg/core";
2
+ import { ServiceRecords, ServiceTypeMap } from "../types";
3
3
  export interface InstantiateServiceParams {
4
4
  serviceProperties: ServiceProperties;
5
5
  serviceRecords?: ServiceRecords;
@@ -1,6 +1,6 @@
1
- import { Service } from '@ldsg/core';
2
- import { ServiceRecords, ServiceTypeMap } from '../types';
3
- import { InstantiateService } from './instantiate-service';
1
+ import { Service } from "@ldsg/core";
2
+ import { ServiceRecords, ServiceTypeMap } from "../types";
3
+ import { InstantiateService } from "./instantiate-service";
4
4
  export interface InstantiateServicesParams {
5
5
  serviceRecords: ServiceRecords;
6
6
  instantiateService?: InstantiateService;
@@ -1,8 +1,8 @@
1
- import { AppData } from '@ldsg/types';
2
- import JSZip from 'jszip';
3
- import { ZipAppDataLayout } from './constants';
4
- export * from './constants';
5
- export * from './utils';
1
+ import { AppData } from "@ldsg/types";
2
+ import JSZip from "jszip";
3
+ import { ZipAppDataLayout } from "./constants";
4
+ export * from "./constants";
5
+ export * from "./utils";
6
6
  export interface AppDataWithAppModuleHandlerDependencyVersionTemplate extends AppData {
7
7
  appModuleHandlerDependencyVersionTemplate?: string;
8
8
  }
@@ -1,5 +1,5 @@
1
- import { AppDataFile, FileData } from '@ldsg/types';
2
- import JSZip from 'jszip';
1
+ import { AppDataFile, FileData } from "@ldsg/types";
2
+ import JSZip from "jszip";
3
3
  interface AddFileToZipFolderParams extends AppDataFile {
4
4
  folder: JSZip;
5
5
  data: FileData;
@@ -1,4 +1,4 @@
1
- import { HandlerResourceDependency } from '@ldsg/handler';
1
+ import { HandlerResourceDependency } from "@ldsg/handler";
2
2
  interface GetHandlerPackageJsonParams {
3
3
  packageJson: PackageJson;
4
4
  moduleName: string;
@@ -1,2 +1,2 @@
1
- export * from './add-file-to-zip-folder';
2
- export * from './get-handler-package-json';
1
+ export * from "./add-file-to-zip-folder";
2
+ export * from "./get-handler-package-json";
@@ -1,4 +1,4 @@
1
- import { AppData } from '@ldsg/types';
1
+ import { AppData } from "@ldsg/types";
2
2
  export interface ExtendAppDataWithPathParams {
3
3
  appData: AppData;
4
4
  extraAppDataPath?: string;
@@ -1,4 +1,4 @@
1
- import { AppData } from '@ldsg/types';
1
+ import { AppData } from "@ldsg/types";
2
2
  export interface ExtendAppDataParams {
3
3
  appData: AppData;
4
4
  extraAppData?: Partial<AppData>;
@@ -1,4 +1,4 @@
1
- import { AppData, ResourceRecords } from '@ldsg/types';
1
+ import { AppData, ResourceRecords } from "@ldsg/types";
2
2
  export interface LoadAppResourceRecordsParams {
3
3
  appDataUri?: string;
4
4
  apaasAppDataUri?: string;
@@ -6,7 +6,7 @@ export interface LoadAppResourceRecordsParams {
6
6
  }
7
7
  export interface LoadAppResourceRecordsRes {
8
8
  resourceRecords: ResourceRecords;
9
- sourceType: 'apaas' | 'runtime';
9
+ sourceType: "apaas" | "runtime";
10
10
  }
11
11
  export declare const loadAppResourceRecords: (params: LoadAppResourceRecordsParams) => Promise<LoadAppResourceRecordsRes>;
12
12
  export interface FetchAppDataParams {
@@ -1,4 +1,4 @@
1
- import { AppData } from '@ldsg/types';
1
+ import { AppData } from "@ldsg/types";
2
2
  interface GenerateByAppDataParams {
3
3
  appData: AppData;
4
4
  outputPath: string;
@@ -1,5 +1,5 @@
1
- import { AppData } from '@ldsg/types';
2
- import { FetchAppDataParams } from './fetch-app-data';
1
+ import { AppData } from "@ldsg/types";
2
+ import { FetchAppDataParams } from "./fetch-app-data";
3
3
  interface GetAppDataParams extends FetchAppDataParams {
4
4
  extraAppDataPath?: string;
5
5
  }
@@ -1,4 +1,4 @@
1
- import { ResourceRecords } from '@ldsg/types';
1
+ import { ResourceRecords } from "@ldsg/types";
2
2
  interface GetTreeResourceRecordsParams {
3
3
  resourceRecords: ResourceRecords;
4
4
  rootId: string;
package/dist/index.cjs CHANGED
@@ -78,7 +78,7 @@ const instantiateServices = (params)=>{
78
78
  const instantiate_service_instantiateService = (params)=>{
79
79
  const { serviceProperties, serviceRecords, serviceTypeMap } = params;
80
80
  const { type } = serviceProperties;
81
- if (!type) throw new Error('service type is required');
81
+ if (!type) throw new Error("service type is required");
82
82
  const ServiceConstructor = serviceTypeMap?.[type]?.class || core_namespaceObject.Service;
83
83
  const service = new ServiceConstructor(serviceProperties);
84
84
  if (serviceRecords) {
@@ -99,14 +99,14 @@ const external_lodash_namespaceObject = require("lodash");
99
99
  var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
100
100
  const external_path_namespaceObject = require("path");
101
101
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
102
- const RUSH_JSON_PATH = external_path_default().resolve(process.cwd(), '../../rush.json');
102
+ const RUSH_JSON_PATH = external_path_default().resolve(process.cwd(), "../../rush.json");
103
103
  function syncRushProjects(rushJsonPath, generatedProjects) {
104
104
  const rushJson = external_fs_extra_default().readJsonSync(rushJsonPath);
105
- const nonGenerated = rushJson.projects.filter((p)=>!p.projectFolder.startsWith('generated/'));
105
+ const nonGenerated = rushJson.projects.filter((p)=>!p.projectFolder.startsWith("generated/"));
106
106
  rushJson.projects = external_lodash_default().sortBy(external_lodash_default().uniqBy([
107
107
  ...nonGenerated,
108
108
  ...generatedProjects
109
- ], 'projectFolder'), 'projectFolder');
109
+ ], "projectFolder"), "projectFolder");
110
110
  external_fs_extra_default().writeJsonSync(rushJsonPath, rushJson, {
111
111
  spaces: 2
112
112
  });
@@ -115,8 +115,8 @@ const apaas_constants_namespaceObject = require("@ldsg/apaas-constants");
115
115
  const constants_namespaceObject = require("@ldsg/constants");
116
116
  const external_jszip_namespaceObject = require("jszip");
117
117
  var external_jszip_default = /*#__PURE__*/ __webpack_require__.n(external_jszip_namespaceObject);
118
- const DEFAULT_APP_MODULE_HANDLER_DEPENDENCY_VERSION_TEMPLATE = 'workspace:*';
119
- const DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME = 'handlers';
118
+ const DEFAULT_APP_MODULE_HANDLER_DEPENDENCY_VERSION_TEMPLATE = "workspace:*";
119
+ const DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME = "handlers";
120
120
  var constants_ZipAppDataLayout = /*#__PURE__*/ function(ZipAppDataLayout) {
121
121
  ZipAppDataLayout["FLAT"] = "flat";
122
122
  ZipAppDataLayout["NESTED"] = "nested";
@@ -128,12 +128,12 @@ const addFileToZipFolder = (params)=>{
128
128
  };
129
129
  const getHandlerPackageJson = (params)=>{
130
130
  const { moduleName, dependencies, reuseMainAppDependencies, packageJson } = params;
131
- external_lodash_default().set(packageJson, 'name', moduleName);
131
+ external_lodash_default().set(packageJson, "name", moduleName);
132
132
  const packageJsonDependencies = external_lodash_default().omit(external_lodash_default().fromPairs(dependencies.map((value)=>[
133
133
  value.name,
134
- value.version ?? 'latest'
134
+ value.version ?? "latest"
135
135
  ])), reuseMainAppDependencies);
136
- external_lodash_default().set(packageJson, 'dependencies', packageJsonDependencies);
136
+ external_lodash_default().set(packageJson, "dependencies", packageJsonDependencies);
137
137
  const res = {
138
138
  packageJson
139
139
  };
@@ -159,26 +159,26 @@ const zipAppData = async (params)=>{
159
159
  handlerModuleParentFolder = appModuleFolder.folder(DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME);
160
160
  break;
161
161
  }
162
- if (!appModuleFolder) throw new Error('invalid app folder');
163
- if (!handlerModuleParentFolder) throw new Error('invalid handler module parent folder');
162
+ if (!appModuleFolder) throw new Error("invalid app folder");
163
+ if (!handlerModuleParentFolder) throw new Error("invalid handler module parent folder");
164
164
  for (const file of filesInAppModele){
165
165
  const { path } = file;
166
166
  let data;
167
167
  switch(path){
168
- case 'manifest.json':
169
- data = external_lodash_default().pick(params, 'resourceRecords');
168
+ case "manifest.json":
169
+ data = external_lodash_default().pick(params, "resourceRecords");
170
170
  break;
171
- case '.env':
172
- if (environmentVariables) data = external_lodash_default().toPairs(environmentVariables).map((value)=>value.join('=')).join('\n');
171
+ case ".env":
172
+ if (environmentVariables) data = external_lodash_default().toPairs(environmentVariables).map((value)=>value.join("=")).join("\n");
173
173
  break;
174
174
  default:
175
175
  {
176
176
  const omitPaths = [
177
- '.gitignore',
178
- 'pnpm-lock.yaml'
177
+ ".gitignore",
178
+ "pnpm-lock.yaml"
179
179
  ];
180
180
  if (!omitPaths.includes(path)) {
181
- if ('data' in file) data = file.data;
181
+ if ("data" in file) data = file.data;
182
182
  }
183
183
  break;
184
184
  }
@@ -197,10 +197,10 @@ const zipAppData = async (params)=>{
197
197
  const { path } = file;
198
198
  let data;
199
199
  switch(path){
200
- case 'index.ts':
200
+ case "index.ts":
201
201
  data = code;
202
202
  break;
203
- case 'package.json':
203
+ case "package.json":
204
204
  {
205
205
  const { packageJson } = getHandlerPackageJson({
206
206
  packageJson: file.data,
@@ -212,7 +212,7 @@ const zipAppData = async (params)=>{
212
212
  break;
213
213
  }
214
214
  default:
215
- if ('data' in file) data = file.data;
215
+ if ("data" in file) data = file.data;
216
216
  break;
217
217
  }
218
218
  if (data) addFileToZipFolder({
@@ -256,7 +256,7 @@ var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_
256
256
  const external_jsonata_namespaceObject = require("jsonata");
257
257
  var external_jsonata_default = /*#__PURE__*/ __webpack_require__.n(external_jsonata_namespaceObject);
258
258
  const readSourceData = async (uri)=>{
259
- if (external_lodash_default().startsWith(uri, 'http')) {
259
+ if (external_lodash_default().startsWith(uri, "http")) {
260
260
  const axiosRes = await external_axios_default()({
261
261
  url: uri
262
262
  });
@@ -269,7 +269,7 @@ const loadAppResourceRecords = async (params)=>{
269
269
  const { appDataUri, apaasAppDataUri, apaasAppDataExpression } = params;
270
270
  if (apaasAppDataUri) {
271
271
  const rawData = await readSourceData(apaasAppDataUri);
272
- const expression = apaasAppDataExpression || '$';
272
+ const expression = apaasAppDataExpression || "$";
273
273
  const exp = external_jsonata_default()(expression);
274
274
  const appData = await exp.evaluate(rawData);
275
275
  const { resourceRecords } = appData;
@@ -281,14 +281,14 @@ const loadAppResourceRecords = async (params)=>{
281
281
  }));
282
282
  return {
283
283
  resourceRecords: apaasRecords,
284
- sourceType: 'apaas'
284
+ sourceType: "apaas"
285
285
  };
286
286
  }
287
- if (!appDataUri) throw new Error('Missing appDataUri or apaasAppDataUri');
287
+ if (!appDataUri) throw new Error("Missing appDataUri or apaasAppDataUri");
288
288
  const appData = await readSourceData(appDataUri);
289
289
  return {
290
290
  resourceRecords: appData.resourceRecords,
291
- sourceType: 'runtime'
291
+ sourceType: "runtime"
292
292
  };
293
293
  };
294
294
  const fetchAppData = async (params)=>{
@@ -305,7 +305,7 @@ const generateByAppData = async (params)=>{
305
305
  const { appData, outputPath } = params;
306
306
  const zipAppDataRes = await zipAppData({
307
307
  ...appData,
308
- type: 'nodebuffer'
308
+ type: "nodebuffer"
309
309
  });
310
310
  const { archive } = zipAppDataRes;
311
311
  const admZip = new (external_adm_zip_default())(archive);
@@ -359,21 +359,21 @@ const getTreeResourceRecords = (params)=>{
359
359
  const prepare = async (params)=>{
360
360
  const { outputPath } = params;
361
361
  const { archive } = await zipAppData({
362
- ...external_lodash_default().omit(params, 'outputPath'),
363
- type: 'nodebuffer'
362
+ ...external_lodash_default().omit(params, "outputPath"),
363
+ type: "nodebuffer"
364
364
  });
365
365
  const admZip = new (external_adm_zip_default())(archive);
366
366
  admZip.extractAllTo(outputPath, true);
367
367
  };
368
368
  const replaceResourceIdsInString = (params)=>{
369
369
  const { jsonString, oldResourceIdToNewResourceIdMap } = params;
370
- const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
371
- if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
370
+ const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || "(empty)");
371
+ if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(", ")}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
372
372
  let result = jsonString;
373
373
  const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
374
374
  for (const [oldResourceId, newResourceId] of entries){
375
- const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
376
- const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
375
+ const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
376
+ const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, "g");
377
377
  result = result.replace(regex, newResourceId);
378
378
  }
379
379
  const res = {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export * from './common';
2
- export * from './extend-app-data';
3
- export * from './extend-app-data-with-path';
4
- export * from './fetch-app-data';
5
- export * from './generate';
6
- export * from './generate-by-app-data';
7
- export * from './get-app-data';
8
- export * from './get-tree-resource-records';
9
- export * from './prepare';
10
- export * from './replace-resource-ids';
1
+ export * from "./common";
2
+ export * from "./extend-app-data";
3
+ export * from "./extend-app-data-with-path";
4
+ export * from "./fetch-app-data";
5
+ export * from "./generate";
6
+ export * from "./generate-by-app-data";
7
+ export * from "./get-app-data";
8
+ export * from "./get-tree-resource-records";
9
+ export * from "./prepare";
10
+ export * from "./replace-resource-ids";
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ const instantiateServices = (params)=>{
30
30
  const instantiate_service_instantiateService = (params)=>{
31
31
  const { serviceProperties, serviceRecords, serviceTypeMap } = params;
32
32
  const { type } = serviceProperties;
33
- if (!type) throw new Error('service type is required');
33
+ if (!type) throw new Error("service type is required");
34
34
  const ServiceConstructor = serviceTypeMap?.[type]?.class || Service;
35
35
  const service = new ServiceConstructor(serviceProperties);
36
36
  if (serviceRecords) {
@@ -45,20 +45,20 @@ const instantiate_service_instantiateService = (params)=>{
45
45
  };
46
46
  return res;
47
47
  };
48
- const RUSH_JSON_PATH = path_0.resolve(process.cwd(), '../../rush.json');
48
+ const RUSH_JSON_PATH = path_0.resolve(process.cwd(), "../../rush.json");
49
49
  function syncRushProjects(rushJsonPath, generatedProjects) {
50
50
  const rushJson = fs_extra.readJsonSync(rushJsonPath);
51
- const nonGenerated = rushJson.projects.filter((p)=>!p.projectFolder.startsWith('generated/'));
51
+ const nonGenerated = rushJson.projects.filter((p)=>!p.projectFolder.startsWith("generated/"));
52
52
  rushJson.projects = lodash.sortBy(lodash.uniqBy([
53
53
  ...nonGenerated,
54
54
  ...generatedProjects
55
- ], 'projectFolder'), 'projectFolder');
55
+ ], "projectFolder"), "projectFolder");
56
56
  fs_extra.writeJsonSync(rushJsonPath, rushJson, {
57
57
  spaces: 2
58
58
  });
59
59
  }
60
- const DEFAULT_APP_MODULE_HANDLER_DEPENDENCY_VERSION_TEMPLATE = 'workspace:*';
61
- const DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME = 'handlers';
60
+ const DEFAULT_APP_MODULE_HANDLER_DEPENDENCY_VERSION_TEMPLATE = "workspace:*";
61
+ const DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME = "handlers";
62
62
  var constants_ZipAppDataLayout = /*#__PURE__*/ function(ZipAppDataLayout) {
63
63
  ZipAppDataLayout["FLAT"] = "flat";
64
64
  ZipAppDataLayout["NESTED"] = "nested";
@@ -70,12 +70,12 @@ const addFileToZipFolder = (params)=>{
70
70
  };
71
71
  const getHandlerPackageJson = (params)=>{
72
72
  const { moduleName, dependencies, reuseMainAppDependencies, packageJson } = params;
73
- lodash.set(packageJson, 'name', moduleName);
73
+ lodash.set(packageJson, "name", moduleName);
74
74
  const packageJsonDependencies = lodash.omit(lodash.fromPairs(dependencies.map((value)=>[
75
75
  value.name,
76
- value.version ?? 'latest'
76
+ value.version ?? "latest"
77
77
  ])), reuseMainAppDependencies);
78
- lodash.set(packageJson, 'dependencies', packageJsonDependencies);
78
+ lodash.set(packageJson, "dependencies", packageJsonDependencies);
79
79
  const res = {
80
80
  packageJson
81
81
  };
@@ -101,26 +101,26 @@ const zipAppData = async (params)=>{
101
101
  handlerModuleParentFolder = appModuleFolder.folder(DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME);
102
102
  break;
103
103
  }
104
- if (!appModuleFolder) throw new Error('invalid app folder');
105
- if (!handlerModuleParentFolder) throw new Error('invalid handler module parent folder');
104
+ if (!appModuleFolder) throw new Error("invalid app folder");
105
+ if (!handlerModuleParentFolder) throw new Error("invalid handler module parent folder");
106
106
  for (const file of filesInAppModele){
107
107
  const { path } = file;
108
108
  let data;
109
109
  switch(path){
110
- case 'manifest.json':
111
- data = lodash.pick(params, 'resourceRecords');
110
+ case "manifest.json":
111
+ data = lodash.pick(params, "resourceRecords");
112
112
  break;
113
- case '.env':
114
- if (environmentVariables) data = lodash.toPairs(environmentVariables).map((value)=>value.join('=')).join('\n');
113
+ case ".env":
114
+ if (environmentVariables) data = lodash.toPairs(environmentVariables).map((value)=>value.join("=")).join("\n");
115
115
  break;
116
116
  default:
117
117
  {
118
118
  const omitPaths = [
119
- '.gitignore',
120
- 'pnpm-lock.yaml'
119
+ ".gitignore",
120
+ "pnpm-lock.yaml"
121
121
  ];
122
122
  if (!omitPaths.includes(path)) {
123
- if ('data' in file) data = file.data;
123
+ if ("data" in file) data = file.data;
124
124
  }
125
125
  break;
126
126
  }
@@ -139,10 +139,10 @@ const zipAppData = async (params)=>{
139
139
  const { path } = file;
140
140
  let data;
141
141
  switch(path){
142
- case 'index.ts':
142
+ case "index.ts":
143
143
  data = code;
144
144
  break;
145
- case 'package.json':
145
+ case "package.json":
146
146
  {
147
147
  const { packageJson } = getHandlerPackageJson({
148
148
  packageJson: file.data,
@@ -154,7 +154,7 @@ const zipAppData = async (params)=>{
154
154
  break;
155
155
  }
156
156
  default:
157
- if ('data' in file) data = file.data;
157
+ if ("data" in file) data = file.data;
158
158
  break;
159
159
  }
160
160
  if (data) addFileToZipFolder({
@@ -194,7 +194,7 @@ const extendAppDataWithPath = async (params)=>{
194
194
  return res;
195
195
  };
196
196
  const readSourceData = async (uri)=>{
197
- if (lodash.startsWith(uri, 'http')) {
197
+ if (lodash.startsWith(uri, "http")) {
198
198
  const axiosRes = await axios({
199
199
  url: uri
200
200
  });
@@ -207,7 +207,7 @@ const loadAppResourceRecords = async (params)=>{
207
207
  const { appDataUri, apaasAppDataUri, apaasAppDataExpression } = params;
208
208
  if (apaasAppDataUri) {
209
209
  const rawData = await readSourceData(apaasAppDataUri);
210
- const expression = apaasAppDataExpression || '$';
210
+ const expression = apaasAppDataExpression || "$";
211
211
  const exp = jsonata(expression);
212
212
  const appData = await exp.evaluate(rawData);
213
213
  const { resourceRecords } = appData;
@@ -219,14 +219,14 @@ const loadAppResourceRecords = async (params)=>{
219
219
  }));
220
220
  return {
221
221
  resourceRecords: apaasRecords,
222
- sourceType: 'apaas'
222
+ sourceType: "apaas"
223
223
  };
224
224
  }
225
- if (!appDataUri) throw new Error('Missing appDataUri or apaasAppDataUri');
225
+ if (!appDataUri) throw new Error("Missing appDataUri or apaasAppDataUri");
226
226
  const appData = await readSourceData(appDataUri);
227
227
  return {
228
228
  resourceRecords: appData.resourceRecords,
229
- sourceType: 'runtime'
229
+ sourceType: "runtime"
230
230
  };
231
231
  };
232
232
  const fetchAppData = async (params)=>{
@@ -241,7 +241,7 @@ const generateByAppData = async (params)=>{
241
241
  const { appData, outputPath } = params;
242
242
  const zipAppDataRes = await zipAppData({
243
243
  ...appData,
244
- type: 'nodebuffer'
244
+ type: "nodebuffer"
245
245
  });
246
246
  const { archive } = zipAppDataRes;
247
247
  const admZip = new adm_zip(archive);
@@ -295,21 +295,21 @@ const getTreeResourceRecords = (params)=>{
295
295
  const prepare = async (params)=>{
296
296
  const { outputPath } = params;
297
297
  const { archive } = await zipAppData({
298
- ...lodash.omit(params, 'outputPath'),
299
- type: 'nodebuffer'
298
+ ...lodash.omit(params, "outputPath"),
299
+ type: "nodebuffer"
300
300
  });
301
301
  const admZip = new adm_zip(archive);
302
302
  admZip.extractAllTo(outputPath, true);
303
303
  };
304
304
  const replaceResourceIdsInString = (params)=>{
305
305
  const { jsonString, oldResourceIdToNewResourceIdMap } = params;
306
- const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
307
- if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
306
+ const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || "(empty)");
307
+ if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(", ")}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
308
308
  let result = jsonString;
309
309
  const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
310
310
  for (const [oldResourceId, newResourceId] of entries){
311
- const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
312
- const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
311
+ const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
312
+ const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, "g");
313
313
  result = result.replace(regex, newResourceId);
314
314
  }
315
315
  const res = {
package/dist/prepare.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppDataWithAppModuleHandlerDependencyVersionTemplate } from './common';
1
+ import { AppDataWithAppModuleHandlerDependencyVersionTemplate } from "./common";
2
2
  export interface PrepareParams extends AppDataWithAppModuleHandlerDependencyVersionTemplate {
3
3
  outputPath: string;
4
4
  }
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "@ldsg/utils",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "wanxger",
7
+ "files": [
8
+ "dist/"
9
+ ],
7
10
  "type": "module",
11
+ "main": "./dist/index.cjs",
12
+ "browser": {
13
+ ".": "./dist/browser.js"
14
+ },
15
+ "types": "./dist/index.d.ts",
8
16
  "exports": {
9
17
  ".": {
10
18
  "types": "./dist/index.d.ts",
@@ -18,26 +26,21 @@
18
26
  "require": "./dist/browser.cjs"
19
27
  }
20
28
  },
21
- "main": "./dist/index.cjs",
22
- "browser": {
23
- ".": "./dist/browser.js"
29
+ "publishConfig": {
30
+ "access": "public"
24
31
  },
25
- "types": "./dist/index.d.ts",
26
- "files": [
27
- "dist/"
28
- ],
29
32
  "dependencies": {
30
33
  "adm-zip": "^0.5.16",
31
34
  "axios": "^1.7.7",
32
35
  "fs-extra": "^11.2.0",
33
- "jsonata": "^2.0.6",
36
+ "jsonata": "2.2.2",
34
37
  "jszip": "^3.10.1",
35
38
  "lodash": "^4.17.21",
36
- "@ldsg/apaas-constants": "0.3.31",
37
- "@ldsg/constants": "0.3.31",
38
- "@ldsg/core": "0.3.31",
39
- "@ldsg/handler": "0.3.31",
40
- "@ldsg/types": "0.3.31"
39
+ "@ldsg/constants": "0.3.33",
40
+ "@ldsg/apaas-constants": "0.3.33",
41
+ "@ldsg/types": "0.3.33",
42
+ "@ldsg/core": "0.3.33",
43
+ "@ldsg/handler": "0.3.33"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@rslib/core": "^0.17.1",
@@ -45,14 +48,15 @@
45
48
  "@types/fs-extra": "^11.0.4",
46
49
  "@types/lodash": "^4.14.202",
47
50
  "@types/node": "^20.13.0",
51
+ "oxfmt": "latest",
52
+ "oxlint": "latest",
48
53
  "typescript": "^5.3.3"
49
54
  },
50
- "publishConfig": {
51
- "access": "public"
52
- },
53
55
  "scripts": {
54
56
  "build": "rslib build",
55
57
  "clean": "rm -rf dist",
56
- "dev": "rslib build --watch"
58
+ "dev": "rslib build --watch",
59
+ "format": "oxfmt --write src/",
60
+ "lint": "oxlint src/"
57
61
  }
58
62
  }