@fgv/ts-res 4.5.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/ts-res.d.ts +4282 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +79 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/common/conditions.d.ts +148 -0
- package/lib/packlets/common/conditions.d.ts.map +1 -0
- package/lib/packlets/common/conditions.js +50 -0
- package/lib/packlets/common/conditions.js.map +1 -0
- package/lib/packlets/common/convert.d.ts +111 -0
- package/lib/packlets/common/convert.d.ts.map +1 -0
- package/lib/packlets/common/convert.js +173 -0
- package/lib/packlets/common/convert.js.map +1 -0
- package/lib/packlets/common/helpers/conditions.d.ts +39 -0
- package/lib/packlets/common/helpers/conditions.d.ts.map +1 -0
- package/lib/packlets/common/helpers/conditions.js +105 -0
- package/lib/packlets/common/helpers/conditions.js.map +1 -0
- package/lib/packlets/common/helpers/index.d.ts +3 -0
- package/lib/packlets/common/helpers/index.d.ts.map +1 -0
- package/lib/packlets/common/helpers/index.js +40 -0
- package/lib/packlets/common/helpers/index.js.map +1 -0
- package/lib/packlets/common/helpers/resources.d.ts +34 -0
- package/lib/packlets/common/helpers/resources.d.ts.map +1 -0
- package/lib/packlets/common/helpers/resources.js +81 -0
- package/lib/packlets/common/helpers/resources.js.map +1 -0
- package/lib/packlets/common/index.d.ts +7 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +69 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/resources.d.ts +41 -0
- package/lib/packlets/common/resources.d.ts.map +1 -0
- package/lib/packlets/common/resources.js +30 -0
- package/lib/packlets/common/resources.js.map +1 -0
- package/lib/packlets/common/validate/conditions.d.ts +248 -0
- package/lib/packlets/common/validate/conditions.d.ts.map +1 -0
- package/lib/packlets/common/validate/conditions.js +436 -0
- package/lib/packlets/common/validate/conditions.js.map +1 -0
- package/lib/packlets/common/validate/index.d.ts +5 -0
- package/lib/packlets/common/validate/index.d.ts.map +1 -0
- package/lib/packlets/common/validate/index.js +65 -0
- package/lib/packlets/common/validate/index.js.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts +39 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.js +63 -0
- package/lib/packlets/common/validate/regularExpressions.js.map +1 -0
- package/lib/packlets/common/validate/resources.d.ts +97 -0
- package/lib/packlets/common/validate/resources.d.ts.map +1 -0
- package/lib/packlets/common/validate/resources.js +171 -0
- package/lib/packlets/common/validate/resources.js.map +1 -0
- package/lib/packlets/conditions/condition.d.ts +91 -0
- package/lib/packlets/conditions/condition.d.ts.map +1 -0
- package/lib/packlets/conditions/condition.js +146 -0
- package/lib/packlets/conditions/condition.js.map +1 -0
- package/lib/packlets/conditions/conditionCollector.d.ts +54 -0
- package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionCollector.js +72 -0
- package/lib/packlets/conditions/conditionCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionDecls.d.ts +26 -0
- package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionDecls.js +24 -0
- package/lib/packlets/conditions/conditionDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionSet.d.ts +99 -0
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSet.js +164 -0
- package/lib/packlets/conditions/conditionSet.js.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts +65 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.js +90 -0
- package/lib/packlets/conditions/conditionSetCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts +18 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.js +24 -0
- package/lib/packlets/conditions/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionToken.d.ts +86 -0
- package/lib/packlets/conditions/conditionToken.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionToken.js +150 -0
- package/lib/packlets/conditions/conditionToken.js.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +24 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js +54 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/convert/decls.d.ts +24 -0
- package/lib/packlets/conditions/convert/decls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/decls.js +111 -0
- package/lib/packlets/conditions/convert/decls.js.map +1 -0
- package/lib/packlets/conditions/convert/index.d.ts +3 -0
- package/lib/packlets/conditions/convert/index.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/index.js +40 -0
- package/lib/packlets/conditions/convert/index.js.map +1 -0
- package/lib/packlets/conditions/index.d.ts +10 -0
- package/lib/packlets/conditions/index.d.ts.map +1 -0
- package/lib/packlets/conditions/index.js +70 -0
- package/lib/packlets/conditions/index.js.map +1 -0
- package/lib/packlets/decisions/abstractDecision.d.ts +39 -0
- package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecision.js +63 -0
- package/lib/packlets/decisions/abstractDecision.js.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts +59 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js +92 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -0
- package/lib/packlets/decisions/candidate.d.ts +58 -0
- package/lib/packlets/decisions/candidate.d.ts.map +1 -0
- package/lib/packlets/decisions/candidate.js +80 -0
- package/lib/packlets/decisions/candidate.js.map +1 -0
- package/lib/packlets/decisions/common.d.ts +15 -0
- package/lib/packlets/decisions/common.d.ts.map +1 -0
- package/lib/packlets/decisions/common.js +24 -0
- package/lib/packlets/decisions/common.js.map +1 -0
- package/lib/packlets/decisions/concreteDecision.d.ts +74 -0
- package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/concreteDecision.js +114 -0
- package/lib/packlets/decisions/concreteDecision.js.map +1 -0
- package/lib/packlets/decisions/decision.d.ts +91 -0
- package/lib/packlets/decisions/decision.d.ts.map +1 -0
- package/lib/packlets/decisions/decision.js +126 -0
- package/lib/packlets/decisions/decision.js.map +1 -0
- package/lib/packlets/decisions/index.d.ts +7 -0
- package/lib/packlets/decisions/index.d.ts.map +1 -0
- package/lib/packlets/decisions/index.js +44 -0
- package/lib/packlets/decisions/index.js.map +1 -0
- package/lib/packlets/import/fsItem.d.ts +99 -0
- package/lib/packlets/import/fsItem.d.ts.map +1 -0
- package/lib/packlets/import/fsItem.js +174 -0
- package/lib/packlets/import/fsItem.js.map +1 -0
- package/lib/packlets/import/importContext.d.ts +85 -0
- package/lib/packlets/import/importContext.d.ts.map +1 -0
- package/lib/packlets/import/importContext.js +94 -0
- package/lib/packlets/import/importContext.js.map +1 -0
- package/lib/packlets/import/importManager.d.ts +93 -0
- package/lib/packlets/import/importManager.d.ts.map +1 -0
- package/lib/packlets/import/importManager.js +133 -0
- package/lib/packlets/import/importManager.js.map +1 -0
- package/lib/packlets/import/importable.d.ts +71 -0
- package/lib/packlets/import/importable.d.ts.map +1 -0
- package/lib/packlets/import/importable.js +35 -0
- package/lib/packlets/import/importable.js.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts +60 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.js +146 -0
- package/lib/packlets/import/importers/collectionImporter.js.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts +49 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.js +120 -0
- package/lib/packlets/import/importers/fsItemImporter.js.map +1 -0
- package/lib/packlets/import/importers/importer.d.ts +31 -0
- package/lib/packlets/import/importers/importer.d.ts.map +1 -0
- package/lib/packlets/import/importers/importer.js +24 -0
- package/lib/packlets/import/importers/importer.js.map +1 -0
- package/lib/packlets/import/importers/index.d.ts +6 -0
- package/lib/packlets/import/importers/index.d.ts.map +1 -0
- package/lib/packlets/import/importers/index.js +43 -0
- package/lib/packlets/import/importers/index.js.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts +32 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.js +140 -0
- package/lib/packlets/import/importers/jsonImporter.js.map +1 -0
- package/lib/packlets/import/importers/pathImporter.d.ts +61 -0
- package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/pathImporter.js +87 -0
- package/lib/packlets/import/importers/pathImporter.js.map +1 -0
- package/lib/packlets/import/index.d.ts +7 -0
- package/lib/packlets/import/index.d.ts.map +1 -0
- package/lib/packlets/import/index.js +67 -0
- package/lib/packlets/import/index.js.map +1 -0
- package/lib/packlets/qualifier-types/convert.d.ts +19 -0
- package/lib/packlets/qualifier-types/convert.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/convert.js +45 -0
- package/lib/packlets/qualifier-types/convert.js.map +1 -0
- package/lib/packlets/qualifier-types/index.d.ts +8 -0
- package/lib/packlets/qualifier-types/index.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/index.js +68 -0
- package/lib/packlets/qualifier-types/index.js.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +56 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js +87 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +92 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js +114 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +184 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.js +173 -0
- package/lib/packlets/qualifier-types/qualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +40 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js +102 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +74 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js +113 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts +23 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.js +71 -0
- package/lib/packlets/qualifiers/convert/decls.js.map +1 -0
- package/lib/packlets/qualifiers/convert/index.d.ts +3 -0
- package/lib/packlets/qualifiers/convert/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/index.js +40 -0
- package/lib/packlets/qualifiers/convert/index.js.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts +17 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.js +43 -0
- package/lib/packlets/qualifiers/convert/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/index.d.ts +6 -0
- package/lib/packlets/qualifiers/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/index.js +66 -0
- package/lib/packlets/qualifiers/index.js.map +1 -0
- package/lib/packlets/qualifiers/qualifier.d.ts +68 -0
- package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifier.js +87 -0
- package/lib/packlets/qualifiers/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts +90 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.js +157 -0
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts +46 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.js +24 -0
- package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -0
- package/lib/packlets/resource-json/convert.d.ts +54 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -0
- package/lib/packlets/resource-json/convert.js +139 -0
- package/lib/packlets/resource-json/convert.js.map +1 -0
- package/lib/packlets/resource-json/helpers.d.ts +41 -0
- package/lib/packlets/resource-json/helpers.d.ts.map +1 -0
- package/lib/packlets/resource-json/helpers.js +96 -0
- package/lib/packlets/resource-json/helpers.js.map +1 -0
- package/lib/packlets/resource-json/index.d.ts +9 -0
- package/lib/packlets/resource-json/index.d.ts.map +1 -0
- package/lib/packlets/resource-json/index.js +72 -0
- package/lib/packlets/resource-json/index.js.map +1 -0
- package/lib/packlets/resource-json/json.d.ts +182 -0
- package/lib/packlets/resource-json/json.d.ts.map +1 -0
- package/lib/packlets/resource-json/json.js +24 -0
- package/lib/packlets/resource-json/json.js.map +1 -0
- package/lib/packlets/resource-json/normalized.d.ts +123 -0
- package/lib/packlets/resource-json/normalized.d.ts.map +1 -0
- package/lib/packlets/resource-json/normalized.js +24 -0
- package/lib/packlets/resource-json/normalized.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js +121 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts +11 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js +24 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.js +122 -0
- package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -0
- package/lib/packlets/resource-types/index.d.ts +4 -0
- package/lib/packlets/resource-types/index.d.ts.map +1 -0
- package/lib/packlets/resource-types/index.js +41 -0
- package/lib/packlets/resource-types/index.js.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts +65 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.js +63 -0
- package/lib/packlets/resource-types/jsonResourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceType.d.ts +87 -0
- package/lib/packlets/resource-types/resourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceType.js +62 -0
- package/lib/packlets/resource-types/resourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts +30 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js +65 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js.map +1 -0
- package/lib/packlets/resources/index.d.ts +5 -0
- package/lib/packlets/resources/index.d.ts.map +1 -0
- package/lib/packlets/resources/index.js +42 -0
- package/lib/packlets/resources/index.js.map +1 -0
- package/lib/packlets/resources/resource.d.ts +75 -0
- package/lib/packlets/resources/resource.d.ts.map +1 -0
- package/lib/packlets/resources/resource.js +109 -0
- package/lib/packlets/resources/resource.js.map +1 -0
- package/lib/packlets/resources/resourceBuilder.d.ts +112 -0
- package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -0
- package/lib/packlets/resources/resourceBuilder.js +162 -0
- package/lib/packlets/resources/resourceBuilder.js.map +1 -0
- package/lib/packlets/resources/resourceCandidate.d.ts +102 -0
- package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -0
- package/lib/packlets/resources/resourceCandidate.js +180 -0
- package/lib/packlets/resources/resourceCandidate.js.map +1 -0
- package/lib/packlets/resources/resourceManager.d.ts +104 -0
- package/lib/packlets/resources/resourceManager.d.ts.map +1 -0
- package/lib/packlets/resources/resourceManager.js +193 -0
- package/lib/packlets/resources/resourceManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { FileTree, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ResourceManager } from '../resources';
|
|
3
|
+
import { ImportContext } from './importContext';
|
|
4
|
+
import { IImportable } from './importable';
|
|
5
|
+
import { IImporter } from './importers';
|
|
6
|
+
import { IReadOnlyQualifierCollector } from '../qualifiers';
|
|
7
|
+
/**
|
|
8
|
+
* Parameters for creating an {@link Import.ImportManager | ImportManager}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface IImporterCreateParams {
|
|
12
|
+
/**
|
|
13
|
+
* The {@link Resources.ResourceManager | resource manager} into which resources
|
|
14
|
+
* will be imported.
|
|
15
|
+
*/
|
|
16
|
+
resources: ResourceManager;
|
|
17
|
+
/**
|
|
18
|
+
* An optional initial {@link Import.ImportContext | import context} for the import operation.
|
|
19
|
+
*/
|
|
20
|
+
initialContext?: ImportContext;
|
|
21
|
+
/**
|
|
22
|
+
* An optional `FileTree` for importing path items.
|
|
23
|
+
*/
|
|
24
|
+
fileTree?: FileTree.FileTree;
|
|
25
|
+
/**
|
|
26
|
+
* An optional list of {@link Import.Importers.IImporter | importers} to use for the import.
|
|
27
|
+
*/
|
|
28
|
+
importers?: IImporter[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Class to manage the import of resources from various sources.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare class ImportManager {
|
|
35
|
+
/**
|
|
36
|
+
* The {@link Resources.ResourceManager | resource manager} into which resources
|
|
37
|
+
* will be imported.
|
|
38
|
+
*/
|
|
39
|
+
readonly resources: ResourceManager;
|
|
40
|
+
/**
|
|
41
|
+
* The list of {@link Import.Importers.IImporter | importers} to use for the
|
|
42
|
+
* import operations.
|
|
43
|
+
*/
|
|
44
|
+
get importers(): ReadonlyArray<IImporter>;
|
|
45
|
+
/**
|
|
46
|
+
* The initial {@link Import.ImportContext | import context} for the import operation.
|
|
47
|
+
*/
|
|
48
|
+
initialContext: ImportContext;
|
|
49
|
+
protected _stack: IImportable[];
|
|
50
|
+
protected _importers: IImporter[];
|
|
51
|
+
/**
|
|
52
|
+
* Protected constructor for the {@link Import.ImportManager | ImportManager}.
|
|
53
|
+
* @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.
|
|
54
|
+
*/
|
|
55
|
+
protected constructor(params: IImporterCreateParams);
|
|
56
|
+
/**
|
|
57
|
+
* Factory method to create a new {@link Import.ImportManager | ImportManager}.
|
|
58
|
+
* @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.
|
|
59
|
+
* @returns `Success` with the new {@link Import.ImportManager | ImportManager}
|
|
60
|
+
* if successful, or `Failure` with an error message if creation fails.
|
|
61
|
+
*/
|
|
62
|
+
static create(params: IImporterCreateParams): Result<ImportManager>;
|
|
63
|
+
/**
|
|
64
|
+
* Imports resources from an {@link Import.IImportable | importable} object.
|
|
65
|
+
* @param importable - The {@link Import.IImportable | importable} object to import.
|
|
66
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
67
|
+
* or `Failure` with an error message if the import fails.
|
|
68
|
+
*/
|
|
69
|
+
import(importable: IImportable): Result<ImportManager>;
|
|
70
|
+
/**
|
|
71
|
+
* Imports resources from a file system path.
|
|
72
|
+
* @param filePath - The path to import resources from.
|
|
73
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
74
|
+
* or `Failure` with an error message if the import fails.
|
|
75
|
+
*/
|
|
76
|
+
importFromFileSystem(filePath: string): Result<ImportManager>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the default importers using supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers}
|
|
79
|
+
* and optional `FileTree`.
|
|
80
|
+
* @param qualifiers - The {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers} to use for the import.
|
|
81
|
+
* @param tree - An optional `FileTree` for importing path items.
|
|
82
|
+
* @returns A read-only array of {@link Import.Importers.IImporter | importers}.
|
|
83
|
+
*/
|
|
84
|
+
static getDefaultImporters(qualifiers: IReadOnlyQualifierCollector, tree?: FileTree.FileTree): ReadonlyArray<IImporter>;
|
|
85
|
+
/**
|
|
86
|
+
* Imports any items on the import stack.
|
|
87
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
88
|
+
* or `Failure` with an error message if the import fails.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
protected _import(): Result<ImportManager>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=importManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importManager.d.ts","sourceRoot":"","sources":["../../../src/packlets/import/importManager.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,QAAQ,EAAqB,MAAM,EAAW,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAmB,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAsB,SAAS,EAA8B,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,2BAA2B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granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ImportManager = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const importContext_1 = require("./importContext");
|
|
27
|
+
const fsItemImporter_1 = require("./importers/fsItemImporter");
|
|
28
|
+
const importers_1 = require("./importers");
|
|
29
|
+
/**
|
|
30
|
+
* Class to manage the import of resources from various sources.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class ImportManager {
|
|
34
|
+
/**
|
|
35
|
+
* The list of {@link Import.Importers.IImporter | importers} to use for the
|
|
36
|
+
* import operations.
|
|
37
|
+
*/
|
|
38
|
+
get importers() {
|
|
39
|
+
return this._importers;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Protected constructor for the {@link Import.ImportManager | ImportManager}.
|
|
43
|
+
* @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.
|
|
44
|
+
*/
|
|
45
|
+
constructor(params) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
this._stack = [];
|
|
48
|
+
this._importers = [];
|
|
49
|
+
this.resources = params.resources;
|
|
50
|
+
this.initialContext = (_a = params.initialContext) !== null && _a !== void 0 ? _a : importContext_1.ImportContext.create().orThrow();
|
|
51
|
+
this._importers = Array.from((_b = params.importers) !== null && _b !== void 0 ? _b : ImportManager.getDefaultImporters(this.resources.qualifiers, params.fileTree));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Factory method to create a new {@link Import.ImportManager | ImportManager}.
|
|
55
|
+
* @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.
|
|
56
|
+
* @returns `Success` with the new {@link Import.ImportManager | ImportManager}
|
|
57
|
+
* if successful, or `Failure` with an error message if creation fails.
|
|
58
|
+
*/
|
|
59
|
+
static create(params) {
|
|
60
|
+
return (0, ts_utils_1.captureResult)(() => new ImportManager(params));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Imports resources from an {@link Import.IImportable | importable} object.
|
|
64
|
+
* @param importable - The {@link Import.IImportable | importable} object to import.
|
|
65
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
66
|
+
* or `Failure` with an error message if the import fails.
|
|
67
|
+
*/
|
|
68
|
+
import(importable) {
|
|
69
|
+
this._stack.push(importable);
|
|
70
|
+
return this._import();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Imports resources from a file system path.
|
|
74
|
+
* @param filePath - The path to import resources from.
|
|
75
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
76
|
+
* or `Failure` with an error message if the import fails.
|
|
77
|
+
*/
|
|
78
|
+
importFromFileSystem(filePath) {
|
|
79
|
+
const importable = { type: 'path', path: filePath };
|
|
80
|
+
return this.import(importable);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets the default importers using supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers}
|
|
84
|
+
* and optional `FileTree`.
|
|
85
|
+
* @param qualifiers - The {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers} to use for the import.
|
|
86
|
+
* @param tree - An optional `FileTree` for importing path items.
|
|
87
|
+
* @returns A read-only array of {@link Import.Importers.IImporter | importers}.
|
|
88
|
+
*/
|
|
89
|
+
static getDefaultImporters(qualifiers, tree) {
|
|
90
|
+
return [
|
|
91
|
+
importers_1.PathImporter.create({ qualifiers, tree }).orThrow(),
|
|
92
|
+
fsItemImporter_1.FsItemImporter.create({ qualifiers }).orThrow(),
|
|
93
|
+
importers_1.JsonImporter.create().orThrow(),
|
|
94
|
+
importers_1.CollectionImporter.create().orThrow()
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Imports any items on the import stack.
|
|
99
|
+
* @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,
|
|
100
|
+
* or `Failure` with an error message if the import fails.
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
_import() {
|
|
104
|
+
const errors = new ts_utils_1.MessageAggregator();
|
|
105
|
+
while (this._stack.length > 0) {
|
|
106
|
+
const item = this._stack.pop();
|
|
107
|
+
if (item !== undefined) {
|
|
108
|
+
let processed = false;
|
|
109
|
+
let consumed = false;
|
|
110
|
+
for (const importer of this._importers) {
|
|
111
|
+
if (consumed || !importer.types.includes(item.type)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const result = importer.import(item, this.resources).aggregateError(errors);
|
|
115
|
+
processed = processed || result.detail !== 'skipped';
|
|
116
|
+
consumed = consumed || result.detail === 'consumed';
|
|
117
|
+
if (result.isSuccess()) {
|
|
118
|
+
this._stack.push(...result.value);
|
|
119
|
+
}
|
|
120
|
+
else if (result.detail !== 'skipped') {
|
|
121
|
+
errors.addMessage(`${item.type}: ${result.message}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!processed) {
|
|
125
|
+
errors.addMessage(`${item.type}: No matching importer found`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return errors.returnOrReport((0, ts_utils_1.succeed)(this));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.ImportManager = ImportManager;
|
|
133
|
+
//# sourceMappingURL=importManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importManager.js","sourceRoot":"","sources":["../../../src/packlets/import/importManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAA4F;AAE5F,mDAAgD;AAEhD,+DAA4D;AAC5D,2CAAwF;AA8BxF;;;GAGG;AACH,MAAa,aAAa;IAOxB;;;OAGG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAUD;;;OAGG;IACH,YAAsB,MAA6B;;QAPzC,WAAM,GAAkB,EAAE,CAAC;QAC3B,eAAU,GAAgB,EAAE,CAAC;QAOrC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,MAAA,MAAM,CAAC,cAAc,mCAAI,6BAAa,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;QAChF,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAC1B,MAAA,MAAM,CAAC,SAAS,mCAAI,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAClG,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAA6B;QAChD,OAAO,IAAA,wBAA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,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBACpD,SAAS;oBACX,CAAC;oBAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;oBAC5E,SAAS,GAAG,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC;oBACrD,QAAQ,GAAG,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC;oBAEpD,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;wBACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;oBACpC,CAAC;yBAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wBACvC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;oBACvD,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,8BAA8B,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,cAAc,CAAC,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF;AA7HD,sCA6HC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, FileTree, MessageAggregator, Result, succeed } from '@fgv/ts-utils';\nimport { ResourceManager } from '../resources';\nimport { ImportContext } from './importContext';\nimport { IImportable, IImportablePath } from './importable';\nimport { FsItemImporter } from './importers/fsItemImporter';\nimport { CollectionImporter, IImporter, JsonImporter, PathImporter } from './importers';\nimport { IReadOnlyQualifierCollector } from '../qualifiers';\n\n/**\n * Parameters for creating an {@link Import.ImportManager | ImportManager}.\n * @public\n */\nexport interface IImporterCreateParams {\n /**\n * The {@link Resources.ResourceManager | resource manager} into which resources\n * will be imported.\n */\n resources: ResourceManager;\n\n /**\n * An optional initial {@link Import.ImportContext | import context} for the import operation.\n */\n initialContext?: ImportContext;\n\n /**\n * An optional `FileTree` for importing path items.\n */\n fileTree?: FileTree.FileTree;\n\n /**\n * An optional list of {@link Import.Importers.IImporter | importers} to use for the import.\n */\n importers?: IImporter[];\n}\n\n/**\n * Class to manage the import of resources from various sources.\n * @public\n */\nexport class ImportManager {\n /**\n * The {@link Resources.ResourceManager | resource manager} into which resources\n * will be imported.\n */\n public readonly resources: ResourceManager;\n\n /**\n * The list of {@link Import.Importers.IImporter | importers} to use for the\n * import operations.\n */\n public get importers(): ReadonlyArray<IImporter> {\n return this._importers;\n }\n\n /**\n * The initial {@link Import.ImportContext | import context} for the import operation.\n */\n public initialContext: ImportContext;\n\n protected _stack: IImportable[] = [];\n protected _importers: IImporter[] = [];\n\n /**\n * Protected constructor for the {@link Import.ImportManager | ImportManager}.\n * @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.\n */\n protected constructor(params: IImporterCreateParams) {\n this.resources = params.resources;\n this.initialContext = params.initialContext ?? ImportContext.create().orThrow();\n this._importers = Array.from(\n params.importers ?? ImportManager.getDefaultImporters(this.resources.qualifiers, params.fileTree)\n );\n }\n\n /**\n * Factory method to create a new {@link Import.ImportManager | ImportManager}.\n * @param params - Parameters for creating the {@link Import.ImportManager | ImportManager}.\n * @returns `Success` with the new {@link Import.ImportManager | ImportManager}\n * if successful, or `Failure` with an error message if creation fails.\n */\n public static create(params: IImporterCreateParams): Result<ImportManager> {\n return captureResult(() => new ImportManager(params));\n }\n\n /**\n * Imports resources from an {@link Import.IImportable | importable} object.\n * @param importable - The {@link Import.IImportable | importable} object to import.\n * @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,\n * or `Failure` with an error message if the import fails.\n */\n public import(importable: IImportable): Result<ImportManager> {\n this._stack.push(importable);\n return this._import();\n }\n\n /**\n * Imports resources from a file system path.\n * @param filePath - The path to import resources from.\n * @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,\n * or `Failure` with an error message if the import fails.\n */\n public importFromFileSystem(filePath: string): Result<ImportManager> {\n const importable: IImportablePath = { type: 'path', path: filePath };\n return this.import(importable);\n }\n\n /**\n * Gets the default importers using supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers}\n * and optional `FileTree`.\n * @param qualifiers - The {@link Qualifiers.IReadOnlyQualifierCollector | qualifiers} to use for the import.\n * @param tree - An optional `FileTree` for importing path items.\n * @returns A read-only array of {@link Import.Importers.IImporter | importers}.\n */\n public static getDefaultImporters(\n qualifiers: IReadOnlyQualifierCollector,\n tree?: FileTree.FileTree\n ): ReadonlyArray<IImporter> {\n return [\n PathImporter.create({ qualifiers, tree }).orThrow(),\n FsItemImporter.create({ qualifiers }).orThrow(),\n JsonImporter.create().orThrow(),\n CollectionImporter.create().orThrow()\n ];\n }\n\n /**\n * Imports any items on the import stack.\n * @returns `Success` with the {@link Import.ImportManager | ImportManager} if successful,\n * or `Failure` with an error message if the import fails.\n * @public\n */\n protected _import(): Result<ImportManager> {\n const errors: MessageAggregator = new MessageAggregator();\n\n while (this._stack.length > 0) {\n const item = this._stack.pop();\n if (item !== undefined) {\n let processed: boolean = false;\n let consumed: boolean = false;\n\n for (const importer of this._importers) {\n if (consumed || !importer.types.includes(item.type)) {\n continue;\n }\n\n const result = importer.import(item, this.resources).aggregateError(errors);\n processed = processed || result.detail !== 'skipped';\n consumed = consumed || result.detail === 'consumed';\n\n if (result.isSuccess()) {\n this._stack.push(...result.value);\n } else if (result.detail !== 'skipped') {\n errors.addMessage(`${item.type}: ${result.message}`);\n }\n }\n\n if (!processed) {\n errors.addMessage(`${item.type}: No matching importer found`);\n }\n }\n }\n\n return errors.returnOrReport(succeed(this));\n }\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import * as ResourceJson from '../resource-json';
|
|
3
|
+
import { ImportContext } from './importContext';
|
|
4
|
+
import { FsItem } from './fsItem';
|
|
5
|
+
/**
|
|
6
|
+
* Base interface for importable entities.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IImportable {
|
|
10
|
+
type: string;
|
|
11
|
+
context?: ImportContext;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a filesystem path to be imported.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface IImportablePath extends IImportable {
|
|
18
|
+
type: 'path';
|
|
19
|
+
path: string;
|
|
20
|
+
context?: ImportContext;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Represents a filesystem item to be imported.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface IImportableFsItem extends IImportable {
|
|
27
|
+
type: 'fsItem';
|
|
28
|
+
item: FsItem;
|
|
29
|
+
context?: ImportContext;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Represents some JSON to be imported.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface IImportableJson extends IImportable {
|
|
36
|
+
type: 'json';
|
|
37
|
+
json: JsonValue;
|
|
38
|
+
context?: ImportContext;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a resource collection to be imported.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export interface IImportableResourceCollection extends IImportable {
|
|
45
|
+
type: 'resourceCollection';
|
|
46
|
+
collection: ResourceJson.ResourceDeclCollection;
|
|
47
|
+
context?: ImportContext;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents a resource tree to be imported.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface IImportableResourceTree extends IImportable {
|
|
54
|
+
type: 'resourceTree';
|
|
55
|
+
tree: ResourceJson.ResourceDeclTree;
|
|
56
|
+
context?: ImportContext;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type of importable entities.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export type Importable = IImportablePath | IImportableFsItem | IImportableJson | IImportableResourceCollection | IImportableResourceTree;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard for {@link Import.Importable | importables}.
|
|
65
|
+
* @param i - The entity to check.
|
|
66
|
+
* @returns `true` if the supplied {@link Import.IImportable | IImportable} is a
|
|
67
|
+
* {@link Import.Importable | known importable}, `false` otherwise.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare function isImportable(i: IImportable): i is Importable;
|
|
71
|
+
//# sourceMappingURL=importable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importable.d.ts","sourceRoot":"","sources":["../../../src/packlets/import/importable.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,S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C,CAAC,EAAE,WAAW,GAAG,CAAC,IAAI,UAAU,CAE5D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.isImportable = isImportable;
|
|
25
|
+
/**
|
|
26
|
+
* Type guard for {@link Import.Importable | importables}.
|
|
27
|
+
* @param i - The entity to check.
|
|
28
|
+
* @returns `true` if the supplied {@link Import.IImportable | IImportable} is a
|
|
29
|
+
* {@link Import.Importable | known importable}, `false` otherwise.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
function isImportable(i) {
|
|
33
|
+
return ['path', 'fsItem', 'json', 'resourceCollection', 'resourceTree'].includes(i.type);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=importable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importable.js","sourceRoot":"","sources":["../../../src/packlets/import/importable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAoFH,oCAEC;AATD;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,CAAc;IACzC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonValue } from '@fgv/ts-json-base';\nimport * as ResourceJson from '../resource-json';\nimport { ImportContext } from './importContext';\nimport { FsItem } from './fsItem';\n\n/**\n * Base interface for importable entities.\n * @public\n */\nexport interface IImportable {\n type: string;\n context?: ImportContext;\n}\n\n/**\n * Represents a filesystem path to be imported.\n * @public\n */\nexport interface IImportablePath extends IImportable {\n type: 'path';\n path: string;\n context?: ImportContext;\n}\n\n/**\n * Represents a filesystem item to be imported.\n * @public\n */\nexport interface IImportableFsItem extends IImportable {\n type: 'fsItem';\n item: FsItem;\n context?: ImportContext;\n}\n\n/**\n * Represents some JSON to be imported.\n * @public\n */\nexport interface IImportableJson extends IImportable {\n type: 'json';\n json: JsonValue;\n context?: ImportContext;\n}\n\n/**\n * Represents a resource collection to be imported.\n * @public\n */\nexport interface IImportableResourceCollection extends IImportable {\n type: 'resourceCollection';\n collection: ResourceJson.ResourceDeclCollection;\n context?: ImportContext;\n}\n\n/**\n * Represents a resource tree to be imported.\n * @public\n */\nexport interface IImportableResourceTree extends IImportable {\n type: 'resourceTree';\n tree: ResourceJson.ResourceDeclTree;\n context?: ImportContext;\n}\n\n/**\n * Type of importable entities.\n * @public\n */\nexport type Importable =\n | IImportablePath\n | IImportableFsItem\n | IImportableJson\n | IImportableResourceCollection\n | IImportableResourceTree;\n\n/**\n * Type guard for {@link Import.Importable | importables}.\n * @param i - The entity to check.\n * @returns `true` if the supplied {@link Import.IImportable | IImportable} is a\n * {@link Import.Importable | known importable}, `false` otherwise.\n * @public\n */\nexport function isImportable(i: IImportable): i is Importable {\n return ['path', 'fsItem', 'json', 'resourceCollection', 'resourceTree'].includes(i.type);\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ResourceManager } from '../../resources';
|
|
3
|
+
import { IImportable } from '../importable';
|
|
4
|
+
import { IImporter, ImporterResultDetail } from './importer';
|
|
5
|
+
/**
|
|
6
|
+
* {@link Import.Importers.IImporter | Importer} implementation which imports
|
|
7
|
+
* a {@link ResourceJson.ResourceDeclCollection | resource collection} or
|
|
8
|
+
* {@link ResourceJson.ResourceDeclTree | resource tree} from an importable item.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare class CollectionImporter implements IImporter {
|
|
12
|
+
/**
|
|
13
|
+
* {@inheritdoc Import.Importers.IImporter.types}
|
|
14
|
+
*/
|
|
15
|
+
readonly types: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Protected {@link Import.Importers.CollectionImporter | CollectionImporter} constructor for derived classes
|
|
18
|
+
*/
|
|
19
|
+
protected constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new {@link Import.Importers.CollectionImporter | CollectionImporter} instance.
|
|
22
|
+
* @returns `Success` with the new {@link Import.Importers.CollectionImporter | CollectionImporter} if successful,
|
|
23
|
+
* `Failure` o4
|
|
24
|
+
*
|
|
25
|
+
* therwise.
|
|
26
|
+
*/
|
|
27
|
+
static create(): Result<CollectionImporter>;
|
|
28
|
+
/**
|
|
29
|
+
* {@inheritdoc Import.Importers.IImporter.import}
|
|
30
|
+
*/
|
|
31
|
+
import(item: IImportable, manager: ResourceManager): DetailedResult<IImportable[], ImporterResultDetail>;
|
|
32
|
+
/**
|
|
33
|
+
* Adds a {@link ResourceJson.Normalized.ILooseResourceDecl | declared resource} to
|
|
34
|
+
* the supplied {@link Resources.ResourceManager | resource manager}, merging an
|
|
35
|
+
* optional {@link Import.ImportContext | import context} if provided.
|
|
36
|
+
* @param manager - The {@link Resources.ResourceManager | resource manager} to which
|
|
37
|
+
* the resource will be added.
|
|
38
|
+
* @param resource - The {@link ResourceJson.Normalized.ILooseResourceDecl | resource}
|
|
39
|
+
* to add.
|
|
40
|
+
* @param context - Optional {@link Import.ImportContext | import context} to merge
|
|
41
|
+
* with the resource.
|
|
42
|
+
* @returns `Success` with the {@link Resources.ResourceBuilder | resource builder}
|
|
43
|
+
* for the resource if successful, `Failure` with an error message if not.
|
|
44
|
+
*/
|
|
45
|
+
private _addResource;
|
|
46
|
+
/**
|
|
47
|
+
* Adds a {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | declared resource candidate}
|
|
48
|
+
* to the supplied {@link Resources.ResourceManager | resource manager}, merging an optional
|
|
49
|
+
* {@link Import.ImportContext | import context} if provided.
|
|
50
|
+
* @param manager - The {@link Resources.ResourceManager | resource manager} to which the
|
|
51
|
+
* candidate will be added.
|
|
52
|
+
* @param candidate - The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | candidate}
|
|
53
|
+
* to add.
|
|
54
|
+
* @param context - Optional {@link Import.ImportContext | import context} to merge with the candidate.
|
|
55
|
+
* @returns `Success` with the {@link Resources.ResourceCandidate | resource candidate} if successful,
|
|
56
|
+
* `Failure` with an error message if not.
|
|
57
|
+
*/
|
|
58
|
+
private _addCandidate;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=collectionImporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionImporter.d.ts","sourceRoot":"","sources":["../../../../src/packlets/import/importers/collectionImporter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,cAAc,EAGd,MAAM,EAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAsC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAgB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAI7D;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,SAAS;IAClD;;OAEG;IACH,SAAgB,KAAK,EAAE,MAAM,EAAE,CAA0C;IAEzE;;OAEG;IACH,SAAS;IAET;;;;;;OAMG;WACW,MAAM,IAAI,MAAM,CAAC,kBAAkB,CAAC;IAIlD;;OAEG;IACI,MAAM,CACX,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,eAAe,GACvB,cAAc,CAAC,WAAW,EAAE,EAAE,oBAAoB,CAAC;IAoBtD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,YAAY;IAapB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,aAAa;CActB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.CollectionImporter = void 0;
|
|
58
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
59
|
+
const importable_1 = require("../importable");
|
|
60
|
+
const ResourceJson = __importStar(require("../../resource-json"));
|
|
61
|
+
/**
|
|
62
|
+
* {@link Import.Importers.IImporter | Importer} implementation which imports
|
|
63
|
+
* a {@link ResourceJson.ResourceDeclCollection | resource collection} or
|
|
64
|
+
* {@link ResourceJson.ResourceDeclTree | resource tree} from an importable item.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
class CollectionImporter {
|
|
68
|
+
/**
|
|
69
|
+
* Protected {@link Import.Importers.CollectionImporter | CollectionImporter} constructor for derived classes
|
|
70
|
+
*/
|
|
71
|
+
constructor() {
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritdoc Import.Importers.IImporter.types}
|
|
74
|
+
*/
|
|
75
|
+
this.types = ['resourceCollection', 'resourceTree'];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new {@link Import.Importers.CollectionImporter | CollectionImporter} instance.
|
|
79
|
+
* @returns `Success` with the new {@link Import.Importers.CollectionImporter | CollectionImporter} if successful,
|
|
80
|
+
* `Failure` o4
|
|
81
|
+
*
|
|
82
|
+
* therwise.
|
|
83
|
+
*/
|
|
84
|
+
static create() {
|
|
85
|
+
return (0, ts_utils_1.captureResult)(() => new CollectionImporter());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* {@inheritdoc Import.Importers.IImporter.import}
|
|
89
|
+
*/
|
|
90
|
+
import(item, manager) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
if (!(0, importable_1.isImportable)(item) || (item.type !== 'resourceCollection' && item.type !== 'resourceTree')) {
|
|
93
|
+
/* c8 ignore next 1 - defense in depth */
|
|
94
|
+
const name = (_b = (_a = item.context) === null || _a === void 0 ? void 0 : _a.baseId) !== null && _b !== void 0 ? _b : 'unknown';
|
|
95
|
+
return (0, ts_utils_1.failWithDetail)(`${name}: not a valid resource collection importable (${item.type})`, 'skipped');
|
|
96
|
+
}
|
|
97
|
+
const collection = item.type === 'resourceCollection' ? item.collection : item.tree;
|
|
98
|
+
const errors = new ts_utils_1.MessageAggregator();
|
|
99
|
+
for (const resource of collection.getLooseResources()) {
|
|
100
|
+
this._addResource(manager, resource, item.context).aggregateError(errors);
|
|
101
|
+
}
|
|
102
|
+
for (const candidate of collection.getLooseCandidates()) {
|
|
103
|
+
this._addCandidate(manager, candidate, item.context).aggregateError(errors);
|
|
104
|
+
}
|
|
105
|
+
return errors.returnOrReport((0, ts_utils_1.succeed)([])).withDetail('failed', 'consumed');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a {@link ResourceJson.Normalized.ILooseResourceDecl | declared resource} to
|
|
109
|
+
* the supplied {@link Resources.ResourceManager | resource manager}, merging an
|
|
110
|
+
* optional {@link Import.ImportContext | import context} if provided.
|
|
111
|
+
* @param manager - The {@link Resources.ResourceManager | resource manager} to which
|
|
112
|
+
* the resource will be added.
|
|
113
|
+
* @param resource - The {@link ResourceJson.Normalized.ILooseResourceDecl | resource}
|
|
114
|
+
* to add.
|
|
115
|
+
* @param context - Optional {@link Import.ImportContext | import context} to merge
|
|
116
|
+
* with the resource.
|
|
117
|
+
* @returns `Success` with the {@link Resources.ResourceBuilder | resource builder}
|
|
118
|
+
* for the resource if successful, `Failure` with an error message if not.
|
|
119
|
+
*/
|
|
120
|
+
_addResource(manager, resource, context) {
|
|
121
|
+
if (context) {
|
|
122
|
+
return ResourceJson.Helpers.mergeLooseResource(resource, context.baseId, context.conditions).onSuccess((merged) => manager.addResource(merged));
|
|
123
|
+
}
|
|
124
|
+
return manager.addResource(resource);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Adds a {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | declared resource candidate}
|
|
128
|
+
* to the supplied {@link Resources.ResourceManager | resource manager}, merging an optional
|
|
129
|
+
* {@link Import.ImportContext | import context} if provided.
|
|
130
|
+
* @param manager - The {@link Resources.ResourceManager | resource manager} to which the
|
|
131
|
+
* candidate will be added.
|
|
132
|
+
* @param candidate - The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | candidate}
|
|
133
|
+
* to add.
|
|
134
|
+
* @param context - Optional {@link Import.ImportContext | import context} to merge with the candidate.
|
|
135
|
+
* @returns `Success` with the {@link Resources.ResourceCandidate | resource candidate} if successful,
|
|
136
|
+
* `Failure` with an error message if not.
|
|
137
|
+
*/
|
|
138
|
+
_addCandidate(manager, candidate, context) {
|
|
139
|
+
if (context) {
|
|
140
|
+
return ResourceJson.Helpers.mergeLooseCandidate(candidate, context.baseId, context.conditions).onSuccess((merged) => manager.addLooseCandidate(merged));
|
|
141
|
+
}
|
|
142
|
+
return manager.addLooseCandidate(candidate);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.CollectionImporter = CollectionImporter;
|
|
146
|
+
//# sourceMappingURL=collectionImporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectionImporter.js","sourceRoot":"","sources":["../../../../src/packlets/import/importers/collectionImporter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAOuB;AAEvB,8CAA0D;AAE1D,kEAAoD;AAGpD;;;;;GAKG;AACH,MAAa,kBAAkB;IAM7B;;OAEG;IACH;QARA;;WAEG;QACa,UAAK,GAAa,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC;IAKhD,CAAC;IAE1B;;;;;;OAMG;IACI,MAAM,CAAC,MAAM;QAClB,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACI,MAAM,CACX,IAAiB,EACjB,OAAwB;;QAExB,IAAI,CAAC,IAAA,yBAAY,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,oBAAoB,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,EAAE,CAAC;YAChG,yCAAyC;YACzC,MAAM,IAAI,GAAG,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,mCAAI,SAAS,CAAC;YAC/C,OAAO,IAAA,yBAAc,EAAC,GAAG,IAAI,iDAAiD,IAAI,CAAC,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC;QACzG,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,C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7C,SAAS,EACT,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,UAAU,CACnB,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF;AApGD,gDAoGC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n captureResult,\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed\n} from '@fgv/ts-utils';\nimport { ResourceBuilder, ResourceCandidate, ResourceManager } from '../../resources';\nimport { IImportable, isImportable } from '../importable';\nimport { IImporter, ImporterResultDetail } from './importer';\nimport * as ResourceJson from '../../resource-json';\nimport { ImportContext } from '../importContext';\n\n/**\n * {@link Import.Importers.IImporter | Importer} implementation which imports\n * a {@link ResourceJson.ResourceDeclCollection | resource collection} or\n * {@link ResourceJson.ResourceDeclTree | resource tree} from an importable item.\n * @public\n */\nexport class CollectionImporter implements IImporter {\n /**\n * {@inheritdoc Import.Importers.IImporter.types}\n */\n public readonly types: string[] = ['resourceCollection', 'resourceTree'];\n\n /**\n * Protected {@link Import.Importers.CollectionImporter | CollectionImporter} constructor for derived classes\n */\n protected constructor() {}\n\n /**\n * Creates a new {@link Import.Importers.CollectionImporter | CollectionImporter} instance.\n * @returns `Success` with the new {@link Import.Importers.CollectionImporter | CollectionImporter} if successful,\n * `Failure` o4\n *\n * therwise.\n */\n public static create(): Result<CollectionImporter> {\n return captureResult(() => new CollectionImporter());\n }\n\n /**\n * {@inheritdoc Import.Importers.IImporter.import}\n */\n public import(\n item: IImportable,\n manager: ResourceManager\n ): DetailedResult<IImportable[], ImporterResultDetail> {\n if (!isImportable(item) || (item.type !== 'resourceCollection' && item.type !== 'resourceTree')) {\n /* c8 ignore next 1 - defense in depth */\n const name = item.context?.baseId ?? 'unknown';\n return failWithDetail(`${name}: not a valid resource collection importable (${item.type})`, 'skipped');\n }\n\n const collection = item.type === 'resourceCollection' ? item.collection : item.tree;\n\n const errors: MessageAggregator = new MessageAggregator();\n for (const resource of collection.getLooseResources()) {\n this._addResource(manager, resource, item.context).aggregateError(errors);\n }\n\n for (const candidate of collection.getLooseCandidates()) {\n this._addCandidate(manager, candidate, item.context).aggregateError(errors);\n }\n return errors.returnOrReport(succeed([])).withDetail('failed', 'consumed');\n }\n\n /**\n * Adds a {@link ResourceJson.Normalized.ILooseResourceDecl | declared resource} to\n * the supplied {@link Resources.ResourceManager | resource manager}, merging an\n * optional {@link Import.ImportContext | import context} if provided.\n * @param manager - The {@link Resources.ResourceManager | resource manager} to which\n * the resource will be added.\n * @param resource - The {@link ResourceJson.Normalized.ILooseResourceDecl | resource}\n * to add.\n * @param context - Optional {@link Import.ImportContext | import context} to merge\n * with the resource.\n * @returns `Success` with the {@link Resources.ResourceBuilder | resource builder}\n * for the resource if successful, `Failure` with an error message if not.\n */\n private _addResource(\n manager: ResourceManager,\n resource: ResourceJson.Normalized.ILooseResourceDecl,\n context?: ImportContext\n ): Result<ResourceBuilder> {\n if (context) {\n return ResourceJson.Helpers.mergeLooseResource(resource, context.baseId, context.conditions).onSuccess(\n (merged) => manager.addResource(merged)\n );\n }\n return manager.addResource(resource);\n }\n\n /**\n * Adds a {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | declared resource candidate}\n * to the supplied {@link Resources.ResourceManager | resource manager}, merging an optional\n * {@link Import.ImportContext | import context} if provided.\n * @param manager - The {@link Resources.ResourceManager | resource manager} to which the\n * candidate will be added.\n * @param candidate - The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | candidate}\n * to add.\n * @param context - Optional {@link Import.ImportContext | import context} to merge with the candidate.\n * @returns `Success` with the {@link Resources.ResourceCandidate | resource candidate} if successful,\n * `Failure` with an error message if not.\n */\n private _addCandidate(\n manager: ResourceManager,\n candidate: ResourceJson.Normalized.ILooseResourceCandidateDecl,\n context?: ImportContext\n ): Result<ResourceCandidate> {\n if (context) {\n return ResourceJson.Helpers.mergeLooseCandidate(\n candidate,\n context.baseId,\n context.conditions\n ).onSuccess((merged) => manager.addLooseCandidate(merged));\n }\n return manager.addLooseCandidate(candidate);\n }\n}\n"]}
|