@hamak/shared-utils 0.4.1
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/core-utils-chrono.d.ts +8 -0
- package/dist/core-utils-chrono.d.ts.map +1 -0
- package/dist/core-utils-chrono.js +16 -0
- package/dist/core-utils-comparator.d.ts +11 -0
- package/dist/core-utils-comparator.d.ts.map +1 -0
- package/dist/core-utils-comparator.js +22 -0
- package/dist/core-utils-file.d.ts +10 -0
- package/dist/core-utils-file.d.ts.map +1 -0
- package/dist/core-utils-file.js +1 -0
- package/dist/core-utils-filesystem.d.ts +69 -0
- package/dist/core-utils-filesystem.d.ts.map +1 -0
- package/dist/core-utils-filesystem.js +156 -0
- package/dist/core-utils-fqn.d.ts +11 -0
- package/dist/core-utils-fqn.d.ts.map +1 -0
- package/dist/core-utils-fqn.js +19 -0
- package/dist/core-utils-pathway-resolver.d.ts +20 -0
- package/dist/core-utils-pathway-resolver.d.ts.map +1 -0
- package/dist/core-utils-pathway-resolver.js +31 -0
- package/dist/core-utils-pathway.d.ts +84 -0
- package/dist/core-utils-pathway.d.ts.map +1 -0
- package/dist/core-utils-pathway.js +206 -0
- package/dist/core-utils-registry.d.ts +7 -0
- package/dist/core-utils-registry.d.ts.map +1 -0
- package/dist/core-utils-registry.js +22 -0
- package/dist/core-utils-resolver.d.ts +33 -0
- package/dist/core-utils-resolver.d.ts.map +1 -0
- package/dist/core-utils-resolver.js +65 -0
- package/dist/core-utils-stack.d.ts +20 -0
- package/dist/core-utils-stack.d.ts.map +1 -0
- package/dist/core-utils-stack.js +47 -0
- package/dist/core-utils-types-hkt.d.ts +12 -0
- package/dist/core-utils-types-hkt.d.ts.map +1 -0
- package/dist/core-utils-types-hkt.js +1 -0
- package/dist/core-utils-types.d.ts +83 -0
- package/dist/core-utils-types.d.ts.map +1 -0
- package/dist/core-utils-types.js +39 -0
- package/dist/core-utils-validations.d.ts +21 -0
- package/dist/core-utils-validations.d.ts.map +1 -0
- package/dist/core-utils-validations.js +18 -0
- package/dist/core-utils.d.ts +39 -0
- package/dist/core-utils.d.ts.map +1 -0
- package/dist/core-utils.js +113 -0
- package/dist/es2015/core-utils-chrono.js +16 -0
- package/dist/es2015/core-utils-comparator.js +22 -0
- package/dist/es2015/core-utils-file.js +1 -0
- package/dist/es2015/core-utils-filesystem.js +157 -0
- package/dist/es2015/core-utils-fqn.js +19 -0
- package/dist/es2015/core-utils-pathway-resolver.js +31 -0
- package/dist/es2015/core-utils-pathway.js +206 -0
- package/dist/es2015/core-utils-registry.js +22 -0
- package/dist/es2015/core-utils-resolver.js +68 -0
- package/dist/es2015/core-utils-stack.js +47 -0
- package/dist/es2015/core-utils-types-hkt.js +1 -0
- package/dist/es2015/core-utils-types.js +39 -0
- package/dist/es2015/core-utils-validations.js +18 -0
- package/dist/es2015/core-utils.js +113 -0
- package/dist/es2015/index.js +24 -0
- package/dist/es2015/itinerary/hyper-layer-node.js +21 -0
- package/dist/es2015/itinerary/itinerary.js +276 -0
- package/dist/es2015/itinerary/stack.js +47 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/itinerary/hyper-layer-node.d.ts +12 -0
- package/dist/itinerary/hyper-layer-node.d.ts.map +1 -0
- package/dist/itinerary/hyper-layer-node.js +21 -0
- package/dist/itinerary/itinerary.d.ts +86 -0
- package/dist/itinerary/itinerary.d.ts.map +1 -0
- package/dist/itinerary/itinerary.js +275 -0
- package/dist/itinerary/stack.d.ts +20 -0
- package/dist/itinerary/stack.d.ts.map +1 -0
- package/dist/itinerary/stack.js +47 -0
- package/package.json +41 -0
- package/src/core-utils-chrono.ts +21 -0
- package/src/core-utils-comparator.ts +27 -0
- package/src/core-utils-file.ts +10 -0
- package/src/core-utils-filesystem.spec.ts +63 -0
- package/src/core-utils-filesystem.ts +232 -0
- package/src/core-utils-fqn.ts +17 -0
- package/src/core-utils-pathway-resolver.ts +36 -0
- package/src/core-utils-pathway.ts +232 -0
- package/src/core-utils-registry.ts +23 -0
- package/src/core-utils-resolver.ts +75 -0
- package/src/core-utils-stack.spec.ts +42 -0
- package/src/core-utils-stack.ts +62 -0
- package/src/core-utils-types-hkt.ts +9 -0
- package/src/core-utils-types.ts +127 -0
- package/src/core-utils-validations.ts +36 -0
- package/src/core-utils.spec.ts +56 -0
- package/src/core-utils.ts +139 -0
- package/src/index.ts +34 -0
- package/src/itinerary/hyper-layer-node.ts +25 -0
- package/src/itinerary/itinerary.spec.ts +388 -0
- package/src/itinerary/itinerary.ts +363 -0
- package/src/itinerary/stack.spec.ts +46 -0
- package/src/itinerary/stack.ts +62 -0
- package/tsconfig.es2015.json +24 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-chrono.d.ts","sourceRoot":"","sources":["../src/core-utils-chrono.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAS;;IAKtB,QAAQ,IAAK,MAAM;IAInB,OAAO,IAAK,MAAM;CAMnB;AAED,wBAAgB,WAAW,gBAE1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class Chronometre {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.start = Date.now();
|
|
4
|
+
}
|
|
5
|
+
duration() {
|
|
6
|
+
return Date.now() - this.start;
|
|
7
|
+
}
|
|
8
|
+
restart() {
|
|
9
|
+
const d = this.duration();
|
|
10
|
+
this.start = Date.now();
|
|
11
|
+
return d;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function chronometre() {
|
|
15
|
+
return new Chronometre();
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Order = -1 | 0 | 1;
|
|
2
|
+
export type Weighted<T, W> = {
|
|
3
|
+
value: T;
|
|
4
|
+
weight: W;
|
|
5
|
+
};
|
|
6
|
+
export type WeightFn<T> = (t: T) => number;
|
|
7
|
+
export type CompareFn<T> = (a: T, b: T, ...fns: [WeightFn<T>, ...WeightFn<T>[]]) => Order;
|
|
8
|
+
export declare function reverseOrder<T>(compareFn: CompareFn<T>): CompareFn<T>;
|
|
9
|
+
export declare function compare<T>(a: T, b: T, ...fns: WeightFn<T>[]): Order;
|
|
10
|
+
export declare const compareDesc: <T>(a: T, b: T, fns_0: WeightFn<T>, ...fns_1: WeightFn<T>[]) => Order;
|
|
11
|
+
//# sourceMappingURL=core-utils-comparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-comparator.d.ts","sourceRoot":"","sources":["../src/core-utils-comparator.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC9B,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI;IAAC,KAAK,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAC,CAAA;AAClD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAG,CAAC,KAAK,MAAM,CAAA;AAC3C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAG,CAAC,EAAE,CAAC,EAAG,CAAC,EAAE,GAAG,GAAG,EAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,KAAK,CAAA;AAC5F,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAG,SAAS,CAAC,CAAC,CAAC,GAAI,SAAS,CAAC,CAAC,CAAC,CAEvE;AACD,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAG,CAAC,EAAE,CAAC,EAAG,CAAC,EAAE,GAAG,GAAG,EAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAI,KAAK,CAiBvE;AAED,eAAO,MAAM,WAAW,kEAvB+D,KAuBvC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function reverseOrder(compareFn) {
|
|
2
|
+
return (a, b, fns) => -compareFn(a, b, fns);
|
|
3
|
+
}
|
|
4
|
+
export function compare(a, b, ...fns) {
|
|
5
|
+
if (fns.length === 0) {
|
|
6
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
7
|
+
fns = [(x) => x];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
throw new Error(`Expecting at least one weight function when arguments are not numbers`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
for (const weightFn of fns) {
|
|
14
|
+
const aWeight = weightFn(a);
|
|
15
|
+
const bWeight = weightFn(b);
|
|
16
|
+
if (aWeight != bWeight) {
|
|
17
|
+
return a < b ? -1 : 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
export const compareDesc = reverseOrder(compare);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-file.d.ts","sourceRoot":"","sources":["../src/core-utils-file.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Path, Pathway } from './core-utils-pathway';
|
|
2
|
+
import { Holder } from './core-utils-types';
|
|
3
|
+
import { PathwayResolver } from './core-utils-pathway-resolver';
|
|
4
|
+
export type FileContentSchema = string | {
|
|
5
|
+
schemaObject: string;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
};
|
|
8
|
+
export interface FileSystemState {
|
|
9
|
+
root: DirectoryNode;
|
|
10
|
+
}
|
|
11
|
+
export interface FileMemoState {
|
|
12
|
+
originalContent: Holder;
|
|
13
|
+
modified: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface FileSystemNodeState {
|
|
16
|
+
contentLoaded: boolean;
|
|
17
|
+
contentLoading: boolean;
|
|
18
|
+
contentLoadError?: {
|
|
19
|
+
code?: string;
|
|
20
|
+
message?: string;
|
|
21
|
+
};
|
|
22
|
+
memo?: FileMemoState;
|
|
23
|
+
contentHistory: any[];
|
|
24
|
+
extensionStates: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export declare function fileSystemNodeInitialState(contentPresent?: boolean): FileSystemNodeState;
|
|
27
|
+
export interface FileSystemNodeBase {
|
|
28
|
+
type: 'directory' | 'file';
|
|
29
|
+
name: string;
|
|
30
|
+
state: FileSystemNodeState;
|
|
31
|
+
}
|
|
32
|
+
export interface DirectoryNode extends FileSystemNodeBase {
|
|
33
|
+
type: 'directory';
|
|
34
|
+
children: Record<string, FileSystemNode>;
|
|
35
|
+
}
|
|
36
|
+
export interface FileNode<T = any> extends FileSystemNodeBase {
|
|
37
|
+
type: 'file';
|
|
38
|
+
content: T;
|
|
39
|
+
schema: string | FileContentSchema;
|
|
40
|
+
}
|
|
41
|
+
export type FileSystemNode = DirectoryNode | FileNode;
|
|
42
|
+
export declare class DirectoryNodePathwayResolver implements PathwayResolver<FileSystemNode> {
|
|
43
|
+
readonly root: FileSystemNode;
|
|
44
|
+
constructor(root: FileSystemNode);
|
|
45
|
+
resolve(path: string | Pathway | string[]): FileSystemNode | undefined;
|
|
46
|
+
changeDIr(path: Path): DirectoryNodePathwayResolver;
|
|
47
|
+
}
|
|
48
|
+
declare class FilesystemUtil {
|
|
49
|
+
createRootDir(children: FileSystemNode[], state?: FileSystemNodeState): DirectoryNode;
|
|
50
|
+
createDir(name: string, children: FileSystemNode[], state?: FileSystemNodeState): DirectoryNode;
|
|
51
|
+
createDirs(path: Path, children: FileSystemNode[], state?: FileSystemNodeState): DirectoryNode;
|
|
52
|
+
createFile(name: string, content: any, schema?: string, state?: FileSystemNodeState): FileNode;
|
|
53
|
+
resolveFileNode(fromDir: FileSystemNode | undefined, path: Path): FileSystemNode | undefined;
|
|
54
|
+
asFile<T = any>(fsn: FileSystemNode | undefined): FileNode<T> | undefined;
|
|
55
|
+
asDirectory(fsn: FileSystemNode | undefined): DirectoryNode | undefined;
|
|
56
|
+
resolveDescendent(fromDir: FileSystemNode | undefined, path: Path): FileSystemNode | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Set a file node content a specified location. It create intermediary directories and target if missed location.
|
|
59
|
+
* @param fromDir
|
|
60
|
+
* @param path
|
|
61
|
+
* @param content
|
|
62
|
+
* @param schema
|
|
63
|
+
* @param state
|
|
64
|
+
*/
|
|
65
|
+
createDescendent(fromDir: FileSystemNode | undefined, path: Path, content: any, schema?: string, state?: FileSystemNodeState, override?: boolean): FileNode | undefined;
|
|
66
|
+
}
|
|
67
|
+
export declare const fsutils: FilesystemUtil;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=core-utils-filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-filesystem.d.ts","sourceRoot":"","sources":["../src/core-utils-filesystem.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Pathway } from './core-utils-pathway';
|
|
2
|
+
export function fileSystemNodeInitialState(contentPresent = true) {
|
|
3
|
+
return {
|
|
4
|
+
contentLoaded: contentPresent,
|
|
5
|
+
contentLoading: false,
|
|
6
|
+
contentLoadError: undefined,
|
|
7
|
+
contentHistory: [],
|
|
8
|
+
extensionStates: {}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function isRoot(node) {
|
|
12
|
+
switch (node.type) {
|
|
13
|
+
case "directory": {
|
|
14
|
+
return node.name === null || node.name === undefined || node.name.trim() === "" || node.name.trim() === "/";
|
|
15
|
+
}
|
|
16
|
+
case "file": {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class DirectoryNodePathwayResolver {
|
|
22
|
+
constructor(root) {
|
|
23
|
+
this.root = root;
|
|
24
|
+
}
|
|
25
|
+
resolve(path) {
|
|
26
|
+
return fsutils.resolveFileNode(this.root, path);
|
|
27
|
+
}
|
|
28
|
+
changeDIr(path) {
|
|
29
|
+
const fileNode = this.resolve(path);
|
|
30
|
+
if (fileNode === undefined) {
|
|
31
|
+
throw new Error(`No such directory: ${Pathway.asString(path)}`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
switch (fileNode.type) {
|
|
35
|
+
case "directory": return new DirectoryNodePathwayResolver(fileNode);
|
|
36
|
+
case "file": throw new Error(`Path is not directory: ${Pathway.asString(path)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class FilesystemUtil {
|
|
42
|
+
createRootDir(children, state = fileSystemNodeInitialState()) {
|
|
43
|
+
return this.createDir("", children, state);
|
|
44
|
+
}
|
|
45
|
+
createDir(name, children, state = fileSystemNodeInitialState()) {
|
|
46
|
+
return {
|
|
47
|
+
type: "directory", name, state,
|
|
48
|
+
children: children.reduce((acc, child) => ({ ...acc, [child.name]: child }), {})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
createDirs(path, children, state = fileSystemNodeInitialState()) {
|
|
52
|
+
const pathway = Pathway.of(path);
|
|
53
|
+
const dir = pathway.getSegments().reverse().reduce((acc, segment) => {
|
|
54
|
+
return this.createDir(segment, acc === undefined ? children : [acc]);
|
|
55
|
+
}, undefined);
|
|
56
|
+
if (dir === undefined) {
|
|
57
|
+
throw new Error(`Unable de create dir '${path}'`);
|
|
58
|
+
}
|
|
59
|
+
return pathway.isAbsolute() ? this.createRootDir([dir]) : dir;
|
|
60
|
+
}
|
|
61
|
+
createFile(name, content, schema = "xs:any", state = fileSystemNodeInitialState()) {
|
|
62
|
+
return { type: "file", name, content, schema, state };
|
|
63
|
+
}
|
|
64
|
+
resolveFileNode(fromDir, path) {
|
|
65
|
+
if (fromDir === undefined) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const pathway = Pathway.of(path);
|
|
69
|
+
if (pathway.isAbsolute() && !isRoot(fromDir)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const result = pathway.getSegments().reduce((acc, segment) => {
|
|
73
|
+
if (acc === undefined) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
switch (acc.type) {
|
|
78
|
+
case "directory":
|
|
79
|
+
{
|
|
80
|
+
return acc.children?.[segment];
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case "file":
|
|
84
|
+
{
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
default: {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, fromDir);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
asFile(fsn) {
|
|
97
|
+
return fsn?.type === "file" ? fsn : undefined;
|
|
98
|
+
}
|
|
99
|
+
asDirectory(fsn) {
|
|
100
|
+
return fsn?.type === "directory" ? fsn : undefined;
|
|
101
|
+
}
|
|
102
|
+
resolveDescendent(fromDir, path) {
|
|
103
|
+
const pathway = Pathway.of(path);
|
|
104
|
+
return pathway.isCurrentDir() ? undefined : this.resolveFileNode(fromDir, pathway);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set a file node content a specified location. It create intermediary directories and target if missed location.
|
|
108
|
+
* @param fromDir
|
|
109
|
+
* @param path
|
|
110
|
+
* @param content
|
|
111
|
+
* @param schema
|
|
112
|
+
* @param state
|
|
113
|
+
*/
|
|
114
|
+
createDescendent(fromDir, path, content, schema = "xs:any", state = fileSystemNodeInitialState(), override = false) {
|
|
115
|
+
if (!fromDir)
|
|
116
|
+
return undefined;
|
|
117
|
+
const pathway = Pathway.of(path);
|
|
118
|
+
if (pathway.isCurrentDir())
|
|
119
|
+
return undefined;
|
|
120
|
+
const segments = pathway.getSegments();
|
|
121
|
+
if (segments.length === 0)
|
|
122
|
+
return undefined;
|
|
123
|
+
if (fromDir.type !== "directory") {
|
|
124
|
+
throw new Error("Cannot create descendent on a non-directory node.");
|
|
125
|
+
}
|
|
126
|
+
let currentDir = fromDir;
|
|
127
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
128
|
+
const segment = segments[i];
|
|
129
|
+
let nextNode = currentDir.children[segment];
|
|
130
|
+
if (!nextNode) {
|
|
131
|
+
// Create intermediate directory
|
|
132
|
+
const newDir = this.createDir(segment, []);
|
|
133
|
+
currentDir.children[segment] = newDir;
|
|
134
|
+
nextNode = newDir;
|
|
135
|
+
}
|
|
136
|
+
if (nextNode.type !== "directory") {
|
|
137
|
+
throw new Error(`Path conflict: '${segment}' is a file, expected a directory.`);
|
|
138
|
+
}
|
|
139
|
+
currentDir = nextNode;
|
|
140
|
+
}
|
|
141
|
+
const fileName = segments[segments.length - 1];
|
|
142
|
+
const existingNode = currentDir.children[fileName];
|
|
143
|
+
if (existingNode) {
|
|
144
|
+
if (existingNode.type !== "file") {
|
|
145
|
+
throw new Error(`Path conflict: '${fileName}' exists and is not a file.`);
|
|
146
|
+
}
|
|
147
|
+
if (!override) {
|
|
148
|
+
throw new Error(`File '${fileName}' already exists and override is disabled.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const fileNode = this.createFile(fileName, content, schema, state);
|
|
152
|
+
currentDir.children[fileName] = fileNode;
|
|
153
|
+
return fileNode;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export const fsutils = new FilesystemUtil();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unresolved qualified name by either namespace of prefix
|
|
3
|
+
*/
|
|
4
|
+
export declare class LexicalQualifiedName {
|
|
5
|
+
readonly namespace: string | undefined;
|
|
6
|
+
readonly prefix: string | undefined;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
constructor(namespace: string | undefined, prefix: string | undefined, name: string);
|
|
9
|
+
isEqualTo(other: LexicalQualifiedName): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=core-utils-fqn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-fqn.d.ts","sourceRoot":"","sources":["../src/core-utils-fqn.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,oBAAoB;aACH,SAAS,EAAE,MAAM,GAAG,SAAS;aAAkB,MAAM,EAAG,MAAM,GAAG,SAAS;aAAkB,IAAI,EAAG,MAAM;gBAAzG,SAAS,EAAE,MAAM,GAAG,SAAS,EAAkB,MAAM,EAAG,MAAM,GAAG,SAAS,EAAkB,IAAI,EAAG,MAAM;IAGrI,SAAS,CAAC,KAAK,EAAG,oBAAoB,GAAI,OAAO;CASlD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unresolved qualified name by either namespace of prefix
|
|
3
|
+
*/
|
|
4
|
+
export class LexicalQualifiedName {
|
|
5
|
+
constructor(namespace, prefix, name) {
|
|
6
|
+
this.namespace = namespace;
|
|
7
|
+
this.prefix = prefix;
|
|
8
|
+
this.name = name;
|
|
9
|
+
}
|
|
10
|
+
isEqualTo(other) {
|
|
11
|
+
if ((this.name === undefined && other.name === undefined)
|
|
12
|
+
|| (this.name === null && other.name === null)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return this.namespace === other.namespace && this.prefix === other.prefix && this.name === other.name;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Path, Pathway } from "./core-utils-pathway";
|
|
2
|
+
export interface PathwayResolver<T> {
|
|
3
|
+
resolve(path: string | string[] | Pathway): T | undefined;
|
|
4
|
+
}
|
|
5
|
+
export declare class RecordPathwayResolver<T> implements PathwayResolver<T> {
|
|
6
|
+
readonly record: Record<string, T>;
|
|
7
|
+
constructor(record: Record<string, T>);
|
|
8
|
+
resolve(path: string | string[] | Pathway): T | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare class EmptyPathwayResolver<T> implements PathwayResolver<T> {
|
|
11
|
+
resolve(path: string | string[] | Pathway): T | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare class RelativePathwayResolver<T> implements PathwayResolver<T> {
|
|
14
|
+
readonly parentResolver: PathwayResolver<T>;
|
|
15
|
+
readonly path: Path;
|
|
16
|
+
private relativePathway;
|
|
17
|
+
constructor(parentResolver: PathwayResolver<T>, path: Path);
|
|
18
|
+
resolve(path: string | string[] | Pathway): T | undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=core-utils-pathway-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-pathway-resolver.d.ts","sourceRoot":"","sources":["../src/core-utils-pathway-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,OAAO,CAAC,IAAI,EAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAI,CAAC,GAAG,SAAS,CAAA;CAC5D;AAED,qBAAa,qBAAqB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;gBAA1B,MAAM,EAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAG/C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,CAAC,GAAG,SAAS;CAI1D;AAED,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,CAAC,GAAG,SAAS;CAG1D;AAED,qBAAa,uBAAuB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAEvD,QAAQ,CAAC,cAAc,EAAG,eAAe,CAAC,CAAC,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAG,IAAI;IAD9E,OAAO,CAAC,eAAe,CAAU;gBACZ,cAAc,EAAG,eAAe,CAAC,CAAC,CAAC,EAAW,IAAI,EAAG,IAAI;IAG9E,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,CAAC,GAAG,SAAS;CAQ1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Pathway } from "./core-utils-pathway";
|
|
2
|
+
export class RecordPathwayResolver {
|
|
3
|
+
constructor(record) {
|
|
4
|
+
this.record = record;
|
|
5
|
+
}
|
|
6
|
+
resolve(path) {
|
|
7
|
+
const key = Pathway.asString(path);
|
|
8
|
+
return this.record[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class EmptyPathwayResolver {
|
|
12
|
+
resolve(path) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class RelativePathwayResolver {
|
|
17
|
+
constructor(parentResolver, path) {
|
|
18
|
+
this.parentResolver = parentResolver;
|
|
19
|
+
this.path = path;
|
|
20
|
+
this.relativePathway = Pathway.of(path);
|
|
21
|
+
}
|
|
22
|
+
resolve(path) {
|
|
23
|
+
const pathway = Pathway.of(path);
|
|
24
|
+
if (pathway.isAbsolute()) {
|
|
25
|
+
return this.parentResolver.resolve(path);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return this.parentResolver.resolve(this.relativePathway.resolve(pathway));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type Path = string | string[] | Pathway;
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a normalized pathway.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Pathway {
|
|
6
|
+
private segments;
|
|
7
|
+
private isAbsolutePath;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Pathway instance.
|
|
10
|
+
* @param path - The pathway to normalize, either as a string or an array of strings.
|
|
11
|
+
* An empty array or "." represents the current directory.
|
|
12
|
+
*/
|
|
13
|
+
constructor(path: string | string[] | null | undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Factory method to create a Pathway instance.
|
|
16
|
+
* @param path - The pathway to normalize, either as a string or an array of strings.
|
|
17
|
+
* @returns A new Pathway instance.
|
|
18
|
+
*/
|
|
19
|
+
static of(path: string | string[] | null | undefined | Pathway): Pathway;
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes a pathway by converting it into an array of segments.
|
|
22
|
+
* @param path - The pathway to normalize, either as a string or an array of strings.
|
|
23
|
+
* @returns An array of normalized path segments, or an empty array if the input is null or undefined.
|
|
24
|
+
*/
|
|
25
|
+
private normalizePath;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the normalized path segments.
|
|
28
|
+
* @returns An array of normalized path segments.
|
|
29
|
+
*/
|
|
30
|
+
getSegments(): string[];
|
|
31
|
+
isCurrentDir(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Converts the normalized path segments back to a string.
|
|
34
|
+
* @returns The normalized path as a string.
|
|
35
|
+
*/
|
|
36
|
+
toString(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the pathway is absolute.
|
|
39
|
+
* @returns True if the pathway is absolute, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
isAbsolute(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the pathway is relative.
|
|
44
|
+
* @returns True if the pathway is relative, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
isRelative(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the current pathway with another pathway or string.
|
|
49
|
+
* @param otherPath - The other pathway or string to resolve against.
|
|
50
|
+
* @returns A new Pathway instance representing the resolved path.
|
|
51
|
+
*/
|
|
52
|
+
resolve(otherPath: Pathway | string | string[]): Pathway;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the parent directory of the current pathway.
|
|
55
|
+
* @returns A new Pathway instance representing the parent directory.
|
|
56
|
+
*/
|
|
57
|
+
getParent(): Pathway;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the current directory of the pathway.
|
|
60
|
+
* @returns The current directory as a string.
|
|
61
|
+
*/
|
|
62
|
+
getCurrentDirectory(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Static method to get the absolute path of the root.
|
|
65
|
+
* @returns A new Pathway instance representing the root path.
|
|
66
|
+
*/
|
|
67
|
+
static ofRoot(): Pathway;
|
|
68
|
+
/**
|
|
69
|
+
* Determines the relative path from this pathway to another pathway.
|
|
70
|
+
* @param otherPath - The other pathway to relativize against.
|
|
71
|
+
* @returns A new Pathway instance representing the relative path.
|
|
72
|
+
*/
|
|
73
|
+
relativize(otherPath: Pathway | string | string[]): Pathway;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the given path is a descendant of the current pathway.
|
|
76
|
+
* @param otherPath - The other pathway to check.
|
|
77
|
+
* @returns True if the given path is a descendant, false otherwise.
|
|
78
|
+
*/
|
|
79
|
+
isDescendant(otherPath: Pathway | string | string[]): boolean;
|
|
80
|
+
static isRelativePath(path: Path): boolean;
|
|
81
|
+
static asString(path: Path): string;
|
|
82
|
+
static getName(path: string | string[] | Pathway): string;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=core-utils-pathway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-utils-pathway.d.ts","sourceRoot":"","sources":["../src/core-utils-pathway.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAA;AAC9C;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,cAAc,CAAU;IAEhC;;;;OAIG;gBACS,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS;IAUtD;;;;OAIG;WACW,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO;IAQ/E;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAgBrB;;;OAGG;IACI,WAAW,IAAI,MAAM,EAAE;IAIvB,YAAY;IAInB;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;OAGG;IACI,UAAU,IAAI,OAAO;IAI5B;;;OAGG;IACI,UAAU,IAAI,OAAO;IAI5B;;;;OAIG;IACI,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;IAuB/D;;;OAGG;IACI,SAAS,IAAI,OAAO;IAQ3B;;;OAGG;IACI,mBAAmB,IAAI,MAAM;IAOpC;;;OAGG;WACW,MAAM,IAAI,OAAO;IAI/B;;;;OAIG;IACI,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;IAsBlE;;;;OAIG;IACI,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;IAiBpE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAG,IAAI,GAAI,OAAO;IAK5C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAG,IAAI,GAAI,MAAM;IASrC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;CAgBjD"}
|