@xrmforge/typegen 0.2.0 → 0.4.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/dist/index.d.ts +141 -10
- package/dist/index.js +455 -99
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare enum ErrorCode {
|
|
|
21
21
|
META_SOLUTION_NOT_FOUND = "META_3002",
|
|
22
22
|
META_FORM_PARSE_FAILED = "META_3003",
|
|
23
23
|
META_ATTRIBUTE_UNKNOWN_TYPE = "META_3004",
|
|
24
|
+
META_VERSION_STAMP_EXPIRED = "META_3005",
|
|
24
25
|
GEN_OUTPUT_WRITE_FAILED = "GEN_4001",
|
|
25
26
|
GEN_TEMPLATE_FAILED = "GEN_4002",
|
|
26
27
|
GEN_INVALID_IDENTIFIER = "GEN_4003",
|
|
@@ -302,6 +303,8 @@ declare class DataverseHttpClient {
|
|
|
302
303
|
private readonly maxRateLimitRetries;
|
|
303
304
|
private readonly readOnly;
|
|
304
305
|
private cachedToken;
|
|
306
|
+
/** Pending token refresh promise (prevents concurrent token requests) */
|
|
307
|
+
private pendingTokenRefresh;
|
|
305
308
|
private activeConcurrentRequests;
|
|
306
309
|
private readonly waitQueue;
|
|
307
310
|
constructor(options: HttpClientOptions);
|
|
@@ -327,6 +330,16 @@ declare class DataverseHttpClient {
|
|
|
327
330
|
* @param signal - Optional AbortSignal to cancel the request
|
|
328
331
|
*/
|
|
329
332
|
getAll<T>(path: string, signal?: AbortSignal): Promise<T[]>;
|
|
333
|
+
/**
|
|
334
|
+
* Execute a POST request that is semantically a read operation.
|
|
335
|
+
* Used for Dataverse actions like RetrieveMetadataChanges that require POST
|
|
336
|
+
* but do not modify data. Allowed even in read-only mode.
|
|
337
|
+
*
|
|
338
|
+
* @param path - API path (relative to apiUrl)
|
|
339
|
+
* @param body - JSON body to send
|
|
340
|
+
* @param signal - Optional AbortSignal to cancel the request
|
|
341
|
+
*/
|
|
342
|
+
postReadOnly<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T>;
|
|
330
343
|
/**
|
|
331
344
|
* Returns true if this client is in read-only mode (the safe default).
|
|
332
345
|
*/
|
|
@@ -360,6 +373,8 @@ declare class DataverseHttpClient {
|
|
|
360
373
|
*/
|
|
361
374
|
static escapeODataString(value: string): string;
|
|
362
375
|
private getToken;
|
|
376
|
+
/** Internal: actually acquire a new token from the credential provider. */
|
|
377
|
+
private refreshToken;
|
|
363
378
|
/**
|
|
364
379
|
* Execute a request within the concurrency semaphore.
|
|
365
380
|
* The semaphore is acquired ONCE per logical request. Retries happen
|
|
@@ -800,9 +815,11 @@ declare class MetadataCache {
|
|
|
800
815
|
private readonly cacheDir;
|
|
801
816
|
private readonly cacheFilePath;
|
|
802
817
|
/**
|
|
803
|
-
* @param
|
|
818
|
+
* @param cacheDir - Directory where cache files are stored.
|
|
819
|
+
* Can be an absolute path or relative to cwd.
|
|
820
|
+
* Defaults to ".xrmforge/cache" when constructed without argument.
|
|
804
821
|
*/
|
|
805
|
-
constructor(
|
|
822
|
+
constructor(cacheDir?: string);
|
|
806
823
|
/**
|
|
807
824
|
* Load cached metadata from disk.
|
|
808
825
|
* Returns null if no cache exists, cache is for a different environment,
|
|
@@ -837,6 +854,58 @@ declare class MetadataCache {
|
|
|
837
854
|
exists(): Promise<boolean>;
|
|
838
855
|
}
|
|
839
856
|
|
|
857
|
+
/**
|
|
858
|
+
* @xrmforge/typegen - Metadata Change Detector
|
|
859
|
+
*
|
|
860
|
+
* Uses the Dataverse RetrieveMetadataChanges action to determine
|
|
861
|
+
* which entities have changed since the last generation run.
|
|
862
|
+
* This enables incremental type generation (only re-fetch changed entities).
|
|
863
|
+
*
|
|
864
|
+
* @see https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/retrievemetadatachanges
|
|
865
|
+
*/
|
|
866
|
+
|
|
867
|
+
/** Result of a change detection query */
|
|
868
|
+
interface ChangeDetectionResult {
|
|
869
|
+
/** Entity logical names that have changed (new or modified) */
|
|
870
|
+
changedEntityNames: string[];
|
|
871
|
+
/** Entity logical names that have been deleted */
|
|
872
|
+
deletedEntityNames: string[];
|
|
873
|
+
/** New server version stamp (store this for the next run) */
|
|
874
|
+
newVersionStamp: string;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Detects metadata changes in Dataverse using RetrieveMetadataChanges.
|
|
878
|
+
*
|
|
879
|
+
* Usage:
|
|
880
|
+
* ```typescript
|
|
881
|
+
* const detector = new ChangeDetector(httpClient);
|
|
882
|
+
* const result = await detector.detectChanges(cachedVersionStamp);
|
|
883
|
+
* // result.changedEntityNames = ['account', 'contact']
|
|
884
|
+
* // result.newVersionStamp = 'new-stamp-to-cache'
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
declare class ChangeDetector {
|
|
888
|
+
private readonly http;
|
|
889
|
+
constructor(http: DataverseHttpClient);
|
|
890
|
+
/**
|
|
891
|
+
* Detect which entities have changed since the given version stamp.
|
|
892
|
+
*
|
|
893
|
+
* @param clientVersionStamp - The ServerVersionStamp from the last run (from cache)
|
|
894
|
+
* @returns Changed entity names, deleted entity names, and new version stamp
|
|
895
|
+
* @throws {MetadataError} with META_VERSION_STAMP_EXPIRED if stamp is too old (>90 days)
|
|
896
|
+
*/
|
|
897
|
+
detectChanges(clientVersionStamp: string): Promise<ChangeDetectionResult>;
|
|
898
|
+
/**
|
|
899
|
+
* Perform an initial metadata query to get the first ServerVersionStamp.
|
|
900
|
+
* This is used on the very first run (no cache exists).
|
|
901
|
+
*
|
|
902
|
+
* @returns The initial server version stamp
|
|
903
|
+
*/
|
|
904
|
+
getInitialVersionStamp(): Promise<string>;
|
|
905
|
+
/** Check if an error is the expired version stamp error (0x80044352) */
|
|
906
|
+
private isExpiredVersionStampError;
|
|
907
|
+
}
|
|
908
|
+
|
|
840
909
|
/**
|
|
841
910
|
* @xrmforge/typegen - Label Utilities
|
|
842
911
|
*
|
|
@@ -1362,6 +1431,36 @@ declare function generateEntityFieldsEnum(info: EntityTypeInfo, options?: Entity
|
|
|
1362
1431
|
*/
|
|
1363
1432
|
declare function generateEntityNavigationProperties(info: EntityTypeInfo, options?: EntityFieldsGeneratorOptions): string;
|
|
1364
1433
|
|
|
1434
|
+
/**
|
|
1435
|
+
* @xrmforge/typegen - Entity Names Enum Generator
|
|
1436
|
+
*
|
|
1437
|
+
* Generates a single const enum with all entity logical names.
|
|
1438
|
+
* Eliminates raw strings in Xrm.WebApi calls.
|
|
1439
|
+
*
|
|
1440
|
+
* Output pattern:
|
|
1441
|
+
* ```typescript
|
|
1442
|
+
* declare namespace XrmForge {
|
|
1443
|
+
* const enum EntityNames {
|
|
1444
|
+
* Account = 'account',
|
|
1445
|
+
* Contact = 'contact',
|
|
1446
|
+
* Lead = 'lead',
|
|
1447
|
+
* }
|
|
1448
|
+
* }
|
|
1449
|
+
* ```
|
|
1450
|
+
*/
|
|
1451
|
+
interface EntityNamesGeneratorOptions {
|
|
1452
|
+
/** Namespace (default: "XrmForge") */
|
|
1453
|
+
namespace?: string;
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Generate a const enum mapping entity PascalCase names to logical names.
|
|
1457
|
+
*
|
|
1458
|
+
* @param entityNames - Array of entity logical names
|
|
1459
|
+
* @param options - Generator options
|
|
1460
|
+
* @returns TypeScript declaration string
|
|
1461
|
+
*/
|
|
1462
|
+
declare function generateEntityNamesEnum(entityNames: string[], options?: EntityNamesGeneratorOptions): string;
|
|
1463
|
+
|
|
1365
1464
|
/**
|
|
1366
1465
|
* @xrmforge/typegen - Web API Helper Functions
|
|
1367
1466
|
*
|
|
@@ -1781,17 +1880,19 @@ interface GenerateConfig {
|
|
|
1781
1880
|
generateOptionSets?: boolean;
|
|
1782
1881
|
/** Whether to generate Custom API Action/Function executors (default: false) */
|
|
1783
1882
|
generateActions?: boolean;
|
|
1883
|
+
/** Filter Custom APIs by uniquename prefix (e.g. "markant_"). Only APIs matching the prefix are generated. */
|
|
1884
|
+
actionsFilter?: string;
|
|
1784
1885
|
/**
|
|
1785
1886
|
* Whether to use metadata cache for faster re-generation.
|
|
1786
|
-
*
|
|
1787
|
-
*
|
|
1887
|
+
* When enabled, only changed entities are re-fetched from Dataverse
|
|
1888
|
+
* using RetrieveMetadataChanges delta detection.
|
|
1889
|
+
* On first run or expired cache, a full refresh is performed automatically.
|
|
1788
1890
|
* @defaultValue false
|
|
1789
1891
|
*/
|
|
1790
1892
|
useCache?: boolean;
|
|
1791
1893
|
/**
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1794
|
-
* Planned for v0.2.0.
|
|
1894
|
+
* Directory for metadata cache files.
|
|
1895
|
+
* Relative paths are resolved from the current working directory.
|
|
1795
1896
|
* @defaultValue ".xrmforge/cache"
|
|
1796
1897
|
*/
|
|
1797
1898
|
cacheDir?: string;
|
|
@@ -1816,6 +1917,19 @@ interface GeneratedFile {
|
|
|
1816
1917
|
/** Type of generated content */
|
|
1817
1918
|
type: 'entity' | 'optionset' | 'form' | 'action';
|
|
1818
1919
|
}
|
|
1920
|
+
/** Statistics about cache usage during generation */
|
|
1921
|
+
interface CacheStats {
|
|
1922
|
+
/** Whether the cache was used in this run */
|
|
1923
|
+
cacheUsed: boolean;
|
|
1924
|
+
/** Whether this was a full refresh (no prior cache or expired stamp) */
|
|
1925
|
+
fullRefresh: boolean;
|
|
1926
|
+
/** Number of entities loaded from cache (unchanged) */
|
|
1927
|
+
entitiesFromCache: number;
|
|
1928
|
+
/** Number of entities fetched from Dataverse (new or changed) */
|
|
1929
|
+
entitiesFetched: number;
|
|
1930
|
+
/** Number of entities removed (deleted in Dataverse) */
|
|
1931
|
+
entitiesDeleted: number;
|
|
1932
|
+
}
|
|
1819
1933
|
/** Overall result of the generation process */
|
|
1820
1934
|
interface GenerationResult {
|
|
1821
1935
|
/** Per-entity results */
|
|
@@ -1826,6 +1940,8 @@ interface GenerationResult {
|
|
|
1826
1940
|
totalWarnings: number;
|
|
1827
1941
|
/** Duration in milliseconds */
|
|
1828
1942
|
durationMs: number;
|
|
1943
|
+
/** Cache statistics (present when useCache was enabled) */
|
|
1944
|
+
cacheStats?: CacheStats;
|
|
1829
1945
|
}
|
|
1830
1946
|
|
|
1831
1947
|
/**
|
|
@@ -1870,9 +1986,24 @@ declare class TypeGenerationOrchestrator {
|
|
|
1870
1986
|
signal?: AbortSignal;
|
|
1871
1987
|
}): Promise<GenerationResult>;
|
|
1872
1988
|
/**
|
|
1873
|
-
*
|
|
1989
|
+
* Resolve the cache: load existing cache, detect changes, determine which
|
|
1990
|
+
* entities need to be fetched vs. can be served from cache.
|
|
1991
|
+
*
|
|
1992
|
+
* On any failure (corrupt cache, expired stamp), falls back to full refresh.
|
|
1993
|
+
*/
|
|
1994
|
+
private resolveCache;
|
|
1995
|
+
/**
|
|
1996
|
+
* Update the metadata cache after a successful generation run.
|
|
1997
|
+
*/
|
|
1998
|
+
private updateCache;
|
|
1999
|
+
/**
|
|
2000
|
+
* Generate all output files for a single entity from its metadata.
|
|
2001
|
+
*/
|
|
2002
|
+
private generateEntityFiles;
|
|
2003
|
+
/**
|
|
2004
|
+
* Generate Custom API Action/Function executor files.
|
|
1874
2005
|
*/
|
|
1875
|
-
private
|
|
2006
|
+
private generateActions;
|
|
1876
2007
|
/**
|
|
1877
2008
|
* Extract picklist attributes with their OptionSet metadata.
|
|
1878
2009
|
* Maps the raw EntityTypeInfo data to the format expected by the OptionSet generator.
|
|
@@ -1880,4 +2011,4 @@ declare class TypeGenerationOrchestrator {
|
|
|
1880
2011
|
private getPicklistAttributes;
|
|
1881
2012
|
}
|
|
1882
2013
|
|
|
1883
|
-
export { type ActionGeneratorOptions, ApiRequestError, type AttributeMetadata, type AuthConfig, type AuthMethod, AuthenticationError, BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, type ClientCredentialsAuth, ClientState, ClientType, ConfigError, ConsoleLogSink, type CustomApiTypeInfo, DEFAULT_LABEL_CONFIG, DataverseHttpClient, type DateTimeAttributeMetadata, type DecimalAttributeMetadata, type DeviceCodeAuth, DisplayState, type EntityFieldsGeneratorOptions, type EntityGenerationResult, type EntityGeneratorOptions, type EntityMetadata, type EntityTypeInfo, ErrorCode, FastXmlParser, type FormControl, type FormGeneratorOptions, FormNotificationLevel, type FormSection, type FormTab, type GenerateConfig, type GeneratedFile, GenerationError, type GenerationResult, type GroupedCustomApis, type HttpClientOptions, type IntegerAttributeMetadata, type InteractiveAuth, JsonLogSink, type Label, type LabelConfig, type LocalizedLabel, type LogEntry, LogLevel, type LogSink, Logger, type LookupAttributeMetadata, type ManyToManyRelationshipMetadata, MetadataCache, MetadataClient, MetadataError, type MoneyAttributeMetadata, type OneToManyRelationshipMetadata, OperationType, type OptionMetadata, type OptionSetGeneratorOptions, type OptionSetMetadata, type ParameterMeta, type ParameterMetaMap, type ParsedForm, type PicklistAttributeMetadata, RequiredLevel, SaveMode, SilentLogSink, type SolutionComponent, type StateAttributeMetadata, type StatusAttributeMetadata, type StringAttributeMetadata, StructuralProperty, SubmitMode, type SystemFormMetadata, TypeGenerationOrchestrator, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, type XmlElement, type XmlParser, XrmForgeError, configureLogging, createBoundAction, createBoundFunction, createCredential, createLogger, createUnboundAction, createUnboundFunction, defaultXmlParser, disambiguateEnumMembers, executeMultiple, executeRequest, extractControlFields, getJSDocLabel as formatDualLabel, generateActionDeclarations, generateActionModule, generateActivityPartyInterface, generateEntityFieldsEnum, generateEntityForms, generateEntityInterface, generateEntityNavigationProperties, generateEntityOptionSets, generateEnumMembers, generateFormInterface, generateOptionSetEnum, getEntityPropertyType, getFormAttributeType, getFormControlType, getFormMockValueType, getJSDocLabel, getLabelLanguagesParam, getPrimaryLabel, getSecondaryLabel, groupCustomApis, isLookupType, isPartyListType, isRateLimitError, isXrmForgeError, labelToIdentifier, parseForm, parseFormattedValue, parseLookup, parseLookups, select, selectExpand, shouldIncludeInEntityInterface, toLookupValueProperty, toPascalCase, toSafeIdentifier, withProgress };
|
|
2014
|
+
export { type ActionGeneratorOptions, ApiRequestError, type AttributeMetadata, type AuthConfig, type AuthMethod, AuthenticationError, BindingType, type BoundActionExecutor, type BoundActionWithParamsExecutor, type BoundFunctionExecutor, type CacheStats, type ChangeDetectionResult, ChangeDetector, type ClientCredentialsAuth, ClientState, ClientType, ConfigError, ConsoleLogSink, type CustomApiTypeInfo, DEFAULT_LABEL_CONFIG, DataverseHttpClient, type DateTimeAttributeMetadata, type DecimalAttributeMetadata, type DeviceCodeAuth, DisplayState, type EntityFieldsGeneratorOptions, type EntityGenerationResult, type EntityGeneratorOptions, type EntityMetadata, type EntityNamesGeneratorOptions, type EntityTypeInfo, ErrorCode, FastXmlParser, type FormControl, type FormGeneratorOptions, FormNotificationLevel, type FormSection, type FormTab, type GenerateConfig, type GeneratedFile, GenerationError, type GenerationResult, type GroupedCustomApis, type HttpClientOptions, type IntegerAttributeMetadata, type InteractiveAuth, JsonLogSink, type Label, type LabelConfig, type LocalizedLabel, type LogEntry, LogLevel, type LogSink, Logger, type LookupAttributeMetadata, type ManyToManyRelationshipMetadata, MetadataCache, MetadataClient, MetadataError, type MoneyAttributeMetadata, type OneToManyRelationshipMetadata, OperationType, type OptionMetadata, type OptionSetGeneratorOptions, type OptionSetMetadata, type ParameterMeta, type ParameterMetaMap, type ParsedForm, type PicklistAttributeMetadata, RequiredLevel, SaveMode, SilentLogSink, type SolutionComponent, type StateAttributeMetadata, type StatusAttributeMetadata, type StringAttributeMetadata, StructuralProperty, SubmitMode, type SystemFormMetadata, TypeGenerationOrchestrator, type UnboundActionExecutor, type UnboundActionWithParamsExecutor, type UnboundFunctionExecutor, type XmlElement, type XmlParser, XrmForgeError, configureLogging, createBoundAction, createBoundFunction, createCredential, createLogger, createUnboundAction, createUnboundFunction, defaultXmlParser, disambiguateEnumMembers, executeMultiple, executeRequest, extractControlFields, getJSDocLabel as formatDualLabel, generateActionDeclarations, generateActionModule, generateActivityPartyInterface, generateEntityFieldsEnum, generateEntityForms, generateEntityInterface, generateEntityNamesEnum, generateEntityNavigationProperties, generateEntityOptionSets, generateEnumMembers, generateFormInterface, generateOptionSetEnum, getEntityPropertyType, getFormAttributeType, getFormControlType, getFormMockValueType, getJSDocLabel, getLabelLanguagesParam, getPrimaryLabel, getSecondaryLabel, groupCustomApis, isLookupType, isPartyListType, isRateLimitError, isXrmForgeError, labelToIdentifier, parseForm, parseFormattedValue, parseLookup, parseLookups, select, selectExpand, shouldIncludeInEntityInterface, toLookupValueProperty, toPascalCase, toSafeIdentifier, withProgress };
|