@xrmforge/typegen 0.8.0 → 0.8.2

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.js CHANGED
@@ -2013,25 +2013,37 @@ function generateFormInterface(form, entityLogicalName, attributeMap, options =
2013
2013
  }
2014
2014
  const lines = [];
2015
2015
  lines.push(`/** Valid field names for the "${form.name}" form */`);
2016
- lines.push(`export type ${fieldsTypeName} =`);
2017
- for (let i = 0; i < fields.length; i++) {
2018
- const separator = i === fields.length - 1 ? ";" : "";
2019
- lines.push(` | "${fields[i].logicalName}"${separator}`);
2016
+ if (fields.length === 0) {
2017
+ lines.push(`export type ${fieldsTypeName} = never;`);
2018
+ } else {
2019
+ lines.push(`export type ${fieldsTypeName} =`);
2020
+ for (let i = 0; i < fields.length; i++) {
2021
+ const separator = i === fields.length - 1 ? ";" : "";
2022
+ lines.push(` | "${fields[i].logicalName}"${separator}`);
2023
+ }
2020
2024
  }
2021
2025
  lines.push("");
2022
2026
  lines.push(`/** Attribute type map for "${form.name}" */`);
2023
- lines.push(`export type ${attrMapName} = {`);
2024
- for (const field of fields) {
2025
- lines.push(` ${field.logicalName}: ${field.formAttributeType};`);
2027
+ if (fields.length === 0) {
2028
+ lines.push(`export type ${attrMapName} = Record<string, never>;`);
2029
+ } else {
2030
+ lines.push(`export type ${attrMapName} = {`);
2031
+ for (const field of fields) {
2032
+ lines.push(` ${field.logicalName}: ${field.formAttributeType};`);
2033
+ }
2034
+ lines.push("};");
2026
2035
  }
2027
- lines.push("};");
2028
2036
  lines.push("");
2029
2037
  lines.push(`/** Control type map for "${form.name}" */`);
2030
- lines.push(`export type ${ctrlMapName} = {`);
2031
- for (const field of fields) {
2032
- lines.push(` ${field.logicalName}: ${field.formControlType};`);
2038
+ if (fields.length === 0) {
2039
+ lines.push(`export type ${ctrlMapName} = Record<string, never>;`);
2040
+ } else {
2041
+ lines.push(`export type ${ctrlMapName} = {`);
2042
+ for (const field of fields) {
2043
+ lines.push(` ${field.logicalName}: ${field.formControlType};`);
2044
+ }
2045
+ lines.push("};");
2033
2046
  }
2034
- lines.push("};");
2035
2047
  lines.push("");
2036
2048
  lines.push(`/** Field constants for "${form.name}" (compile-time only, zero runtime) */`);
2037
2049
  lines.push(`export const enum ${fieldsTypeName}Enum {`);
@@ -2325,281 +2337,6 @@ function generateEntityNamesEnum(entityNames, _options = {}) {
2325
2337
  return lines.join("\n");
2326
2338
  }
2327
2339
 
2328
- // src/generators/webapi-helpers.ts
2329
- function select(...fields) {
2330
- if (fields.length === 0) return "";
2331
- return `?$select=${fields.join(",")}`;
2332
- }
2333
- function parseLookup(response, navigationProperty) {
2334
- const key = `_${navigationProperty}_value`;
2335
- const id = response[key];
2336
- if (!id) return null;
2337
- return {
2338
- id,
2339
- name: response[`${key}@OData.Community.Display.V1.FormattedValue`] ?? "",
2340
- entityType: response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? ""
2341
- };
2342
- }
2343
- function parseLookups(response, navigationProperties) {
2344
- const result = {};
2345
- for (const prop of navigationProperties) {
2346
- result[prop] = parseLookup(response, prop);
2347
- }
2348
- return result;
2349
- }
2350
- function parseFormattedValue(response, fieldName) {
2351
- return response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] ?? null;
2352
- }
2353
- function selectExpand(fields, expand) {
2354
- const parts = [];
2355
- if (fields.length > 0) parts.push(`$select=${fields.join(",")}`);
2356
- if (expand) parts.push(`$expand=${expand}`);
2357
- return parts.length > 0 ? `?${parts.join("&")}` : "";
2358
- }
2359
-
2360
- // src/generators/xrm-constants.ts
2361
- var DisplayState = /* @__PURE__ */ ((DisplayState2) => {
2362
- DisplayState2["Expanded"] = "expanded";
2363
- DisplayState2["Collapsed"] = "collapsed";
2364
- return DisplayState2;
2365
- })(DisplayState || {});
2366
- var FormNotificationLevel = /* @__PURE__ */ ((FormNotificationLevel2) => {
2367
- FormNotificationLevel2["Error"] = "ERROR";
2368
- FormNotificationLevel2["Warning"] = "WARNING";
2369
- FormNotificationLevel2["Info"] = "INFO";
2370
- return FormNotificationLevel2;
2371
- })(FormNotificationLevel || {});
2372
- var RequiredLevel = /* @__PURE__ */ ((RequiredLevel2) => {
2373
- RequiredLevel2["None"] = "none";
2374
- RequiredLevel2["Required"] = "required";
2375
- RequiredLevel2["Recommended"] = "recommended";
2376
- return RequiredLevel2;
2377
- })(RequiredLevel || {});
2378
- var SubmitMode = /* @__PURE__ */ ((SubmitMode2) => {
2379
- SubmitMode2["Always"] = "always";
2380
- SubmitMode2["Never"] = "never";
2381
- SubmitMode2["Dirty"] = "dirty";
2382
- return SubmitMode2;
2383
- })(SubmitMode || {});
2384
- var SaveMode = /* @__PURE__ */ ((SaveMode2) => {
2385
- SaveMode2[SaveMode2["Save"] = 1] = "Save";
2386
- SaveMode2[SaveMode2["SaveAndClose"] = 2] = "SaveAndClose";
2387
- SaveMode2[SaveMode2["Deactivate"] = 5] = "Deactivate";
2388
- SaveMode2[SaveMode2["Reactivate"] = 6] = "Reactivate";
2389
- SaveMode2[SaveMode2["Send"] = 7] = "Send";
2390
- SaveMode2[SaveMode2["Disqualify"] = 15] = "Disqualify";
2391
- SaveMode2[SaveMode2["Qualify"] = 16] = "Qualify";
2392
- SaveMode2[SaveMode2["Assign"] = 47] = "Assign";
2393
- SaveMode2[SaveMode2["SaveAsCompleted"] = 58] = "SaveAsCompleted";
2394
- SaveMode2[SaveMode2["SaveAndNew"] = 59] = "SaveAndNew";
2395
- SaveMode2[SaveMode2["AutoSave"] = 70] = "AutoSave";
2396
- return SaveMode2;
2397
- })(SaveMode || {});
2398
- var ClientType = /* @__PURE__ */ ((ClientType2) => {
2399
- ClientType2["Web"] = "Web";
2400
- ClientType2["Outlook"] = "Outlook";
2401
- ClientType2["Mobile"] = "Mobile";
2402
- return ClientType2;
2403
- })(ClientType || {});
2404
- var ClientState = /* @__PURE__ */ ((ClientState2) => {
2405
- ClientState2["Online"] = "Online";
2406
- ClientState2["Offline"] = "Offline";
2407
- return ClientState2;
2408
- })(ClientState || {});
2409
- var OperationType = /* @__PURE__ */ ((OperationType2) => {
2410
- OperationType2[OperationType2["Action"] = 0] = "Action";
2411
- OperationType2[OperationType2["Function"] = 1] = "Function";
2412
- OperationType2[OperationType2["CRUD"] = 2] = "CRUD";
2413
- return OperationType2;
2414
- })(OperationType || {});
2415
- var StructuralProperty = /* @__PURE__ */ ((StructuralProperty2) => {
2416
- StructuralProperty2[StructuralProperty2["Unknown"] = 0] = "Unknown";
2417
- StructuralProperty2[StructuralProperty2["PrimitiveType"] = 1] = "PrimitiveType";
2418
- StructuralProperty2[StructuralProperty2["ComplexType"] = 2] = "ComplexType";
2419
- StructuralProperty2[StructuralProperty2["EnumerationType"] = 3] = "EnumerationType";
2420
- StructuralProperty2[StructuralProperty2["Collection"] = 4] = "Collection";
2421
- StructuralProperty2[StructuralProperty2["EntityType"] = 5] = "EntityType";
2422
- return StructuralProperty2;
2423
- })(StructuralProperty || {});
2424
- var BindingType = /* @__PURE__ */ ((BindingType2) => {
2425
- BindingType2[BindingType2["Global"] = 0] = "Global";
2426
- BindingType2[BindingType2["Entity"] = 1] = "Entity";
2427
- BindingType2[BindingType2["EntityCollection"] = 2] = "EntityCollection";
2428
- return BindingType2;
2429
- })(BindingType || {});
2430
-
2431
- // src/generators/action-runtime.ts
2432
- function executeRequest(request) {
2433
- return Xrm.WebApi.online.execute(request);
2434
- }
2435
- function executeMultiple(requests) {
2436
- return Xrm.WebApi.online.executeMultiple(requests);
2437
- }
2438
- function cleanRecordId(id) {
2439
- return id.replace(/[{}]/g, "");
2440
- }
2441
- function buildBoundRequest(operationName, entityLogicalName, operationType, recordId, paramMeta, params) {
2442
- const parameterTypes = {
2443
- entity: {
2444
- typeName: `mscrm.${entityLogicalName}`,
2445
- structuralProperty: 5 /* EntityType */
2446
- }
2447
- };
2448
- if (paramMeta) {
2449
- for (const [key, meta] of Object.entries(paramMeta)) {
2450
- parameterTypes[key] = meta;
2451
- }
2452
- }
2453
- const request = {
2454
- getMetadata: () => ({
2455
- boundParameter: "entity",
2456
- parameterTypes,
2457
- operationName,
2458
- operationType
2459
- }),
2460
- entity: {
2461
- id: cleanRecordId(recordId),
2462
- entityType: entityLogicalName
2463
- }
2464
- };
2465
- if (params) {
2466
- for (const [key, value] of Object.entries(params)) {
2467
- request[key] = value;
2468
- }
2469
- }
2470
- return request;
2471
- }
2472
- function buildUnboundRequest(operationName, operationType, paramMeta, params) {
2473
- const parameterTypes = {};
2474
- if (paramMeta) {
2475
- for (const [key, meta] of Object.entries(paramMeta)) {
2476
- parameterTypes[key] = meta;
2477
- }
2478
- }
2479
- const request = {
2480
- getMetadata: () => ({
2481
- boundParameter: null,
2482
- parameterTypes,
2483
- operationName,
2484
- operationType
2485
- })
2486
- };
2487
- if (params) {
2488
- for (const [key, value] of Object.entries(params)) {
2489
- request[key] = value;
2490
- }
2491
- }
2492
- return request;
2493
- }
2494
- function createBoundAction(operationName, entityLogicalName, paramMeta) {
2495
- return {
2496
- execute(recordId, params) {
2497
- const req = buildBoundRequest(
2498
- operationName,
2499
- entityLogicalName,
2500
- 0 /* Action */,
2501
- recordId,
2502
- paramMeta,
2503
- params
2504
- );
2505
- return executeRequest(req);
2506
- },
2507
- request(recordId, params) {
2508
- return buildBoundRequest(
2509
- operationName,
2510
- entityLogicalName,
2511
- 0 /* Action */,
2512
- recordId,
2513
- paramMeta,
2514
- params
2515
- );
2516
- }
2517
- };
2518
- }
2519
- function createUnboundAction(operationName, paramMeta) {
2520
- return {
2521
- async execute(params) {
2522
- const req = buildUnboundRequest(
2523
- operationName,
2524
- 0 /* Action */,
2525
- paramMeta,
2526
- params
2527
- );
2528
- const response = await executeRequest(req);
2529
- if (!response.ok) {
2530
- const errorText = await response.text();
2531
- throw new Error(errorText);
2532
- }
2533
- if (response.status !== 204) {
2534
- return response.json();
2535
- }
2536
- return response;
2537
- },
2538
- request(params) {
2539
- return buildUnboundRequest(
2540
- operationName,
2541
- 0 /* Action */,
2542
- paramMeta,
2543
- params
2544
- );
2545
- }
2546
- };
2547
- }
2548
- function createUnboundFunction(operationName) {
2549
- return {
2550
- async execute() {
2551
- const req = buildUnboundRequest(operationName, 1 /* Function */);
2552
- const response = await executeRequest(req);
2553
- if (!response.ok) {
2554
- const errorText = await response.text();
2555
- throw new Error(errorText);
2556
- }
2557
- return response.json();
2558
- },
2559
- request() {
2560
- return buildUnboundRequest(operationName, 1 /* Function */);
2561
- }
2562
- };
2563
- }
2564
- function createBoundFunction(operationName, entityLogicalName) {
2565
- return {
2566
- async execute(recordId) {
2567
- const req = buildBoundRequest(
2568
- operationName,
2569
- entityLogicalName,
2570
- 1 /* Function */,
2571
- recordId
2572
- );
2573
- const response = await executeRequest(req);
2574
- if (!response.ok) {
2575
- const errorText = await response.text();
2576
- throw new Error(errorText);
2577
- }
2578
- return response.json();
2579
- },
2580
- request(recordId) {
2581
- return buildBoundRequest(
2582
- operationName,
2583
- entityLogicalName,
2584
- 1 /* Function */,
2585
- recordId
2586
- );
2587
- }
2588
- };
2589
- }
2590
- async function withProgress(message, operation) {
2591
- Xrm.Utility.showProgressIndicator(message);
2592
- try {
2593
- return await operation();
2594
- } catch (error) {
2595
- const msg = error instanceof Error ? error.message : String(error);
2596
- Xrm.Navigation.openErrorDialog({ message: msg });
2597
- throw error;
2598
- } finally {
2599
- Xrm.Utility.closeProgressIndicator();
2600
- }
2601
- }
2602
-
2603
2340
  // src/metadata/custom-api-types.ts
2604
2341
  function mapCustomApiParameterType(type, entityName) {
2605
2342
  switch (type) {
@@ -2738,22 +2475,29 @@ function generateActionModule(apis, isFunction, options = {}) {
2738
2475
  lines.push(generateResultInterface(name, apiInfo.responseProperties));
2739
2476
  lines.push("");
2740
2477
  }
2478
+ const typeArgs = buildTypeArgs(name, hasParams, hasResult);
2741
2479
  if (apiInfo.api.bindingtype === 0 /* Global */) {
2742
2480
  if (isFunction) {
2743
- lines.push(`export const ${name} = createUnboundFunction('${apiInfo.api.uniquename}');`);
2481
+ const funcTypeArg = hasResult ? `<${name}Result>` : "<unknown>";
2482
+ lines.push(`export const ${name} = createUnboundFunction${funcTypeArg}('${apiInfo.api.uniquename}');`);
2744
2483
  } else if (hasParams) {
2745
2484
  const paramMeta = generateParameterMetaMap(apiInfo.requestParameters);
2746
- lines.push(`export const ${name} = createUnboundAction('${apiInfo.api.uniquename}', ${paramMeta});`);
2485
+ lines.push(`export const ${name} = createUnboundAction${typeArgs}('${apiInfo.api.uniquename}', ${paramMeta});`);
2486
+ } else if (hasResult) {
2487
+ lines.push(`export const ${name} = createUnboundAction<${name}Result>('${apiInfo.api.uniquename}');`);
2747
2488
  } else {
2748
2489
  lines.push(`export const ${name} = createUnboundAction('${apiInfo.api.uniquename}');`);
2749
2490
  }
2750
2491
  } else {
2751
2492
  const entity = apiInfo.api.boundentitylogicalname;
2752
2493
  if (isFunction) {
2753
- lines.push(`export const ${name} = createBoundFunction('${apiInfo.api.uniquename}', '${entity}');`);
2494
+ const funcTypeArg = hasResult ? `<${name}Result>` : "<unknown>";
2495
+ lines.push(`export const ${name} = createBoundFunction${funcTypeArg}('${apiInfo.api.uniquename}', '${entity}');`);
2754
2496
  } else if (hasParams) {
2755
2497
  const paramMeta = generateParameterMetaMap(apiInfo.requestParameters);
2756
- lines.push(`export const ${name} = createBoundAction('${apiInfo.api.uniquename}', '${entity}', ${paramMeta});`);
2498
+ lines.push(`export const ${name} = createBoundAction${typeArgs}('${apiInfo.api.uniquename}', '${entity}', ${paramMeta});`);
2499
+ } else if (hasResult) {
2500
+ lines.push(`export const ${name} = createBoundAction<${name}Result>('${apiInfo.api.uniquename}', '${entity}');`);
2757
2501
  } else {
2758
2502
  lines.push(`export const ${name} = createBoundAction('${apiInfo.api.uniquename}', '${entity}');`);
2759
2503
  }
@@ -2762,6 +2506,18 @@ function generateActionModule(apis, isFunction, options = {}) {
2762
2506
  }
2763
2507
  return lines.join("\n");
2764
2508
  }
2509
+ function buildTypeArgs(name, hasParams, hasResult) {
2510
+ if (hasParams && hasResult) {
2511
+ return `<${name}Params, ${name}Result>`;
2512
+ }
2513
+ if (hasParams) {
2514
+ return `<${name}Params>`;
2515
+ }
2516
+ if (hasResult) {
2517
+ return `<${name}Result>`;
2518
+ }
2519
+ return "";
2520
+ }
2765
2521
  function generateParameterMetaMap(params) {
2766
2522
  const entries = [];
2767
2523
  for (const param of params) {
@@ -2867,9 +2623,9 @@ function generateBarrelIndex(files) {
2867
2623
  lines.push("");
2868
2624
  }
2869
2625
  if (optionsets.length > 0) {
2870
- lines.push("// OptionSet Enums");
2626
+ lines.push("// OptionSet Enums - import directly from individual files to avoid name conflicts:");
2871
2627
  for (const f of optionsets) {
2872
- lines.push(`export * from '${toImportSpecifier(f.relativePath)}';`);
2628
+ lines.push(`// import { ... } from '${toImportSpecifier(f.relativePath)}';`);
2873
2629
  }
2874
2630
  lines.push("");
2875
2631
  }
@@ -2881,9 +2637,9 @@ function generateBarrelIndex(files) {
2881
2637
  lines.push("");
2882
2638
  }
2883
2639
  if (fields.length > 0) {
2884
- lines.push("// Entity Fields & Navigation Properties");
2640
+ lines.push("// Entity Fields & Navigation Properties - import directly from individual files to avoid name conflicts:");
2885
2641
  for (const f of fields) {
2886
- lines.push(`export * from '${toImportSpecifier(f.relativePath)}';`);
2642
+ lines.push(`// import { ... } from '${toImportSpecifier(f.relativePath)}';`);
2887
2643
  }
2888
2644
  lines.push("");
2889
2645
  }
@@ -3007,6 +2763,19 @@ var TypeGenerationOrchestrator = class {
3007
2763
  }
3008
2764
  }
3009
2765
  }
2766
+ if (this.config.generateEntities) {
2767
+ const hasPartyList = Object.values(cachedEntityInfos).some(
2768
+ (info) => info.attributes.some((a) => isPartyListType(a.AttributeType))
2769
+ );
2770
+ if (hasPartyList) {
2771
+ const activityPartyContent = generateActivityPartyInterface();
2772
+ allFiles.push({
2773
+ relativePath: "entities/_activity-party.ts",
2774
+ content: addGeneratedHeader(activityPartyContent),
2775
+ type: "entity"
2776
+ });
2777
+ }
2778
+ }
3010
2779
  this.logger.info(`Generating types for ${this.config.entities.length - failedEntities.size} entities`);
3011
2780
  for (const entityName of this.config.entities) {
3012
2781
  if (signal?.aborted) break;
@@ -3272,7 +3041,7 @@ ${navPropsContent}` : fieldsEnumContent;
3272
3041
  this.logger.info(`Filtered Custom APIs by prefix "${this.config.actionsFilter}": ${before} -> ${customApis.length}`);
3273
3042
  }
3274
3043
  if (customApis.length > 0) {
3275
- const importPath = "@xrmforge/typegen";
3044
+ const importPath = "@xrmforge/helpers";
3276
3045
  const grouped = groupCustomApis(customApis);
3277
3046
  for (const [key, apis] of grouped.actions) {
3278
3047
  const entityName = key === "global" ? void 0 : key;
@@ -3335,18 +3104,13 @@ ${module}`),
3335
3104
  export {
3336
3105
  ApiRequestError,
3337
3106
  AuthenticationError,
3338
- BindingType,
3339
3107
  ChangeDetector,
3340
- ClientState,
3341
- ClientType,
3342
3108
  ConfigError,
3343
3109
  ConsoleLogSink,
3344
3110
  DEFAULT_LABEL_CONFIG,
3345
3111
  DataverseHttpClient,
3346
- DisplayState,
3347
3112
  ErrorCode,
3348
3113
  FastXmlParser,
3349
- FormNotificationLevel,
3350
3114
  GenerationError,
3351
3115
  JsonLogSink,
3352
3116
  LogLevel,
@@ -3354,25 +3118,14 @@ export {
3354
3118
  MetadataCache,
3355
3119
  MetadataClient,
3356
3120
  MetadataError,
3357
- OperationType,
3358
- RequiredLevel,
3359
- SaveMode,
3360
3121
  SilentLogSink,
3361
- StructuralProperty,
3362
- SubmitMode,
3363
3122
  TypeGenerationOrchestrator,
3364
3123
  XrmForgeError,
3365
3124
  configureLogging,
3366
- createBoundAction,
3367
- createBoundFunction,
3368
3125
  createCredential,
3369
3126
  createLogger,
3370
- createUnboundAction,
3371
- createUnboundFunction,
3372
3127
  defaultXmlParser,
3373
3128
  disambiguateEnumMembers,
3374
- executeMultiple,
3375
- executeRequest,
3376
3129
  extractControlFields,
3377
3130
  getJSDocLabel as formatDualLabel,
3378
3131
  generateActionDeclarations,
@@ -3402,15 +3155,9 @@ export {
3402
3155
  isXrmForgeError,
3403
3156
  labelToIdentifier,
3404
3157
  parseForm,
3405
- parseFormattedValue,
3406
- parseLookup,
3407
- parseLookups,
3408
- select,
3409
- selectExpand,
3410
3158
  shouldIncludeInEntityInterface,
3411
3159
  toLookupValueProperty,
3412
3160
  toPascalCase,
3413
- toSafeIdentifier,
3414
- withProgress
3161
+ toSafeIdentifier
3415
3162
  };
3416
3163
  //# sourceMappingURL=index.js.map