@ldsg/utils 0.3.24 → 0.3.26
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/LICENSE +1 -1
- package/dist/browser.cjs +88 -0
- package/dist/browser.d.ts +5 -0
- package/dist/browser.js +51 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/types/handler-service-settings.d.ts +14 -0
- package/dist/common/types/index.d.ts +2 -0
- package/dist/common/types/service-record.d.ts +11 -0
- package/dist/common/utils/index.d.ts +3 -0
- package/dist/common/utils/instantiate-service.d.ts +12 -0
- package/dist/common/utils/instantiate-services.d.ts +13 -0
- package/dist/common/utils/zip-app-data/constants.d.ts +15 -0
- package/dist/common/utils/zip-app-data/index.d.ts +18 -0
- package/dist/common/utils/zip-app-data/utils/add-file-to-zip-folder.d.ts +9 -0
- package/dist/common/utils/zip-app-data/utils/get-handler-package-json.d.ts +20 -0
- package/dist/common/utils/zip-app-data/utils/index.d.ts +2 -0
- package/dist/extend-app-data-with-path.d.ts +0 -1
- package/dist/extend-app-data.d.ts +0 -1
- package/dist/fetch-app-data.d.ts +13 -4
- package/dist/generate-by-app-data.d.ts +0 -1
- package/dist/generate.d.ts +0 -1
- package/dist/get-app-data.d.ts +0 -1
- package/dist/get-tree-resource-records.d.ts +14 -0
- package/dist/index.cjs +440 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +337 -22
- package/dist/prepare.d.ts +6 -0
- package/dist/replace-resource-ids/index.d.ts +8 -0
- package/dist/replace-resource-ids/utils/replace-resource-ids-in-string.d.ts +10 -0
- package/package.json +32 -19
- package/dist/extend-app-data-with-path.d.ts.map +0 -1
- package/dist/extend-app-data-with-path.js +0 -24
- package/dist/extend-app-data.d.ts.map +0 -1
- package/dist/extend-app-data.js +0 -12
- package/dist/fetch-app-data.d.ts.map +0 -1
- package/dist/fetch-app-data.js +0 -16
- package/dist/generate-by-app-data.d.ts.map +0 -1
- package/dist/generate-by-app-data.js +0 -19
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js +0 -11
- package/dist/get-app-data.d.ts.map +0 -1
- package/dist/get-app-data.js +0 -15
- package/dist/index.d.ts.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2014-present
|
|
3
|
+
Copyright (c) 2014-present Wanxger and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
getTreeResourceRecords: ()=>getTreeResourceRecords,
|
|
28
|
+
replaceResourceIds: ()=>replaceResourceIds
|
|
29
|
+
});
|
|
30
|
+
const getTreeResourceRecords = (params)=>{
|
|
31
|
+
const { resourceRecords, rootId } = params;
|
|
32
|
+
const childrenMap = new Map();
|
|
33
|
+
for (const r of resourceRecords){
|
|
34
|
+
if (!r.parentId) continue;
|
|
35
|
+
const children = childrenMap.get(r.parentId);
|
|
36
|
+
if (children) children.push(r.id);
|
|
37
|
+
else childrenMap.set(r.parentId, [
|
|
38
|
+
r.id
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
const ids = new Set();
|
|
42
|
+
const stack = [
|
|
43
|
+
rootId
|
|
44
|
+
];
|
|
45
|
+
while(stack.length > 0){
|
|
46
|
+
const id = stack.pop();
|
|
47
|
+
if (ids.has(id)) continue;
|
|
48
|
+
ids.add(id);
|
|
49
|
+
const children = childrenMap.get(id);
|
|
50
|
+
if (children) stack.push(...children);
|
|
51
|
+
}
|
|
52
|
+
const treeResourceRecords = resourceRecords.filter((r)=>ids.has(r.id));
|
|
53
|
+
const res = {
|
|
54
|
+
treeResourceRecords
|
|
55
|
+
};
|
|
56
|
+
return res;
|
|
57
|
+
};
|
|
58
|
+
const replaceResourceIdsInString = (params)=>{
|
|
59
|
+
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
60
|
+
let result = jsonString;
|
|
61
|
+
for (const [oldResourceId, newResourceId] of Object.entries(oldResourceIdToNewResourceIdMap))result = result.split(oldResourceId).join(newResourceId);
|
|
62
|
+
const res = {
|
|
63
|
+
jsonString: result
|
|
64
|
+
};
|
|
65
|
+
return res;
|
|
66
|
+
};
|
|
67
|
+
const replaceResourceIds = (params)=>{
|
|
68
|
+
const { source, oldResourceIdToNewResourceIdMap } = params;
|
|
69
|
+
const jsonString = JSON.stringify(source);
|
|
70
|
+
const { jsonString: replacedJsonString } = replaceResourceIdsInString({
|
|
71
|
+
jsonString,
|
|
72
|
+
oldResourceIdToNewResourceIdMap
|
|
73
|
+
});
|
|
74
|
+
const replacement = JSON.parse(replacedJsonString);
|
|
75
|
+
const res = {
|
|
76
|
+
replacement
|
|
77
|
+
};
|
|
78
|
+
return res;
|
|
79
|
+
};
|
|
80
|
+
exports.getTreeResourceRecords = __webpack_exports__.getTreeResourceRecords;
|
|
81
|
+
exports.replaceResourceIds = __webpack_exports__.replaceResourceIds;
|
|
82
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
83
|
+
"getTreeResourceRecords",
|
|
84
|
+
"replaceResourceIds"
|
|
85
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
86
|
+
Object.defineProperty(exports, '__esModule', {
|
|
87
|
+
value: true
|
|
88
|
+
});
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const getTreeResourceRecords = (params)=>{
|
|
2
|
+
const { resourceRecords, rootId } = params;
|
|
3
|
+
const childrenMap = new Map();
|
|
4
|
+
for (const r of resourceRecords){
|
|
5
|
+
if (!r.parentId) continue;
|
|
6
|
+
const children = childrenMap.get(r.parentId);
|
|
7
|
+
if (children) children.push(r.id);
|
|
8
|
+
else childrenMap.set(r.parentId, [
|
|
9
|
+
r.id
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
const ids = new Set();
|
|
13
|
+
const stack = [
|
|
14
|
+
rootId
|
|
15
|
+
];
|
|
16
|
+
while(stack.length > 0){
|
|
17
|
+
const id = stack.pop();
|
|
18
|
+
if (ids.has(id)) continue;
|
|
19
|
+
ids.add(id);
|
|
20
|
+
const children = childrenMap.get(id);
|
|
21
|
+
if (children) stack.push(...children);
|
|
22
|
+
}
|
|
23
|
+
const treeResourceRecords = resourceRecords.filter((r)=>ids.has(r.id));
|
|
24
|
+
const res = {
|
|
25
|
+
treeResourceRecords
|
|
26
|
+
};
|
|
27
|
+
return res;
|
|
28
|
+
};
|
|
29
|
+
const replaceResourceIdsInString = (params)=>{
|
|
30
|
+
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
31
|
+
let result = jsonString;
|
|
32
|
+
for (const [oldResourceId, newResourceId] of Object.entries(oldResourceIdToNewResourceIdMap))result = result.split(oldResourceId).join(newResourceId);
|
|
33
|
+
const res = {
|
|
34
|
+
jsonString: result
|
|
35
|
+
};
|
|
36
|
+
return res;
|
|
37
|
+
};
|
|
38
|
+
const replaceResourceIds = (params)=>{
|
|
39
|
+
const { source, oldResourceIdToNewResourceIdMap } = params;
|
|
40
|
+
const jsonString = JSON.stringify(source);
|
|
41
|
+
const { jsonString: replacedJsonString } = replaceResourceIdsInString({
|
|
42
|
+
jsonString,
|
|
43
|
+
oldResourceIdToNewResourceIdMap
|
|
44
|
+
});
|
|
45
|
+
const replacement = JSON.parse(replacedJsonString);
|
|
46
|
+
const res = {
|
|
47
|
+
replacement
|
|
48
|
+
};
|
|
49
|
+
return res;
|
|
50
|
+
};
|
|
51
|
+
export { getTreeResourceRecords, replaceResourceIds };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface HandlerServiceSettings {
|
|
2
|
+
moduleId: string;
|
|
3
|
+
moduleData: HandlerServiceModuleData;
|
|
4
|
+
}
|
|
5
|
+
export interface HandlerServiceModuleData {
|
|
6
|
+
code: string;
|
|
7
|
+
modules: HandlerServiceModuleDataModule[];
|
|
8
|
+
}
|
|
9
|
+
export interface HandlerServiceModuleDataModule {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
path: string;
|
|
13
|
+
requireName?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Service, Settings } from '@ldsg/core';
|
|
2
|
+
export interface ServiceRecord {
|
|
3
|
+
id: string;
|
|
4
|
+
parentId?: string;
|
|
5
|
+
type: string;
|
|
6
|
+
settings?: Settings;
|
|
7
|
+
}
|
|
8
|
+
export type ServiceRecords = ServiceRecord[];
|
|
9
|
+
export type ServiceTypeMap = Record<string, {
|
|
10
|
+
class: typeof Service;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Service, ServiceProperties } from '@ldsg/core';
|
|
2
|
+
import { ServiceRecords, ServiceTypeMap } from '../types';
|
|
3
|
+
export interface InstantiateServiceParams {
|
|
4
|
+
serviceProperties: ServiceProperties;
|
|
5
|
+
serviceRecords?: ServiceRecords;
|
|
6
|
+
serviceTypeMap?: ServiceTypeMap;
|
|
7
|
+
}
|
|
8
|
+
export interface InstantiateServiceRes {
|
|
9
|
+
service: Service;
|
|
10
|
+
}
|
|
11
|
+
export type InstantiateService = (params: InstantiateServiceParams) => InstantiateServiceRes;
|
|
12
|
+
export declare const instantiateService: InstantiateService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Service } from '@ldsg/core';
|
|
2
|
+
import { ServiceRecords, ServiceTypeMap } from '../types';
|
|
3
|
+
import { InstantiateService } from './instantiate-service';
|
|
4
|
+
export interface InstantiateServicesParams {
|
|
5
|
+
serviceRecords: ServiceRecords;
|
|
6
|
+
instantiateService?: InstantiateService;
|
|
7
|
+
serviceTypeMap?: ServiceTypeMap;
|
|
8
|
+
}
|
|
9
|
+
export interface InstantiateServicesRes {
|
|
10
|
+
services: Service[];
|
|
11
|
+
}
|
|
12
|
+
export type InstantiateServices = (params: InstantiateServicesParams) => InstantiateServicesRes;
|
|
13
|
+
export declare const instantiateServices: InstantiateServices;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const DEFAULT_APP_MODULE_DIR_NAME = "app";
|
|
2
|
+
export declare const DEFAULT_APP_MODULE_HANDLER_DEPENDENCY_VERSION_TEMPLATE = "workspace:*";
|
|
3
|
+
export declare const DEFAULT_HANDLER_MODULE_PARENT_DIR_NAME = "handlers";
|
|
4
|
+
export declare enum ZipAppDataLayout {
|
|
5
|
+
/**
|
|
6
|
+
* 平铺
|
|
7
|
+
* 应用模块与处理程序模块在同一文件夹中
|
|
8
|
+
*/
|
|
9
|
+
FLAT = "flat",
|
|
10
|
+
/**
|
|
11
|
+
* 嵌套
|
|
12
|
+
* 处理程序模块在应用模块下的子文件夹中
|
|
13
|
+
*/
|
|
14
|
+
NESTED = "nested"
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export interface AppDataWithAppModuleHandlerDependencyVersionTemplate extends AppData {
|
|
7
|
+
appModuleHandlerDependencyVersionTemplate?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ZipAppDataParams<T extends JSZip.OutputType> extends JSZip.JSZipGeneratorOptions<T>, AppDataWithAppModuleHandlerDependencyVersionTemplate {
|
|
10
|
+
layout?: ZipAppDataLayout;
|
|
11
|
+
}
|
|
12
|
+
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
13
|
+
type OutputByType<T extends JSZip.OutputType> = UnwrapPromise<ReturnType<typeof JSZip.generateAsync<T>>>;
|
|
14
|
+
interface ZipAppDataRes<T extends JSZip.OutputType> {
|
|
15
|
+
archive: OutputByType<T>;
|
|
16
|
+
}
|
|
17
|
+
type ZipAppData = <T extends JSZip.OutputType>(params: ZipAppDataParams<T>) => Promise<ZipAppDataRes<T>>;
|
|
18
|
+
export declare const zipAppData: ZipAppData;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AppDataFile, FileData } from '@ldsg/types';
|
|
2
|
+
import JSZip from 'jszip';
|
|
3
|
+
interface AddFileToZipFolderParams extends AppDataFile {
|
|
4
|
+
folder: JSZip;
|
|
5
|
+
data: FileData;
|
|
6
|
+
}
|
|
7
|
+
type AddFileToZipFolder = (params: AddFileToZipFolderParams) => void;
|
|
8
|
+
export declare const addFileToZipFolder: AddFileToZipFolder;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HandlerResourceDependency } from '@ldsg/handler';
|
|
2
|
+
interface GetHandlerPackageJsonParams {
|
|
3
|
+
packageJson: PackageJson;
|
|
4
|
+
moduleName: string;
|
|
5
|
+
dependencies: HandlerResourceDependency[];
|
|
6
|
+
reuseMainAppDependencies: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface PackageJson {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
main: string;
|
|
12
|
+
scripts: Record<string, string>;
|
|
13
|
+
dependencies: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface GetHandlerPackageJsonRes {
|
|
16
|
+
packageJson: PackageJson;
|
|
17
|
+
}
|
|
18
|
+
type GetHandlerPackageJson = (params: GetHandlerPackageJsonParams) => GetHandlerPackageJsonRes;
|
|
19
|
+
export declare const getHandlerPackageJson: GetHandlerPackageJson;
|
|
20
|
+
export {};
|
|
@@ -6,4 +6,3 @@ export interface ExtendAppDataWithPathParams {
|
|
|
6
6
|
type ExtendAppDataWithPath = (params: ExtendAppDataWithPathParams) => Promise<AppData>;
|
|
7
7
|
export declare const extendAppDataWithPath: ExtendAppDataWithPath;
|
|
8
8
|
export {};
|
|
9
|
-
//# sourceMappingURL=extend-app-data-with-path.d.ts.map
|
package/dist/fetch-app-data.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { AppData } from '@ldsg/types';
|
|
1
|
+
import { AppData, ResourceRecords } from '@ldsg/types';
|
|
2
|
+
export interface LoadAppResourceRecordsParams {
|
|
3
|
+
appDataUri?: string;
|
|
4
|
+
apaasAppDataUri?: string;
|
|
5
|
+
apaasAppDataExpression?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LoadAppResourceRecordsRes {
|
|
8
|
+
resourceRecords: ResourceRecords;
|
|
9
|
+
sourceType: 'apaas' | 'runtime';
|
|
10
|
+
}
|
|
11
|
+
export declare const loadAppResourceRecords: (params: LoadAppResourceRecordsParams) => Promise<LoadAppResourceRecordsRes>;
|
|
2
12
|
export interface FetchAppDataParams {
|
|
3
13
|
lgsgAppDataUrl: string;
|
|
4
14
|
}
|
|
5
|
-
type
|
|
6
|
-
export declare const fetchAppData:
|
|
15
|
+
type FetchAppDataFn = (params: FetchAppDataParams) => Promise<AppData>;
|
|
16
|
+
export declare const fetchAppData: FetchAppDataFn;
|
|
7
17
|
export {};
|
|
8
|
-
//# sourceMappingURL=fetch-app-data.d.ts.map
|
package/dist/generate.d.ts
CHANGED
package/dist/get-app-data.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ResourceRecords } from '@ldsg/types';
|
|
2
|
+
interface GetTreeResourceRecordsParams {
|
|
3
|
+
resourceRecords: ResourceRecords;
|
|
4
|
+
rootId: string;
|
|
5
|
+
}
|
|
6
|
+
interface GetTreeResourceRecordsRes {
|
|
7
|
+
treeResourceRecords: ResourceRecords;
|
|
8
|
+
}
|
|
9
|
+
type GetTreeResourceRecords = (params: GetTreeResourceRecordsParams) => GetTreeResourceRecordsRes;
|
|
10
|
+
/**
|
|
11
|
+
* 获取树形资源记录
|
|
12
|
+
*/
|
|
13
|
+
export declare const getTreeResourceRecords: GetTreeResourceRecords;
|
|
14
|
+
export {};
|