@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,39 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IResourceDeclContainer } from './resourceDeclContainer';
|
|
3
|
+
import * as Normalized from './normalized';
|
|
4
|
+
/**
|
|
5
|
+
* Class that extracts resources and candidates from a
|
|
6
|
+
* {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class ResourceDeclTree implements IResourceDeclContainer {
|
|
10
|
+
/**
|
|
11
|
+
* The {@link ResourceJson.Normalized.IResourceTreeRootDecl | resource tree root declaration}
|
|
12
|
+
* being processed.
|
|
13
|
+
*/
|
|
14
|
+
readonly tree: Normalized.IResourceTreeRootDecl;
|
|
15
|
+
protected _resources: Normalized.ILooseResourceDecl[];
|
|
16
|
+
protected _candidates: Normalized.ILooseResourceCandidateDecl[];
|
|
17
|
+
protected constructor(tree: Normalized.IResourceTreeRootDecl);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new {@link ResourceJson.ResourceDeclTree | ResourceDeclTree} from an
|
|
20
|
+
* untyped {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root declaration}.
|
|
21
|
+
* @param from - The JSON object to convert.
|
|
22
|
+
* @returns `Success` with the new tree if the JSON object is valid, otherwise `Failure`.
|
|
23
|
+
*/
|
|
24
|
+
static create(from: unknown): Result<ResourceDeclTree>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the loose resources extracted from the collection.
|
|
27
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceDecl | loose resource declarations}
|
|
28
|
+
* extracted from the collection.
|
|
29
|
+
*/
|
|
30
|
+
getLooseResources(): ReadonlyArray<Normalized.ILooseResourceDecl>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the loose candidates extracted from the collection.
|
|
33
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | loose resource candidate declarations}
|
|
34
|
+
* extracted from the collection.
|
|
35
|
+
*/
|
|
36
|
+
getLooseCandidates(): ReadonlyArray<Normalized.ILooseResourceCandidateDecl>;
|
|
37
|
+
private _extract;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=resourceDeclTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceDeclTree.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-json/resourceDeclTree.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAgD,MAAM,EAAW,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAK3C;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,sBAAsB;IAC7D;;;OAGG;IACH,SAAgB,IAAI,EAAE,UAAU,CAAC,qBAAqB,CAAC;IAEvD,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,kBAAkB,EAAE,CAAM;IAC3D,SAAS,CAAC,WAAW,EAAE,UAAU,CAAC,2BAA2B,EAAE,CAAM;IAErE,SAAS,aAAa,IAAI,EAAE,UAAU,CAAC,qBAAqB;IAK5D;;;;;OAKG;WACW,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAS7D;;;;OAIG;IACI,iBAAiB,IAAI,aAAa,CAAC,UAAU,CAAC,kBAAkB,CAAC;IAIxE;;;;OAIG;IACI,kBAAkB,IAAI,aAAa,CAAC,UAAU,CAAC,2BAA2B,CAAC;IAIlF,OAAO,CAAC,QAAQ;CAuBjB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
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.ResourceDeclTree = void 0;
|
|
58
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
59
|
+
const Convert = __importStar(require("./convert"));
|
|
60
|
+
const common_1 = require("../common");
|
|
61
|
+
const helpers_1 = require("./helpers");
|
|
62
|
+
/**
|
|
63
|
+
* Class that extracts resources and candidates from a
|
|
64
|
+
* {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root}.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
class ResourceDeclTree {
|
|
68
|
+
constructor(tree) {
|
|
69
|
+
this._resources = [];
|
|
70
|
+
this._candidates = [];
|
|
71
|
+
this.tree = tree;
|
|
72
|
+
this._extract(tree, tree.baseName).orThrow();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new {@link ResourceJson.ResourceDeclTree | ResourceDeclTree} from an
|
|
76
|
+
* untyped {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root declaration}.
|
|
77
|
+
* @param from - The JSON object to convert.
|
|
78
|
+
* @returns `Success` with the new tree if the JSON object is valid, otherwise `Failure`.
|
|
79
|
+
*/
|
|
80
|
+
static create(from) {
|
|
81
|
+
return Convert.resourceTreeRootDecl
|
|
82
|
+
.convert(from)
|
|
83
|
+
.withErrorFormat((err) => `Invalid resource tree: ${err}`)
|
|
84
|
+
.onSuccess((decl) => {
|
|
85
|
+
return (0, ts_utils_1.captureResult)(() => new ResourceDeclTree(decl));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the loose resources extracted from the collection.
|
|
90
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceDecl | loose resource declarations}
|
|
91
|
+
* extracted from the collection.
|
|
92
|
+
*/
|
|
93
|
+
getLooseResources() {
|
|
94
|
+
return this._resources;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets the loose candidates extracted from the collection.
|
|
98
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | loose resource candidate declarations}
|
|
99
|
+
* extracted from the collection.
|
|
100
|
+
*/
|
|
101
|
+
getLooseCandidates() {
|
|
102
|
+
return this._candidates;
|
|
103
|
+
}
|
|
104
|
+
_extract(node, parentName, parentConditions) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const errors = new ts_utils_1.MessageAggregator();
|
|
107
|
+
const resourceEntries = Array.from(Object.entries((_a = node.resources) !== null && _a !== void 0 ? _a : {}));
|
|
108
|
+
const mergedResources = resourceEntries.map(([name, resource]) => (0, helpers_1.mergeChildResource)(resource, name, parentName, parentConditions));
|
|
109
|
+
this._resources.push(...(0, ts_utils_1.mapResults)(mergedResources).aggregateError(errors).orDefault([]));
|
|
110
|
+
const children = Array.from(Object.entries((_b = node.children) !== null && _b !== void 0 ? _b : {}));
|
|
111
|
+
children.forEach(([name, childNode]) => {
|
|
112
|
+
common_1.Helpers.joinResourceIds(parentName, name)
|
|
113
|
+
.onSuccess((childName) => {
|
|
114
|
+
return this._extract(childNode, childName, parentConditions).aggregateError(errors);
|
|
115
|
+
})
|
|
116
|
+
.aggregateError(errors);
|
|
117
|
+
});
|
|
118
|
+
return errors.returnOrReport((0, ts_utils_1.succeed)(this));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ResourceDeclTree = ResourceDeclTree;
|
|
122
|
+
//# sourceMappingURL=resourceDeclTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceDeclTree.js","sourceRoot":"","sources":["../../../src/packlets/resource-json/resourceDeclTree.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8F;AAE9F,mDAAqC;AAGrC,sCAAqD;AACrD,uCAA+C;AAE/C;;;;GAIG;AACH,MAAa,gBAAgB;IAU3B,YAAsB,IAAsC;QAHlD,eAAU,GAAoC,EAAE,CAAC;QACjD,gBAAW,GAA6C,EAAE,CAAC;QAGnE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,IAAa;QAChC,OAAO,OAAO,CAAC,oBAAoB;aAChC,OAAO,CAAC,IAAI,CAAC;aACb,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,0BAA0B,GAAG,EAAE,CAAC;aACzD,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,kBAAkB;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEO,QAAQ,CACd,IAA2C,EAC3C,UAAmB,EACnB,gBAA6C;;QAE7C,MAAM,MAAM,GAAsB,IAAI,4BAAiB,EAAE,CAAC;QAE1D,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAA,IAAI,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,CAAC;QACzE,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,CAC/D,IAAA,4BAAkB,EAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,CAAC,CACjE,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAA,qBAAU,EAAC,eAAe,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAE1F,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAA,IAAI,CAAC,QAAQ,mCAAI,EAAE,CAAC,CAAC,CAAC;QACjE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE;YACrC,gBAAa,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC;iBAC5C,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE;gBACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACtF,CAAC,CAAC;iBACD,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,cAAc,CAAC,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF;AAvED,4CAuEC","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, mapResults, MessageAggregator, Result, succeed } from '@fgv/ts-utils';\nimport { IResourceDeclContainer } from './resourceDeclContainer';\nimport * as Convert from './convert';\nimport * as Normalized from './normalized';\nimport * as Json from './json';\nimport { Helpers as CommonHelpers } from '../common';\nimport { mergeChildResource } from './helpers';\n\n/**\n * Class that extracts resources and candidates from a\n * {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root}.\n * @public\n */\nexport class ResourceDeclTree implements IResourceDeclContainer {\n /**\n * The {@link ResourceJson.Normalized.IResourceTreeRootDecl | resource tree root declaration}\n * being processed.\n */\n public readonly tree: Normalized.IResourceTreeRootDecl;\n\n protected _resources: Normalized.ILooseResourceDecl[] = [];\n protected _candidates: Normalized.ILooseResourceCandidateDecl[] = [];\n\n protected constructor(tree: Normalized.IResourceTreeRootDecl) {\n this.tree = tree;\n this._extract(tree, tree.baseName).orThrow();\n }\n\n /**\n * Creates a new {@link ResourceJson.ResourceDeclTree | ResourceDeclTree} from an\n * untyped {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root declaration}.\n * @param from - The JSON object to convert.\n * @returns `Success` with the new tree if the JSON object is valid, otherwise `Failure`.\n */\n public static create(from: unknown): Result<ResourceDeclTree> {\n return Convert.resourceTreeRootDecl\n .convert(from)\n .withErrorFormat((err) => `Invalid resource tree: ${err}`)\n .onSuccess((decl) => {\n return captureResult(() => new ResourceDeclTree(decl));\n });\n }\n\n /**\n * Gets the loose resources extracted from the collection.\n * @returns The {@link ResourceJson.Normalized.ILooseResourceDecl | loose resource declarations}\n * extracted from the collection.\n */\n public getLooseResources(): ReadonlyArray<Normalized.ILooseResourceDecl> {\n return this._resources;\n }\n\n /**\n * Gets the loose candidates extracted from the collection.\n * @returns The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | loose resource candidate declarations}\n * extracted from the collection.\n */\n public getLooseCandidates(): ReadonlyArray<Normalized.ILooseResourceCandidateDecl> {\n return this._candidates;\n }\n\n private _extract(\n node: Normalized.IResourceTreeChildNodeDecl,\n parentName?: string,\n parentConditions?: Json.ILooseConditionDecl[]\n ): Result<this> {\n const errors: MessageAggregator = new MessageAggregator();\n\n const resourceEntries = Array.from(Object.entries(node.resources ?? {}));\n const mergedResources = resourceEntries.map(([name, resource]) =>\n mergeChildResource(resource, name, parentName, parentConditions)\n );\n this._resources.push(...mapResults(mergedResources).aggregateError(errors).orDefault([]));\n\n const children = Array.from(Object.entries(node.children ?? {}));\n children.forEach(([name, childNode]) => {\n CommonHelpers.joinResourceIds(parentName, name)\n .onSuccess((childName) => {\n return this._extract(childNode, childName, parentConditions).aggregateError(errors);\n })\n .aggregateError(errors);\n });\n return errors.returnOrReport(succeed(this));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/index.ts"],"names":[],"mappings":"AAsBA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
__exportStar(require("./resourceType"), exports);
|
|
39
|
+
__exportStar(require("./resourceTypeCollector"), exports);
|
|
40
|
+
__exportStar(require("./jsonResourceType"), exports);
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/resource-types/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,iDAA+B;AAC/B,0DAAwC;AACxC,qDAAmC","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\nexport * from './resourceType';\nexport * from './resourceTypeCollector';\nexport * from './jsonResourceType';\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { JsonObject, JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { ResourceType } from './resourceType';
|
|
3
|
+
import { ResourceTypeName, ResourceValueMergeMethod } from '../common';
|
|
4
|
+
import { Result } from '@fgv/ts-utils';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters to create a {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IJsonResourceTypeCreateParams {
|
|
10
|
+
/**
|
|
11
|
+
* Optional key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
12
|
+
* Defaults to 'json'.
|
|
13
|
+
*/
|
|
14
|
+
key?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType}
|
|
17
|
+
* instance.
|
|
18
|
+
*/
|
|
19
|
+
index?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Implementation of a {@link ResourceTypes.ResourceType | ResourceType} for JSON values.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare class JsonResourceType extends ResourceType<JsonObject> {
|
|
26
|
+
/**
|
|
27
|
+
* Protected {@link ResourceTypes.JsonResourceType | JsonResourceType} constructor for use by subclasses.
|
|
28
|
+
* Use {@link ResourceTypes.JsonResourceType.create | JsonResourceType.create} to create a new instance.
|
|
29
|
+
* @param key - The key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
30
|
+
* @param index - Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
31
|
+
*/
|
|
32
|
+
protected constructor(key: ResourceTypeName, index?: number);
|
|
33
|
+
/**
|
|
34
|
+
* Factory method to create a new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
35
|
+
* @param params - {@link ResourceTypes.IJsonResourceTypeCreateParams | Parameters} to create the new instance.
|
|
36
|
+
* @returns `Success` with the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance if successful
|
|
37
|
+
* or `Failure` with an error message if not.
|
|
38
|
+
*/
|
|
39
|
+
static create(params?: IJsonResourceTypeCreateParams): Result<JsonResourceType>;
|
|
40
|
+
/**
|
|
41
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:1)}
|
|
42
|
+
*/
|
|
43
|
+
validateDeclaration(json: JsonValue, isPartial: true, mergeMethod?: ResourceValueMergeMethod): Result<Partial<JsonObject>>;
|
|
44
|
+
/**
|
|
45
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:2)}
|
|
46
|
+
*/
|
|
47
|
+
validateDeclaration(json: JsonValue, isPartial: false, mergeMethod?: ResourceValueMergeMethod): Result<JsonObject>;
|
|
48
|
+
/**
|
|
49
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:3)}
|
|
50
|
+
*/
|
|
51
|
+
validateDeclaration(json: JsonValue, isPartial: boolean, mergeMethod?: ResourceValueMergeMethod): Result<JsonObject | Partial<JsonObject>>;
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validate:1)}
|
|
54
|
+
*/
|
|
55
|
+
validate(json: JsonObject, isPartial: true): Result<JsonObject>;
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validate:2)}
|
|
58
|
+
*/
|
|
59
|
+
validate(json: JsonObject, isPartial: false): Result<JsonObject>;
|
|
60
|
+
/**
|
|
61
|
+
* {@inheritdoc ResourceTypes.ResourceType.(validate:3)}
|
|
62
|
+
*/
|
|
63
|
+
validate(json: JsonObject, isPartial: boolean): Result<JsonObject>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=jsonResourceType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonResourceType.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/jsonResourceType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAgC,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAW,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,YAAY,CAAC,UAAU,CAAC;IAC5D;;;;;OAKG;IACH,SAAS,aAAa,GAAG,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM;IAI3D;;;;;OAKG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAMtF;;OAEG;IACI,mBAAmB,CACxB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,IAAI,EACf,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9B;;OAEG;IACI,mBAAmB,CACxB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,KAAK,EAChB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,UAAU,CAAC;IACrB;;OAEG;IACI,mBAAmB,CACxB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,OAAO,EAClB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAS3C;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;IACtE;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;IACvE;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC;CAI1E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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.JsonResourceType = void 0;
|
|
25
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
26
|
+
const resourceType_1 = require("./resourceType");
|
|
27
|
+
const common_1 = require("../common");
|
|
28
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
29
|
+
/**
|
|
30
|
+
* Implementation of a {@link ResourceTypes.ResourceType | ResourceType} for JSON values.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class JsonResourceType extends resourceType_1.ResourceType {
|
|
34
|
+
/**
|
|
35
|
+
* Protected {@link ResourceTypes.JsonResourceType | JsonResourceType} constructor for use by subclasses.
|
|
36
|
+
* Use {@link ResourceTypes.JsonResourceType.create | JsonResourceType.create} to create a new instance.
|
|
37
|
+
* @param key - The key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
38
|
+
* @param index - Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
39
|
+
*/
|
|
40
|
+
constructor(key, index) {
|
|
41
|
+
super(key, index);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Factory method to create a new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
45
|
+
* @param params - {@link ResourceTypes.IJsonResourceTypeCreateParams | Parameters} to create the new instance.
|
|
46
|
+
* @returns `Success` with the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance if successful
|
|
47
|
+
* or `Failure` with an error message if not.
|
|
48
|
+
*/
|
|
49
|
+
static create(params) {
|
|
50
|
+
var _a;
|
|
51
|
+
return common_1.Convert.resourceTypeName.convert((_a = params === null || params === void 0 ? void 0 : params.key) !== null && _a !== void 0 ? _a : 'json').onSuccess((key) => {
|
|
52
|
+
return (0, ts_utils_1.captureResult)(() => new JsonResourceType(key, params === null || params === void 0 ? void 0 : params.index));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
validateDeclaration(json, __isPartial, __mergeMethod) {
|
|
56
|
+
return ts_json_base_1.Converters.jsonObject.convert(json);
|
|
57
|
+
}
|
|
58
|
+
validate(json, __isPartial) {
|
|
59
|
+
return ts_json_base_1.Converters.jsonObject.convert(json);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.JsonResourceType = JsonResourceType;
|
|
63
|
+
//# sourceMappingURL=jsonResourceType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonResourceType.js","sourceRoot":"","sources":["../../../src/packlets/resource-types/jsonResourceType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,oDAAwF;AACxF,iDAA8C;AAC9C,sCAAgF;AAChF,4CAAsD;AAoBtD;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,2BAAwB;IAC5D;;;;;OAKG;IACH,YAAsB,GAAqB,EAAE,KAAc;QACzD,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAAsC;;QACzD,OAAO,gBAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,mCAAI,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/E,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;IA0BM,mBAAmB,CACxB,IAAe,EACf,WAAoB,EACpB,aAAwC;QAExC,OAAO,yBAAc,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAcM,QAAQ,CAAC,IAAgB,EAAE,WAAoB;QACpD,OAAO,yBAAc,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AAtED,4CAsEC","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 { Converters as JsonConverters, JsonObject, JsonValue } from '@fgv/ts-json-base';\nimport { ResourceType } from './resourceType';\nimport { Convert, ResourceTypeName, ResourceValueMergeMethod } from '../common';\nimport { captureResult, Result } from '@fgv/ts-utils';\n\n/**\n * Parameters to create a {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.\n * @public\n */\nexport interface IJsonResourceTypeCreateParams {\n /**\n * Optional key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.\n * Defaults to 'json'.\n */\n key?: string;\n\n /**\n * Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType}\n * instance.\n */\n index?: number;\n}\n\n/**\n * Implementation of a {@link ResourceTypes.ResourceType | ResourceType} for JSON values.\n * @public\n */\nexport class JsonResourceType extends ResourceType<JsonObject> {\n /**\n * Protected {@link ResourceTypes.JsonResourceType | JsonResourceType} constructor for use by subclasses.\n * Use {@link ResourceTypes.JsonResourceType.create | JsonResourceType.create} to create a new instance.\n * @param key - The key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.\n * @param index - Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.\n */\n protected constructor(key: ResourceTypeName, index?: number) {\n super(key, index);\n }\n\n /**\n * Factory method to create a new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.\n * @param params - {@link ResourceTypes.IJsonResourceTypeCreateParams | Parameters} to create the new instance.\n * @returns `Success` with the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance if successful\n * or `Failure` with an error message if not.\n */\n public static create(params?: IJsonResourceTypeCreateParams): Result<JsonResourceType> {\n return Convert.resourceTypeName.convert(params?.key ?? 'json').onSuccess((key) => {\n return captureResult(() => new JsonResourceType(key, params?.index));\n });\n }\n\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:1)}\n */\n public validateDeclaration(\n json: JsonValue,\n isPartial: true,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<Partial<JsonObject>>;\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:2)}\n */\n public validateDeclaration(\n json: JsonValue,\n isPartial: false,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<JsonObject>;\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validateDeclaration:3)}\n */\n public validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<JsonObject | Partial<JsonObject>>;\n public validateDeclaration(\n json: JsonValue,\n __isPartial: boolean,\n __mergeMethod?: ResourceValueMergeMethod\n ): Result<JsonObject | Partial<JsonObject>> {\n return JsonConverters.jsonObject.convert(json);\n }\n\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validate:1)}\n */\n public validate(json: JsonObject, isPartial: true): Result<JsonObject>;\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validate:2)}\n */\n public validate(json: JsonObject, isPartial: false): Result<JsonObject>;\n /**\n * {@inheritdoc ResourceTypes.ResourceType.(validate:3)}\n */\n public validate(json: JsonObject, isPartial: boolean): Result<JsonObject>;\n public validate(json: JsonObject, __isPartial: boolean): Result<JsonObject> {\n return JsonConverters.jsonObject.convert(json);\n }\n}\n"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { ICollectible, Result } from '@fgv/ts-utils';
|
|
3
|
+
import { ResourceTypeIndex, ResourceTypeName, ResourceValueMergeMethod } from '../common';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for resource types which are responsible for
|
|
6
|
+
* validating and converting JSON values into the appropriate strongly-typed
|
|
7
|
+
* resource value.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class ResourceType<T = unknown> implements ICollectible<ResourceTypeName, ResourceTypeIndex> {
|
|
11
|
+
private _collectible;
|
|
12
|
+
/**
|
|
13
|
+
* The key for this resource type.
|
|
14
|
+
*/
|
|
15
|
+
get key(): ResourceTypeName;
|
|
16
|
+
/**
|
|
17
|
+
* The index for this resource type.
|
|
18
|
+
*/
|
|
19
|
+
get index(): ResourceTypeIndex | undefined;
|
|
20
|
+
protected constructor(key: ResourceTypeName, index?: number);
|
|
21
|
+
/**
|
|
22
|
+
* Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for
|
|
23
|
+
* a partial resource instance value.
|
|
24
|
+
* @param json - The JSON value to validate.
|
|
25
|
+
* @param isPartial - `true` indicates that the value is expected to be incomplete.
|
|
26
|
+
* @param mergeMethod - The method to use when merging with previously resolved values.
|
|
27
|
+
* @returns `Success` with the strongly-typed resource value if the JSON and merge
|
|
28
|
+
* method are valid, `Failure` with an error message otherwise.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
abstract validateDeclaration(json: JsonValue, isPartial: true, mergeMethod?: ResourceValueMergeMethod): Result<Partial<T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for
|
|
34
|
+
* a complete resource instance value.
|
|
35
|
+
* @param json - The JSON value to validate.
|
|
36
|
+
* @param isPartial - `false` indicates that the value is expected to be complete.
|
|
37
|
+
* @param mergeMethod - The method to use when merging with previously resolved values.
|
|
38
|
+
* @returns `Success` with the strongly-typed resource value if the JSON and merge method
|
|
39
|
+
* are valid, `Failure` with an error message otherwise.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
abstract validateDeclaration(json: JsonValue, isPartial: false, mergeMethod?: ResourceValueMergeMethod): Result<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for
|
|
45
|
+
* a resource instance value.
|
|
46
|
+
* @param json - The JSON value to validate.
|
|
47
|
+
* @param isPartial - Indicates whether the value is expected to be incomplete.
|
|
48
|
+
* @param mergeMethod - The method to use when merging with previously resolved values.
|
|
49
|
+
* @returns `Success` with the strongly-typed resource value if the JSON and merge method
|
|
50
|
+
* are valid, `Failure` with an error message otherwise.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
abstract validateDeclaration(json: JsonValue, isPartial: boolean, mergeMethod?: ResourceValueMergeMethod): Result<T | Partial<T>>;
|
|
54
|
+
abstract validateDeclaration(json: JsonValue, isPartial: boolean, mergeMethod?: ResourceValueMergeMethod): Result<T | Partial<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Validates a JSON value for use as a partial resource instance value.
|
|
57
|
+
* @param json - The JSON value to validate.
|
|
58
|
+
* @param isPartial - `true` indicates that the value is expected to be partial.
|
|
59
|
+
* @returns `Success` with the strongly-typed partial resource value if the JSON is valid,
|
|
60
|
+
* `Failure` with an error message otherwise.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
abstract validate(json: JsonValue, isPartial: true): Result<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Validates a JSON value for use as a complete resource instance value.
|
|
66
|
+
* @param json - The JSON value to validate.
|
|
67
|
+
* @param isPartial - `false` indicates that the value is expected to be complete.
|
|
68
|
+
* @returns `Success` with the strongly-typed resource value if the JSON is valid,
|
|
69
|
+
* `Failure` with an error message otherwise.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
abstract validate(json: JsonValue, isPartial: false): Result<Partial<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* Validates a JSON value for use as a full or partial resource instance value.
|
|
75
|
+
* @param json - The JSON value to validate.
|
|
76
|
+
* @param isPartial - Indicates whether the value is expected to be partial.
|
|
77
|
+
* @returns `Success` with the strongly-typed full or partial resource value if
|
|
78
|
+
* the JSON is valid, `Failure` with an error message otherwise.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
abstract validate(json: JsonValue, isPartial: boolean): Result<T | Partial<T>>;
|
|
82
|
+
/**
|
|
83
|
+
* Sets the index for this resource type. Once set, the index cannot be changed.
|
|
84
|
+
*/
|
|
85
|
+
setIndex(index: number): Result<ResourceTypeIndex>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=resourceType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceType.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAe,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAGL,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,WAAW,CAAC;AAEnB;;;;;GAKG;AACH,8BAAsB,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,YAAY,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IAC1G,OAAO,CAAC,YAAY,CAA+D;IACnF;;OAEG;IACH,IAAW,GAAG,IAAI,gBAAgB,CAEjC;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,iBAAiB,GAAG,SAAS,CAEhD;IAED,SAAS,aAAa,GAAG,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM;IAS3D;;;;;;;;;OASG;aACa,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,IAAI,EACf,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;;;;;OASG;aACa,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,KAAK,EAChB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,CAAC,CAAC;IAEZ;;;;;;;;;OASG;aACa,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,OAAO,EAClB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;aAET,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,OAAO,EAClB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;;;;OAOG;aACa,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;IAErE;;;;;;;OAOG;aACa,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAE/E;;;;;;;OAOG;aACa,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAErF;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;CAG1D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.ResourceType = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const common_1 = require("../common");
|
|
27
|
+
/**
|
|
28
|
+
* Abstract base class for resource types which are responsible for
|
|
29
|
+
* validating and converting JSON values into the appropriate strongly-typed
|
|
30
|
+
* resource value.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class ResourceType {
|
|
34
|
+
/**
|
|
35
|
+
* The key for this resource type.
|
|
36
|
+
*/
|
|
37
|
+
get key() {
|
|
38
|
+
return this._collectible.key;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The index for this resource type.
|
|
42
|
+
*/
|
|
43
|
+
get index() {
|
|
44
|
+
return this._collectible.index;
|
|
45
|
+
}
|
|
46
|
+
constructor(key, index) {
|
|
47
|
+
this._collectible = new ts_utils_1.Collections.Collectible({
|
|
48
|
+
key,
|
|
49
|
+
/* c8 ignore next 1 - coverage having a rough time */
|
|
50
|
+
index: index !== undefined ? common_1.Validate.toResourceTypeIndex(index).orThrow() : undefined,
|
|
51
|
+
indexConverter: common_1.Convert.resourceTypeIndex
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the index for this resource type. Once set, the index cannot be changed.
|
|
56
|
+
*/
|
|
57
|
+
setIndex(index) {
|
|
58
|
+
return this._collectible.setIndex(index);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ResourceType = ResourceType;
|
|
62
|
+
//# sourceMappingURL=resourceType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceType.js","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAkE;AAClE,sCAMmB;AAEnB;;;;;GAKG;AACH,MAAsB,YAAY;IAEhC;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,YAAsB,GAAqB,EAAE,KAAc;QACzD,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAsC;YACnF,GAAG;YACH,qDAAqD;YACrD,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;YACtF,cAAc,EAAE,gBAAa,CAAC,iBAAiB;SAChD,CAAC,CAAC;IACL,CAAC;IAsFD;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAnHD,oCAmHC","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 { Collections, ICollectible, Result } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n Validate,\n ResourceTypeIndex,\n ResourceTypeName,\n ResourceValueMergeMethod\n} from '../common';\n\n/**\n * Abstract base class for resource types which are responsible for\n * validating and converting JSON values into the appropriate strongly-typed\n * resource value.\n * @public\n */\nexport abstract class ResourceType<T = unknown> implements ICollectible<ResourceTypeName, ResourceTypeIndex> {\n private _collectible: Collections.Collectible<ResourceTypeName, ResourceTypeIndex>;\n /**\n * The key for this resource type.\n */\n public get key(): ResourceTypeName {\n return this._collectible.key;\n }\n\n /**\n * The index for this resource type.\n */\n public get index(): ResourceTypeIndex | undefined {\n return this._collectible.index;\n }\n\n protected constructor(key: ResourceTypeName, index?: number) {\n this._collectible = new Collections.Collectible<ResourceTypeName, ResourceTypeIndex>({\n key,\n /* c8 ignore next 1 - coverage having a rough time */\n index: index !== undefined ? Validate.toResourceTypeIndex(index).orThrow() : undefined,\n indexConverter: CommonConvert.resourceTypeIndex\n });\n }\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge\n * method are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: true,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<Partial<T>>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: false,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n /**\n * Validates a JSON value for use as a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be partial.\n * @returns `Success` with the strongly-typed partial resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: true): Result<T>;\n\n /**\n * Validates a JSON value for use as a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @returns `Success` with the strongly-typed resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: false): Result<Partial<T>>;\n\n /**\n * Validates a JSON value for use as a full or partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be partial.\n * @returns `Success` with the strongly-typed full or partial resource value if\n * the JSON is valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: boolean): Result<T | Partial<T>>;\n\n /**\n * Sets the index for this resource type. Once set, the index cannot be changed.\n */\n public setIndex(index: number): Result<ResourceTypeIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Collections, Result, ValidatingCollector } from '@fgv/ts-utils';
|
|
2
|
+
import { ResourceType } from './resourceType';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for creating a {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IResourceCollectorCreateParams {
|
|
8
|
+
resourceTypes?: ResourceType[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Map {@link ResourceTypeName | resource type names} to {@link ResourceTypes.ResourceType | resource types}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class ResourceTypeCollector extends ValidatingCollector<ResourceType> {
|
|
15
|
+
protected constructor({ resourceTypes }: IResourceCollectorCreateParams);
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.
|
|
18
|
+
* @param params - Optional for creating the new collector.
|
|
19
|
+
* @returns `Success` with the new instance, or `Failure` with an error
|
|
20
|
+
* message if the collector could not be created.
|
|
21
|
+
*/
|
|
22
|
+
static create(params?: IResourceCollectorCreateParams): Result<ResourceTypeCollector>;
|
|
23
|
+
protected _toResourceType(from: unknown): Result<ResourceType>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A read-only version of {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export type ReadOnlyResourceTypeCollector = Collections.IReadOnlyValidatingCollector<ResourceType>;
|
|
30
|
+
//# sourceMappingURL=resourceTypeCollector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceTypeCollector.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceTypeCollector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAiB,mBAAmB,EAAiB,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,mBAAmB,CAAC,YAAY,CAAC;IAC1E,SAAS,aAAa,EAAE,aAAa,EAAE,EAAE,8BAA8B;IAevE;;;;;OAKG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,8BAA8B,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAM5F,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC;CAM/D;AAED;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,WAAW,CAAC,4BAA4B,CAAC,YAAY,CAAC,CAAC"}
|