@xrmforge/typegen 0.8.1 → 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.d.ts +3 -336
- package/dist/index.js +24 -302
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2337,281 +2337,6 @@ function generateEntityNamesEnum(entityNames, _options = {}) {
|
|
|
2337
2337
|
return lines.join("\n");
|
|
2338
2338
|
}
|
|
2339
2339
|
|
|
2340
|
-
// src/generators/webapi-helpers.ts
|
|
2341
|
-
function select(...fields) {
|
|
2342
|
-
if (fields.length === 0) return "";
|
|
2343
|
-
return `?$select=${fields.join(",")}`;
|
|
2344
|
-
}
|
|
2345
|
-
function parseLookup(response, navigationProperty) {
|
|
2346
|
-
const key = `_${navigationProperty}_value`;
|
|
2347
|
-
const id = response[key];
|
|
2348
|
-
if (!id) return null;
|
|
2349
|
-
return {
|
|
2350
|
-
id,
|
|
2351
|
-
name: response[`${key}@OData.Community.Display.V1.FormattedValue`] ?? "",
|
|
2352
|
-
entityType: response[`${key}@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? ""
|
|
2353
|
-
};
|
|
2354
|
-
}
|
|
2355
|
-
function parseLookups(response, navigationProperties) {
|
|
2356
|
-
const result = {};
|
|
2357
|
-
for (const prop of navigationProperties) {
|
|
2358
|
-
result[prop] = parseLookup(response, prop);
|
|
2359
|
-
}
|
|
2360
|
-
return result;
|
|
2361
|
-
}
|
|
2362
|
-
function parseFormattedValue(response, fieldName) {
|
|
2363
|
-
return response[`${fieldName}@OData.Community.Display.V1.FormattedValue`] ?? null;
|
|
2364
|
-
}
|
|
2365
|
-
function selectExpand(fields, expand) {
|
|
2366
|
-
const parts = [];
|
|
2367
|
-
if (fields.length > 0) parts.push(`$select=${fields.join(",")}`);
|
|
2368
|
-
if (expand) parts.push(`$expand=${expand}`);
|
|
2369
|
-
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
2370
|
-
}
|
|
2371
|
-
|
|
2372
|
-
// src/generators/xrm-constants.ts
|
|
2373
|
-
var DisplayState = /* @__PURE__ */ ((DisplayState2) => {
|
|
2374
|
-
DisplayState2["Expanded"] = "expanded";
|
|
2375
|
-
DisplayState2["Collapsed"] = "collapsed";
|
|
2376
|
-
return DisplayState2;
|
|
2377
|
-
})(DisplayState || {});
|
|
2378
|
-
var FormNotificationLevel = /* @__PURE__ */ ((FormNotificationLevel2) => {
|
|
2379
|
-
FormNotificationLevel2["Error"] = "ERROR";
|
|
2380
|
-
FormNotificationLevel2["Warning"] = "WARNING";
|
|
2381
|
-
FormNotificationLevel2["Info"] = "INFO";
|
|
2382
|
-
return FormNotificationLevel2;
|
|
2383
|
-
})(FormNotificationLevel || {});
|
|
2384
|
-
var RequiredLevel = /* @__PURE__ */ ((RequiredLevel2) => {
|
|
2385
|
-
RequiredLevel2["None"] = "none";
|
|
2386
|
-
RequiredLevel2["Required"] = "required";
|
|
2387
|
-
RequiredLevel2["Recommended"] = "recommended";
|
|
2388
|
-
return RequiredLevel2;
|
|
2389
|
-
})(RequiredLevel || {});
|
|
2390
|
-
var SubmitMode = /* @__PURE__ */ ((SubmitMode2) => {
|
|
2391
|
-
SubmitMode2["Always"] = "always";
|
|
2392
|
-
SubmitMode2["Never"] = "never";
|
|
2393
|
-
SubmitMode2["Dirty"] = "dirty";
|
|
2394
|
-
return SubmitMode2;
|
|
2395
|
-
})(SubmitMode || {});
|
|
2396
|
-
var SaveMode = /* @__PURE__ */ ((SaveMode2) => {
|
|
2397
|
-
SaveMode2[SaveMode2["Save"] = 1] = "Save";
|
|
2398
|
-
SaveMode2[SaveMode2["SaveAndClose"] = 2] = "SaveAndClose";
|
|
2399
|
-
SaveMode2[SaveMode2["Deactivate"] = 5] = "Deactivate";
|
|
2400
|
-
SaveMode2[SaveMode2["Reactivate"] = 6] = "Reactivate";
|
|
2401
|
-
SaveMode2[SaveMode2["Send"] = 7] = "Send";
|
|
2402
|
-
SaveMode2[SaveMode2["Disqualify"] = 15] = "Disqualify";
|
|
2403
|
-
SaveMode2[SaveMode2["Qualify"] = 16] = "Qualify";
|
|
2404
|
-
SaveMode2[SaveMode2["Assign"] = 47] = "Assign";
|
|
2405
|
-
SaveMode2[SaveMode2["SaveAsCompleted"] = 58] = "SaveAsCompleted";
|
|
2406
|
-
SaveMode2[SaveMode2["SaveAndNew"] = 59] = "SaveAndNew";
|
|
2407
|
-
SaveMode2[SaveMode2["AutoSave"] = 70] = "AutoSave";
|
|
2408
|
-
return SaveMode2;
|
|
2409
|
-
})(SaveMode || {});
|
|
2410
|
-
var ClientType = /* @__PURE__ */ ((ClientType2) => {
|
|
2411
|
-
ClientType2["Web"] = "Web";
|
|
2412
|
-
ClientType2["Outlook"] = "Outlook";
|
|
2413
|
-
ClientType2["Mobile"] = "Mobile";
|
|
2414
|
-
return ClientType2;
|
|
2415
|
-
})(ClientType || {});
|
|
2416
|
-
var ClientState = /* @__PURE__ */ ((ClientState2) => {
|
|
2417
|
-
ClientState2["Online"] = "Online";
|
|
2418
|
-
ClientState2["Offline"] = "Offline";
|
|
2419
|
-
return ClientState2;
|
|
2420
|
-
})(ClientState || {});
|
|
2421
|
-
var OperationType = /* @__PURE__ */ ((OperationType2) => {
|
|
2422
|
-
OperationType2[OperationType2["Action"] = 0] = "Action";
|
|
2423
|
-
OperationType2[OperationType2["Function"] = 1] = "Function";
|
|
2424
|
-
OperationType2[OperationType2["CRUD"] = 2] = "CRUD";
|
|
2425
|
-
return OperationType2;
|
|
2426
|
-
})(OperationType || {});
|
|
2427
|
-
var StructuralProperty = /* @__PURE__ */ ((StructuralProperty2) => {
|
|
2428
|
-
StructuralProperty2[StructuralProperty2["Unknown"] = 0] = "Unknown";
|
|
2429
|
-
StructuralProperty2[StructuralProperty2["PrimitiveType"] = 1] = "PrimitiveType";
|
|
2430
|
-
StructuralProperty2[StructuralProperty2["ComplexType"] = 2] = "ComplexType";
|
|
2431
|
-
StructuralProperty2[StructuralProperty2["EnumerationType"] = 3] = "EnumerationType";
|
|
2432
|
-
StructuralProperty2[StructuralProperty2["Collection"] = 4] = "Collection";
|
|
2433
|
-
StructuralProperty2[StructuralProperty2["EntityType"] = 5] = "EntityType";
|
|
2434
|
-
return StructuralProperty2;
|
|
2435
|
-
})(StructuralProperty || {});
|
|
2436
|
-
var BindingType = /* @__PURE__ */ ((BindingType2) => {
|
|
2437
|
-
BindingType2[BindingType2["Global"] = 0] = "Global";
|
|
2438
|
-
BindingType2[BindingType2["Entity"] = 1] = "Entity";
|
|
2439
|
-
BindingType2[BindingType2["EntityCollection"] = 2] = "EntityCollection";
|
|
2440
|
-
return BindingType2;
|
|
2441
|
-
})(BindingType || {});
|
|
2442
|
-
|
|
2443
|
-
// src/generators/action-runtime.ts
|
|
2444
|
-
function executeRequest(request) {
|
|
2445
|
-
return Xrm.WebApi.online.execute(request);
|
|
2446
|
-
}
|
|
2447
|
-
function executeMultiple(requests) {
|
|
2448
|
-
return Xrm.WebApi.online.executeMultiple(requests);
|
|
2449
|
-
}
|
|
2450
|
-
function cleanRecordId(id) {
|
|
2451
|
-
return id.replace(/[{}]/g, "");
|
|
2452
|
-
}
|
|
2453
|
-
function buildBoundRequest(operationName, entityLogicalName, operationType, recordId, paramMeta, params) {
|
|
2454
|
-
const parameterTypes = {
|
|
2455
|
-
entity: {
|
|
2456
|
-
typeName: `mscrm.${entityLogicalName}`,
|
|
2457
|
-
structuralProperty: 5 /* EntityType */
|
|
2458
|
-
}
|
|
2459
|
-
};
|
|
2460
|
-
if (paramMeta) {
|
|
2461
|
-
for (const [key, meta] of Object.entries(paramMeta)) {
|
|
2462
|
-
parameterTypes[key] = meta;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
const request = {
|
|
2466
|
-
getMetadata: () => ({
|
|
2467
|
-
boundParameter: "entity",
|
|
2468
|
-
parameterTypes,
|
|
2469
|
-
operationName,
|
|
2470
|
-
operationType
|
|
2471
|
-
}),
|
|
2472
|
-
entity: {
|
|
2473
|
-
id: cleanRecordId(recordId),
|
|
2474
|
-
entityType: entityLogicalName
|
|
2475
|
-
}
|
|
2476
|
-
};
|
|
2477
|
-
if (params) {
|
|
2478
|
-
for (const [key, value] of Object.entries(params)) {
|
|
2479
|
-
request[key] = value;
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2482
|
-
return request;
|
|
2483
|
-
}
|
|
2484
|
-
function buildUnboundRequest(operationName, operationType, paramMeta, params) {
|
|
2485
|
-
const parameterTypes = {};
|
|
2486
|
-
if (paramMeta) {
|
|
2487
|
-
for (const [key, meta] of Object.entries(paramMeta)) {
|
|
2488
|
-
parameterTypes[key] = meta;
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
const request = {
|
|
2492
|
-
getMetadata: () => ({
|
|
2493
|
-
boundParameter: null,
|
|
2494
|
-
parameterTypes,
|
|
2495
|
-
operationName,
|
|
2496
|
-
operationType
|
|
2497
|
-
})
|
|
2498
|
-
};
|
|
2499
|
-
if (params) {
|
|
2500
|
-
for (const [key, value] of Object.entries(params)) {
|
|
2501
|
-
request[key] = value;
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
return request;
|
|
2505
|
-
}
|
|
2506
|
-
function createBoundAction(operationName, entityLogicalName, paramMeta) {
|
|
2507
|
-
return {
|
|
2508
|
-
execute(recordId, params) {
|
|
2509
|
-
const req = buildBoundRequest(
|
|
2510
|
-
operationName,
|
|
2511
|
-
entityLogicalName,
|
|
2512
|
-
0 /* Action */,
|
|
2513
|
-
recordId,
|
|
2514
|
-
paramMeta,
|
|
2515
|
-
params
|
|
2516
|
-
);
|
|
2517
|
-
return executeRequest(req);
|
|
2518
|
-
},
|
|
2519
|
-
request(recordId, params) {
|
|
2520
|
-
return buildBoundRequest(
|
|
2521
|
-
operationName,
|
|
2522
|
-
entityLogicalName,
|
|
2523
|
-
0 /* Action */,
|
|
2524
|
-
recordId,
|
|
2525
|
-
paramMeta,
|
|
2526
|
-
params
|
|
2527
|
-
);
|
|
2528
|
-
}
|
|
2529
|
-
};
|
|
2530
|
-
}
|
|
2531
|
-
function createUnboundAction(operationName, paramMeta) {
|
|
2532
|
-
return {
|
|
2533
|
-
async execute(params) {
|
|
2534
|
-
const req = buildUnboundRequest(
|
|
2535
|
-
operationName,
|
|
2536
|
-
0 /* Action */,
|
|
2537
|
-
paramMeta,
|
|
2538
|
-
params
|
|
2539
|
-
);
|
|
2540
|
-
const response = await executeRequest(req);
|
|
2541
|
-
if (!response.ok) {
|
|
2542
|
-
const errorText = await response.text();
|
|
2543
|
-
throw new Error(errorText);
|
|
2544
|
-
}
|
|
2545
|
-
if (response.status !== 204) {
|
|
2546
|
-
return response.json();
|
|
2547
|
-
}
|
|
2548
|
-
return response;
|
|
2549
|
-
},
|
|
2550
|
-
request(params) {
|
|
2551
|
-
return buildUnboundRequest(
|
|
2552
|
-
operationName,
|
|
2553
|
-
0 /* Action */,
|
|
2554
|
-
paramMeta,
|
|
2555
|
-
params
|
|
2556
|
-
);
|
|
2557
|
-
}
|
|
2558
|
-
};
|
|
2559
|
-
}
|
|
2560
|
-
function createUnboundFunction(operationName) {
|
|
2561
|
-
return {
|
|
2562
|
-
async execute() {
|
|
2563
|
-
const req = buildUnboundRequest(operationName, 1 /* Function */);
|
|
2564
|
-
const response = await executeRequest(req);
|
|
2565
|
-
if (!response.ok) {
|
|
2566
|
-
const errorText = await response.text();
|
|
2567
|
-
throw new Error(errorText);
|
|
2568
|
-
}
|
|
2569
|
-
return response.json();
|
|
2570
|
-
},
|
|
2571
|
-
request() {
|
|
2572
|
-
return buildUnboundRequest(operationName, 1 /* Function */);
|
|
2573
|
-
}
|
|
2574
|
-
};
|
|
2575
|
-
}
|
|
2576
|
-
function createBoundFunction(operationName, entityLogicalName) {
|
|
2577
|
-
return {
|
|
2578
|
-
async execute(recordId) {
|
|
2579
|
-
const req = buildBoundRequest(
|
|
2580
|
-
operationName,
|
|
2581
|
-
entityLogicalName,
|
|
2582
|
-
1 /* Function */,
|
|
2583
|
-
recordId
|
|
2584
|
-
);
|
|
2585
|
-
const response = await executeRequest(req);
|
|
2586
|
-
if (!response.ok) {
|
|
2587
|
-
const errorText = await response.text();
|
|
2588
|
-
throw new Error(errorText);
|
|
2589
|
-
}
|
|
2590
|
-
return response.json();
|
|
2591
|
-
},
|
|
2592
|
-
request(recordId) {
|
|
2593
|
-
return buildBoundRequest(
|
|
2594
|
-
operationName,
|
|
2595
|
-
entityLogicalName,
|
|
2596
|
-
1 /* Function */,
|
|
2597
|
-
recordId
|
|
2598
|
-
);
|
|
2599
|
-
}
|
|
2600
|
-
};
|
|
2601
|
-
}
|
|
2602
|
-
async function withProgress(message, operation) {
|
|
2603
|
-
Xrm.Utility.showProgressIndicator(message);
|
|
2604
|
-
try {
|
|
2605
|
-
return await operation();
|
|
2606
|
-
} catch (error) {
|
|
2607
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
2608
|
-
Xrm.Navigation.openErrorDialog({ message: msg });
|
|
2609
|
-
throw error;
|
|
2610
|
-
} finally {
|
|
2611
|
-
Xrm.Utility.closeProgressIndicator();
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
|
|
2615
2340
|
// src/metadata/custom-api-types.ts
|
|
2616
2341
|
function mapCustomApiParameterType(type, entityName) {
|
|
2617
2342
|
switch (type) {
|
|
@@ -2750,22 +2475,29 @@ function generateActionModule(apis, isFunction, options = {}) {
|
|
|
2750
2475
|
lines.push(generateResultInterface(name, apiInfo.responseProperties));
|
|
2751
2476
|
lines.push("");
|
|
2752
2477
|
}
|
|
2478
|
+
const typeArgs = buildTypeArgs(name, hasParams, hasResult);
|
|
2753
2479
|
if (apiInfo.api.bindingtype === 0 /* Global */) {
|
|
2754
2480
|
if (isFunction) {
|
|
2755
|
-
|
|
2481
|
+
const funcTypeArg = hasResult ? `<${name}Result>` : "<unknown>";
|
|
2482
|
+
lines.push(`export const ${name} = createUnboundFunction${funcTypeArg}('${apiInfo.api.uniquename}');`);
|
|
2756
2483
|
} else if (hasParams) {
|
|
2757
2484
|
const paramMeta = generateParameterMetaMap(apiInfo.requestParameters);
|
|
2758
|
-
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}');`);
|
|
2759
2488
|
} else {
|
|
2760
2489
|
lines.push(`export const ${name} = createUnboundAction('${apiInfo.api.uniquename}');`);
|
|
2761
2490
|
}
|
|
2762
2491
|
} else {
|
|
2763
2492
|
const entity = apiInfo.api.boundentitylogicalname;
|
|
2764
2493
|
if (isFunction) {
|
|
2765
|
-
|
|
2494
|
+
const funcTypeArg = hasResult ? `<${name}Result>` : "<unknown>";
|
|
2495
|
+
lines.push(`export const ${name} = createBoundFunction${funcTypeArg}('${apiInfo.api.uniquename}', '${entity}');`);
|
|
2766
2496
|
} else if (hasParams) {
|
|
2767
2497
|
const paramMeta = generateParameterMetaMap(apiInfo.requestParameters);
|
|
2768
|
-
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}');`);
|
|
2769
2501
|
} else {
|
|
2770
2502
|
lines.push(`export const ${name} = createBoundAction('${apiInfo.api.uniquename}', '${entity}');`);
|
|
2771
2503
|
}
|
|
@@ -2774,6 +2506,18 @@ function generateActionModule(apis, isFunction, options = {}) {
|
|
|
2774
2506
|
}
|
|
2775
2507
|
return lines.join("\n");
|
|
2776
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
|
+
}
|
|
2777
2521
|
function generateParameterMetaMap(params) {
|
|
2778
2522
|
const entries = [];
|
|
2779
2523
|
for (const param of params) {
|
|
@@ -3360,18 +3104,13 @@ ${module}`),
|
|
|
3360
3104
|
export {
|
|
3361
3105
|
ApiRequestError,
|
|
3362
3106
|
AuthenticationError,
|
|
3363
|
-
BindingType,
|
|
3364
3107
|
ChangeDetector,
|
|
3365
|
-
ClientState,
|
|
3366
|
-
ClientType,
|
|
3367
3108
|
ConfigError,
|
|
3368
3109
|
ConsoleLogSink,
|
|
3369
3110
|
DEFAULT_LABEL_CONFIG,
|
|
3370
3111
|
DataverseHttpClient,
|
|
3371
|
-
DisplayState,
|
|
3372
3112
|
ErrorCode,
|
|
3373
3113
|
FastXmlParser,
|
|
3374
|
-
FormNotificationLevel,
|
|
3375
3114
|
GenerationError,
|
|
3376
3115
|
JsonLogSink,
|
|
3377
3116
|
LogLevel,
|
|
@@ -3379,25 +3118,14 @@ export {
|
|
|
3379
3118
|
MetadataCache,
|
|
3380
3119
|
MetadataClient,
|
|
3381
3120
|
MetadataError,
|
|
3382
|
-
OperationType,
|
|
3383
|
-
RequiredLevel,
|
|
3384
|
-
SaveMode,
|
|
3385
3121
|
SilentLogSink,
|
|
3386
|
-
StructuralProperty,
|
|
3387
|
-
SubmitMode,
|
|
3388
3122
|
TypeGenerationOrchestrator,
|
|
3389
3123
|
XrmForgeError,
|
|
3390
3124
|
configureLogging,
|
|
3391
|
-
createBoundAction,
|
|
3392
|
-
createBoundFunction,
|
|
3393
3125
|
createCredential,
|
|
3394
3126
|
createLogger,
|
|
3395
|
-
createUnboundAction,
|
|
3396
|
-
createUnboundFunction,
|
|
3397
3127
|
defaultXmlParser,
|
|
3398
3128
|
disambiguateEnumMembers,
|
|
3399
|
-
executeMultiple,
|
|
3400
|
-
executeRequest,
|
|
3401
3129
|
extractControlFields,
|
|
3402
3130
|
getJSDocLabel as formatDualLabel,
|
|
3403
3131
|
generateActionDeclarations,
|
|
@@ -3427,15 +3155,9 @@ export {
|
|
|
3427
3155
|
isXrmForgeError,
|
|
3428
3156
|
labelToIdentifier,
|
|
3429
3157
|
parseForm,
|
|
3430
|
-
parseFormattedValue,
|
|
3431
|
-
parseLookup,
|
|
3432
|
-
parseLookups,
|
|
3433
|
-
select,
|
|
3434
|
-
selectExpand,
|
|
3435
3158
|
shouldIncludeInEntityInterface,
|
|
3436
3159
|
toLookupValueProperty,
|
|
3437
3160
|
toPascalCase,
|
|
3438
|
-
toSafeIdentifier
|
|
3439
|
-
withProgress
|
|
3161
|
+
toSafeIdentifier
|
|
3440
3162
|
};
|
|
3441
3163
|
//# sourceMappingURL=index.js.map
|