@azure-rest/health-deidentification 1.0.0 → 1.1.0-alpha.20250930.3

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.
Files changed (96) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +35 -16
  3. package/dist/browser/deidentificationClient.js +13 -11
  4. package/dist/browser/deidentificationClient.js.map +1 -1
  5. package/dist/browser/isUnexpected.js +4 -5
  6. package/dist/browser/isUnexpected.js.map +1 -1
  7. package/dist/browser/models.d.ts +40 -4
  8. package/dist/browser/models.js.map +1 -1
  9. package/dist/browser/outputModels.d.ts +4 -2
  10. package/dist/browser/outputModels.js.map +1 -1
  11. package/dist/browser/paginateHelper.js +43 -73
  12. package/dist/browser/paginateHelper.js.map +1 -1
  13. package/dist/browser/pollingHelper.js +11 -8
  14. package/dist/browser/pollingHelper.js.map +1 -1
  15. package/dist/commonjs/deidentificationClient.js +13 -11
  16. package/dist/commonjs/deidentificationClient.js.map +1 -1
  17. package/dist/commonjs/isUnexpected.js +4 -5
  18. package/dist/commonjs/isUnexpected.js.map +1 -1
  19. package/dist/commonjs/models.d.ts +40 -4
  20. package/dist/commonjs/models.js.map +1 -1
  21. package/dist/commonjs/outputModels.d.ts +4 -2
  22. package/dist/commonjs/outputModels.js.map +1 -1
  23. package/dist/commonjs/paginateHelper.js +43 -73
  24. package/dist/commonjs/paginateHelper.js.map +1 -1
  25. package/dist/commonjs/pollingHelper.js +11 -8
  26. package/dist/commonjs/pollingHelper.js.map +1 -1
  27. package/dist/commonjs/tsdoc-metadata.json +11 -11
  28. package/dist/esm/deidentificationClient.js +13 -11
  29. package/dist/esm/deidentificationClient.js.map +1 -1
  30. package/dist/esm/isUnexpected.js +4 -5
  31. package/dist/esm/isUnexpected.js.map +1 -1
  32. package/dist/esm/models.d.ts +40 -4
  33. package/dist/esm/models.js.map +1 -1
  34. package/dist/esm/outputModels.d.ts +4 -2
  35. package/dist/esm/outputModels.js.map +1 -1
  36. package/dist/esm/paginateHelper.js +43 -73
  37. package/dist/esm/paginateHelper.js.map +1 -1
  38. package/dist/esm/pollingHelper.js +11 -8
  39. package/dist/esm/pollingHelper.js.map +1 -1
  40. package/dist/react-native/deidentificationClient.js +13 -11
  41. package/dist/react-native/deidentificationClient.js.map +1 -1
  42. package/dist/react-native/isUnexpected.js +4 -5
  43. package/dist/react-native/isUnexpected.js.map +1 -1
  44. package/dist/react-native/models.d.ts +40 -4
  45. package/dist/react-native/models.js.map +1 -1
  46. package/dist/react-native/outputModels.d.ts +4 -2
  47. package/dist/react-native/outputModels.js.map +1 -1
  48. package/dist/react-native/paginateHelper.js +43 -73
  49. package/dist/react-native/paginateHelper.js.map +1 -1
  50. package/dist/react-native/pollingHelper.js +11 -8
  51. package/dist/react-native/pollingHelper.js.map +1 -1
  52. package/package.json +42 -60
  53. package/dist/browser/clientDefinitions.d.ts.map +0 -1
  54. package/dist/browser/deidentificationClient.d.ts.map +0 -1
  55. package/dist/browser/index.d.ts.map +0 -1
  56. package/dist/browser/isUnexpected.d.ts.map +0 -1
  57. package/dist/browser/logger.d.ts.map +0 -1
  58. package/dist/browser/models.d.ts.map +0 -1
  59. package/dist/browser/outputModels.d.ts.map +0 -1
  60. package/dist/browser/paginateHelper.d.ts.map +0 -1
  61. package/dist/browser/parameters.d.ts.map +0 -1
  62. package/dist/browser/pollingHelper.d.ts.map +0 -1
  63. package/dist/browser/responses.d.ts.map +0 -1
  64. package/dist/commonjs/clientDefinitions.d.ts.map +0 -1
  65. package/dist/commonjs/deidentificationClient.d.ts.map +0 -1
  66. package/dist/commonjs/index.d.ts.map +0 -1
  67. package/dist/commonjs/isUnexpected.d.ts.map +0 -1
  68. package/dist/commonjs/logger.d.ts.map +0 -1
  69. package/dist/commonjs/models.d.ts.map +0 -1
  70. package/dist/commonjs/outputModels.d.ts.map +0 -1
  71. package/dist/commonjs/paginateHelper.d.ts.map +0 -1
  72. package/dist/commonjs/parameters.d.ts.map +0 -1
  73. package/dist/commonjs/pollingHelper.d.ts.map +0 -1
  74. package/dist/commonjs/responses.d.ts.map +0 -1
  75. package/dist/esm/clientDefinitions.d.ts.map +0 -1
  76. package/dist/esm/deidentificationClient.d.ts.map +0 -1
  77. package/dist/esm/index.d.ts.map +0 -1
  78. package/dist/esm/isUnexpected.d.ts.map +0 -1
  79. package/dist/esm/logger.d.ts.map +0 -1
  80. package/dist/esm/models.d.ts.map +0 -1
  81. package/dist/esm/outputModels.d.ts.map +0 -1
  82. package/dist/esm/paginateHelper.d.ts.map +0 -1
  83. package/dist/esm/parameters.d.ts.map +0 -1
  84. package/dist/esm/pollingHelper.d.ts.map +0 -1
  85. package/dist/esm/responses.d.ts.map +0 -1
  86. package/dist/react-native/clientDefinitions.d.ts.map +0 -1
  87. package/dist/react-native/deidentificationClient.d.ts.map +0 -1
  88. package/dist/react-native/index.d.ts.map +0 -1
  89. package/dist/react-native/isUnexpected.d.ts.map +0 -1
  90. package/dist/react-native/logger.d.ts.map +0 -1
  91. package/dist/react-native/models.d.ts.map +0 -1
  92. package/dist/react-native/outputModels.d.ts.map +0 -1
  93. package/dist/react-native/paginateHelper.d.ts.map +0 -1
  94. package/dist/react-native/parameters.d.ts.map +0 -1
  95. package/dist/react-native/pollingHelper.d.ts.map +0 -1
  96. package/dist/react-native/responses.d.ts.map +0 -1
@@ -3,7 +3,7 @@ export interface DeidentificationJob {
3
3
  /**
4
4
  * Operation to perform on the input documents.
5
5
  *
6
- * Possible values: "Redact", "Surrogate", "Tag"
6
+ * Possible values: "Redact", "Surrogate", "Tag", "SurrogateOnly"
7
7
  */
8
8
  operation?: DeidentificationOperationType;
9
9
  /** Storage location to perform the operation on. */
@@ -44,11 +44,13 @@ export interface TargetStorageLocation {
44
44
  export interface DeidentificationJobCustomizationOptions {
45
45
  /**
46
46
  * Format of the redacted output. Only valid when Operation is Redact.
47
- * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.
47
+ * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.
48
48
  */
49
49
  redactionFormat?: string;
50
50
  /** Locale in which the output surrogates are written. */
51
51
  surrogateLocale?: string;
52
+ /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */
53
+ inputLocale?: string;
52
54
  }
53
55
  /** Summary metrics of a job. */
54
56
  export interface DeidentificationJobSummary {
@@ -70,24 +72,58 @@ export interface DeidentificationContent {
70
72
  /**
71
73
  * Operation to perform on the input documents.
72
74
  *
73
- * Possible values: "Redact", "Surrogate", "Tag"
75
+ * Possible values: "Redact", "Surrogate", "Tag", "SurrogateOnly"
74
76
  */
75
77
  operation?: DeidentificationOperationType;
78
+ /** Grouped PHI entities with single encoding specification for SurrogateOnly operation. */
79
+ taggedEntities?: TaggedPhiEntities;
76
80
  /** Customization parameters to override default service behaviors. */
77
81
  customizations?: DeidentificationCustomizationOptions;
78
82
  }
83
+ /** Grouped PHI entities with shared encoding specification. */
84
+ export interface TaggedPhiEntities {
85
+ /**
86
+ * The encoding type used for all entities in this group.
87
+ *
88
+ * Possible values: "Utf8", "Utf16", "CodePoint"
89
+ */
90
+ encoding: TextEncodingType;
91
+ /** List of PHI entities using the specified encoding. */
92
+ entities: Array<SimplePhiEntity>;
93
+ }
94
+ /** Simple PHI entity with encoding-specific offset and length values. */
95
+ export interface SimplePhiEntity {
96
+ /**
97
+ * PHI Category of the entity.
98
+ *
99
+ * Possible values: "Unknown", "Account", "Age", "BioID", "City", "CountryOrRegion", "Date", "Device", "Doctor", "Email", "Fax", "HealthPlan", "Hospital", "IDNum", "IPAddress", "License", "LocationOther", "MedicalRecord", "Organization", "Patient", "Phone", "Profession", "SocialSecurity", "State", "Street", "Url", "Username", "Vehicle", "Zip"
100
+ */
101
+ category: PhiCategory;
102
+ /** Starting index of the location from within the input text using the group's encoding. */
103
+ offset: number;
104
+ /** Length of the input text using the group's encoding. */
105
+ length: number;
106
+ /** Text of the entity (optional). */
107
+ text?: string;
108
+ }
79
109
  /** Customizations options to override default service behaviors for synchronous usage. */
80
110
  export interface DeidentificationCustomizationOptions {
81
111
  /**
82
112
  * Format of the redacted output. Only valid when Operation is Redact.
83
- * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.
113
+ * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.
84
114
  */
85
115
  redactionFormat?: string;
86
116
  /** Locale in which the output surrogates are written. */
87
117
  surrogateLocale?: string;
118
+ /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */
119
+ inputLocale?: string;
88
120
  }
89
121
  /** Alias for DeidentificationOperationType */
90
122
  export type DeidentificationOperationType = string;
91
123
  /** Alias for OperationState */
92
124
  export type OperationState = string;
125
+ /** Alias for TextEncodingType */
126
+ export type TextEncodingType = string;
127
+ /** Alias for PhiCategory */
128
+ export type PhiCategory = string;
93
129
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** A job containing a batch of documents to de-identify. */\nexport interface DeidentificationJob {\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\"\n */\n operation?: DeidentificationOperationType;\n /** Storage location to perform the operation on. */\n sourceLocation: SourceStorageLocation;\n /** Target location to store output of operation. */\n targetLocation: TargetStorageLocation;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationJobCustomizationOptions;\n}\n\n/** Storage location. */\nexport interface SourceStorageLocation {\n /** URL to storage location. */\n location: string;\n /** Prefix to filter path by. */\n prefix: string;\n /** List of extensions to filter path by. */\n extensions?: string[];\n}\n\n/** Storage location. */\nexport interface TargetStorageLocation {\n /** URL to storage location. */\n location: string;\n /**\n * Replaces the input prefix of a file path with the output prefix, preserving the rest of the path structure.\n *\n * Example:\n * File full path: documents/user/note.txt\n * Input Prefix: \"documents/user/\"\n * Output Prefix: \"output_docs/\"\n *\n * Output file: \"output_docs/note.txt\"\n */\n prefix: string;\n /** When set to true during a job, the service will overwrite the output location if it already exists. */\n overwrite?: boolean;\n}\n\n/** Customizations options to override default service behaviors for job usage. */\nexport interface DeidentificationJobCustomizationOptions {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n}\n\n/** Summary metrics of a job. */\nexport interface DeidentificationJobSummary {\n /** Number of documents that have completed. */\n successful: number;\n /** Number of documents that have failed. */\n failed: number;\n /** Number of documents that have been canceled. */\n canceled: number;\n /** Number of documents total. */\n total: number;\n /** Number of bytes processed. */\n bytesProcessed: number;\n}\n\n/** Request body for de-identification operation. */\nexport interface DeidentificationContent {\n /** Input text to de-identify. */\n inputText: string;\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\"\n */\n operation?: DeidentificationOperationType;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationCustomizationOptions;\n}\n\n/** Customizations options to override default service behaviors for synchronous usage. */\nexport interface DeidentificationCustomizationOptions {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n}\n\n/** Alias for DeidentificationOperationType */\nexport type DeidentificationOperationType = string;\n/** Alias for OperationState */\nexport type OperationState = string;\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** A job containing a batch of documents to de-identify. */\nexport interface DeidentificationJob {\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\", \"SurrogateOnly\"\n */\n operation?: DeidentificationOperationType;\n /** Storage location to perform the operation on. */\n sourceLocation: SourceStorageLocation;\n /** Target location to store output of operation. */\n targetLocation: TargetStorageLocation;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationJobCustomizationOptions;\n}\n\n/** Storage location. */\nexport interface SourceStorageLocation {\n /** URL to storage location. */\n location: string;\n /** Prefix to filter path by. */\n prefix: string;\n /** List of extensions to filter path by. */\n extensions?: string[];\n}\n\n/** Storage location. */\nexport interface TargetStorageLocation {\n /** URL to storage location. */\n location: string;\n /**\n * Replaces the input prefix of a file path with the output prefix, preserving the rest of the path structure.\n *\n * Example:\n * File full path: documents/user/note.txt\n * Input Prefix: \"documents/user/\"\n * Output Prefix: \"output_docs/\"\n *\n * Output file: \"output_docs/note.txt\"\n */\n prefix: string;\n /** When set to true during a job, the service will overwrite the output location if it already exists. */\n overwrite?: boolean;\n}\n\n/** Customizations options to override default service behaviors for job usage. */\nexport interface DeidentificationJobCustomizationOptions {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */\n inputLocale?: string;\n}\n\n/** Summary metrics of a job. */\nexport interface DeidentificationJobSummary {\n /** Number of documents that have completed. */\n successful: number;\n /** Number of documents that have failed. */\n failed: number;\n /** Number of documents that have been canceled. */\n canceled: number;\n /** Number of documents total. */\n total: number;\n /** Number of bytes processed. */\n bytesProcessed: number;\n}\n\n/** Request body for de-identification operation. */\nexport interface DeidentificationContent {\n /** Input text to de-identify. */\n inputText: string;\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\", \"SurrogateOnly\"\n */\n operation?: DeidentificationOperationType;\n /** Grouped PHI entities with single encoding specification for SurrogateOnly operation. */\n taggedEntities?: TaggedPhiEntities;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationCustomizationOptions;\n}\n\n/** Grouped PHI entities with shared encoding specification. */\nexport interface TaggedPhiEntities {\n /**\n * The encoding type used for all entities in this group.\n *\n * Possible values: \"Utf8\", \"Utf16\", \"CodePoint\"\n */\n encoding: TextEncodingType;\n /** List of PHI entities using the specified encoding. */\n entities: Array<SimplePhiEntity>;\n}\n\n/** Simple PHI entity with encoding-specific offset and length values. */\nexport interface SimplePhiEntity {\n /**\n * PHI Category of the entity.\n *\n * Possible values: \"Unknown\", \"Account\", \"Age\", \"BioID\", \"City\", \"CountryOrRegion\", \"Date\", \"Device\", \"Doctor\", \"Email\", \"Fax\", \"HealthPlan\", \"Hospital\", \"IDNum\", \"IPAddress\", \"License\", \"LocationOther\", \"MedicalRecord\", \"Organization\", \"Patient\", \"Phone\", \"Profession\", \"SocialSecurity\", \"State\", \"Street\", \"Url\", \"Username\", \"Vehicle\", \"Zip\"\n */\n category: PhiCategory;\n /** Starting index of the location from within the input text using the group's encoding. */\n offset: number;\n /** Length of the input text using the group's encoding. */\n length: number;\n /** Text of the entity (optional). */\n text?: string;\n}\n\n/** Customizations options to override default service behaviors for synchronous usage. */\nexport interface DeidentificationCustomizationOptions {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */\n inputLocale?: string;\n}\n\n/** Alias for DeidentificationOperationType */\nexport type DeidentificationOperationType = string;\n/** Alias for OperationState */\nexport type OperationState = string;\n/** Alias for TextEncodingType */\nexport type TextEncodingType = string;\n/** Alias for PhiCategory */\nexport type PhiCategory = string;\n"]}
@@ -6,7 +6,7 @@ export interface DeidentificationJobOutput {
6
6
  /**
7
7
  * Operation to perform on the input documents.
8
8
  *
9
- * Possible values: "Redact", "Surrogate", "Tag"
9
+ * Possible values: "Redact", "Surrogate", "Tag", "SurrogateOnly"
10
10
  */
11
11
  operation?: DeidentificationOperationTypeOutput;
12
12
  /** Storage location to perform the operation on. */
@@ -69,11 +69,13 @@ export interface TargetStorageLocationOutput {
69
69
  export interface DeidentificationJobCustomizationOptionsOutput {
70
70
  /**
71
71
  * Format of the redacted output. Only valid when Operation is Redact.
72
- * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.
72
+ * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.
73
73
  */
74
74
  redactionFormat?: string;
75
75
  /** Locale in which the output surrogates are written. */
76
76
  surrogateLocale?: string;
77
+ /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */
78
+ inputLocale?: string;
77
79
  }
78
80
  /** Summary metrics of a job. */
79
81
  export interface DeidentificationJobSummaryOutput {
@@ -1 +1 @@
1
- {"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../src/outputModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ErrorModel } from \"@azure-rest/core-client\";\n\n/** A job containing a batch of documents to de-identify. */\nexport interface DeidentificationJobOutput {\n /** The name of a job. */\n readonly name: string;\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\"\n */\n operation?: DeidentificationOperationTypeOutput;\n /** Storage location to perform the operation on. */\n sourceLocation: SourceStorageLocationOutput;\n /** Target location to store output of operation. */\n targetLocation: TargetStorageLocationOutput;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationJobCustomizationOptionsOutput;\n /**\n * Current status of a job.\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Canceled\"\n */\n readonly status: OperationStateOutput;\n /** Error when job fails in it's entirety. */\n readonly error?: ErrorModel;\n /**\n * Date and time when the job was completed.\n *\n * If the job is canceled, this is the time when the job was canceled.\n *\n * If the job failed, this is the time when the job failed.\n */\n readonly lastUpdatedAt: string;\n /** Date and time when the job was created. */\n readonly createdAt: string;\n /** Date and time when the job was started. */\n readonly startedAt?: string;\n /** Summary of a job. Exists only when the job is completed. */\n readonly summary?: DeidentificationJobSummaryOutput;\n}\n\n/** Storage location. */\nexport interface SourceStorageLocationOutput {\n /** URL to storage location. */\n location: string;\n /** Prefix to filter path by. */\n prefix: string;\n /** List of extensions to filter path by. */\n extensions?: string[];\n}\n\n/** Storage location. */\nexport interface TargetStorageLocationOutput {\n /** URL to storage location. */\n location: string;\n /**\n * Replaces the input prefix of a file path with the output prefix, preserving the rest of the path structure.\n *\n * Example:\n * File full path: documents/user/note.txt\n * Input Prefix: \"documents/user/\"\n * Output Prefix: \"output_docs/\"\n *\n * Output file: \"output_docs/note.txt\"\n */\n prefix: string;\n /** When set to true during a job, the service will overwrite the output location if it already exists. */\n overwrite?: boolean;\n}\n\n/** Customizations options to override default service behaviors for job usage. */\nexport interface DeidentificationJobCustomizationOptionsOutput {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/en-us/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n}\n\n/** Summary metrics of a job. */\nexport interface DeidentificationJobSummaryOutput {\n /** Number of documents that have completed. */\n successful: number;\n /** Number of documents that have failed. */\n failed: number;\n /** Number of documents that have been canceled. */\n canceled: number;\n /** Number of documents total. */\n total: number;\n /** Number of bytes processed. */\n bytesProcessed: number;\n}\n\n/** Paged collection of DeidentificationJob items */\nexport interface PagedDeidentificationJobOutput {\n /** The DeidentificationJob items on this page */\n value: Array<DeidentificationJobOutput>;\n /** The link to the next page of items */\n nextLink?: string;\n}\n\n/** Paged collection of DeidentificationDocumentDetails items */\nexport interface PagedDeidentificationDocumentDetailsOutput {\n /** The DeidentificationDocumentDetails items on this page */\n value: Array<DeidentificationDocumentDetailsOutput>;\n /** The link to the next page of items */\n nextLink?: string;\n}\n\n/** Details of a single document in a job. */\nexport interface DeidentificationDocumentDetailsOutput {\n /** Id of the document details. */\n readonly id: string;\n /** Location for the input. */\n input: DeidentificationDocumentLocationOutput;\n /** Location for the output. */\n output?: DeidentificationDocumentLocationOutput;\n /**\n * Status of the document.\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Canceled\"\n */\n status: OperationStateOutput;\n /** Error when document fails. */\n error?: ErrorModel;\n}\n\n/** Location of a document. */\nexport interface DeidentificationDocumentLocationOutput {\n /** Location of document in storage. */\n location: string;\n /** The entity tag for this resource. */\n readonly etag: string;\n}\n\n/** Response body for de-identification operation. */\nexport interface DeidentificationResultOutput {\n /** Output text after de-identification. Not available for \"Tag\" operation. */\n outputText?: string;\n /** Result of the \"Tag\" operation. Only available for \"Tag\" Operation. */\n taggerResult?: PhiTaggerResultOutput;\n}\n\n/** Result of the \"Tag\" operation. */\nexport interface PhiTaggerResultOutput {\n /** List of entities detected in the input. */\n entities: Array<PhiEntityOutput>;\n}\n\n/** PHI Entity tag in the input. */\nexport interface PhiEntityOutput {\n /**\n * PHI Category of the entity.\n *\n * Possible values: \"Unknown\", \"Account\", \"Age\", \"BioID\", \"City\", \"CountryOrRegion\", \"Date\", \"Device\", \"Doctor\", \"Email\", \"Fax\", \"HealthPlan\", \"Hospital\", \"IDNum\", \"IPAddress\", \"License\", \"LocationOther\", \"MedicalRecord\", \"Organization\", \"Patient\", \"Phone\", \"Profession\", \"SocialSecurity\", \"State\", \"Street\", \"Url\", \"Username\", \"Vehicle\", \"Zip\"\n */\n category: PhiCategoryOutput;\n /** Starting index of the location from within the input text. */\n offset: StringIndexOutput;\n /** Length of the input text. */\n length: StringIndexOutput;\n /** Text of the entity. */\n text?: string;\n /** Confidence score of the category match. */\n confidenceScore?: number;\n}\n\n/** String index encoding model. */\nexport interface StringIndexOutput {\n /** The offset or length of the substring in UTF-8 encoding */\n utf8: number;\n /**\n * The offset or length of the substring in UTF-16 encoding.\n *\n * Primary encoding used by .NET, Java, and JavaScript.\n */\n utf16: number;\n /**\n * The offset or length of the substring in CodePoint encoding.\n *\n * Primary encoding used by Python.\n */\n codePoint: number;\n}\n\n/** Alias for DeidentificationOperationTypeOutput */\nexport type DeidentificationOperationTypeOutput = string;\n/** Alias for OperationStateOutput */\nexport type OperationStateOutput = string;\n/** Alias for PhiCategoryOutput */\nexport type PhiCategoryOutput = string;\n"]}
1
+ {"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../src/outputModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ErrorModel } from \"@azure-rest/core-client\";\n\n/** A job containing a batch of documents to de-identify. */\nexport interface DeidentificationJobOutput {\n /** The name of a job. */\n readonly name: string;\n /**\n * Operation to perform on the input documents.\n *\n * Possible values: \"Redact\", \"Surrogate\", \"Tag\", \"SurrogateOnly\"\n */\n operation?: DeidentificationOperationTypeOutput;\n /** Storage location to perform the operation on. */\n sourceLocation: SourceStorageLocationOutput;\n /** Target location to store output of operation. */\n targetLocation: TargetStorageLocationOutput;\n /** Customization parameters to override default service behaviors. */\n customizations?: DeidentificationJobCustomizationOptionsOutput;\n /**\n * Current status of a job.\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Canceled\"\n */\n readonly status: OperationStateOutput;\n /** Error when job fails in it's entirety. */\n readonly error?: ErrorModel;\n /**\n * Date and time when the job was completed.\n *\n * If the job is canceled, this is the time when the job was canceled.\n *\n * If the job failed, this is the time when the job failed.\n */\n readonly lastUpdatedAt: string;\n /** Date and time when the job was created. */\n readonly createdAt: string;\n /** Date and time when the job was started. */\n readonly startedAt?: string;\n /** Summary of a job. Exists only when the job is completed. */\n readonly summary?: DeidentificationJobSummaryOutput;\n}\n\n/** Storage location. */\nexport interface SourceStorageLocationOutput {\n /** URL to storage location. */\n location: string;\n /** Prefix to filter path by. */\n prefix: string;\n /** List of extensions to filter path by. */\n extensions?: string[];\n}\n\n/** Storage location. */\nexport interface TargetStorageLocationOutput {\n /** URL to storage location. */\n location: string;\n /**\n * Replaces the input prefix of a file path with the output prefix, preserving the rest of the path structure.\n *\n * Example:\n * File full path: documents/user/note.txt\n * Input Prefix: \"documents/user/\"\n * Output Prefix: \"output_docs/\"\n *\n * Output file: \"output_docs/note.txt\"\n */\n prefix: string;\n /** When set to true during a job, the service will overwrite the output location if it already exists. */\n overwrite?: boolean;\n}\n\n/** Customizations options to override default service behaviors for job usage. */\nexport interface DeidentificationJobCustomizationOptionsOutput {\n /**\n * Format of the redacted output. Only valid when Operation is Redact.\n * Please refer to https://learn.microsoft.com/azure/healthcare-apis/deidentification/redaction-format for more details.\n */\n redactionFormat?: string;\n /** Locale in which the output surrogates are written. */\n surrogateLocale?: string;\n /** Locale of the input text. Used for better PHI detection. Defaults to 'en-US'. */\n inputLocale?: string;\n}\n\n/** Summary metrics of a job. */\nexport interface DeidentificationJobSummaryOutput {\n /** Number of documents that have completed. */\n successful: number;\n /** Number of documents that have failed. */\n failed: number;\n /** Number of documents that have been canceled. */\n canceled: number;\n /** Number of documents total. */\n total: number;\n /** Number of bytes processed. */\n bytesProcessed: number;\n}\n\n/** Paged collection of DeidentificationJob items */\nexport interface PagedDeidentificationJobOutput {\n /** The DeidentificationJob items on this page */\n value: Array<DeidentificationJobOutput>;\n /** The link to the next page of items */\n nextLink?: string;\n}\n\n/** Paged collection of DeidentificationDocumentDetails items */\nexport interface PagedDeidentificationDocumentDetailsOutput {\n /** The DeidentificationDocumentDetails items on this page */\n value: Array<DeidentificationDocumentDetailsOutput>;\n /** The link to the next page of items */\n nextLink?: string;\n}\n\n/** Details of a single document in a job. */\nexport interface DeidentificationDocumentDetailsOutput {\n /** Id of the document details. */\n readonly id: string;\n /** Location for the input. */\n input: DeidentificationDocumentLocationOutput;\n /** Location for the output. */\n output?: DeidentificationDocumentLocationOutput;\n /**\n * Status of the document.\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Canceled\"\n */\n status: OperationStateOutput;\n /** Error when document fails. */\n error?: ErrorModel;\n}\n\n/** Location of a document. */\nexport interface DeidentificationDocumentLocationOutput {\n /** Location of document in storage. */\n location: string;\n /** The entity tag for this resource. */\n readonly etag: string;\n}\n\n/** Response body for de-identification operation. */\nexport interface DeidentificationResultOutput {\n /** Output text after de-identification. Not available for \"Tag\" operation. */\n outputText?: string;\n /** Result of the \"Tag\" operation. Only available for \"Tag\" Operation. */\n taggerResult?: PhiTaggerResultOutput;\n}\n\n/** Result of the \"Tag\" operation. */\nexport interface PhiTaggerResultOutput {\n /** List of entities detected in the input. */\n entities: Array<PhiEntityOutput>;\n}\n\n/** PHI Entity tag in the input. */\nexport interface PhiEntityOutput {\n /**\n * PHI Category of the entity.\n *\n * Possible values: \"Unknown\", \"Account\", \"Age\", \"BioID\", \"City\", \"CountryOrRegion\", \"Date\", \"Device\", \"Doctor\", \"Email\", \"Fax\", \"HealthPlan\", \"Hospital\", \"IDNum\", \"IPAddress\", \"License\", \"LocationOther\", \"MedicalRecord\", \"Organization\", \"Patient\", \"Phone\", \"Profession\", \"SocialSecurity\", \"State\", \"Street\", \"Url\", \"Username\", \"Vehicle\", \"Zip\"\n */\n category: PhiCategoryOutput;\n /** Starting index of the location from within the input text. */\n offset: StringIndexOutput;\n /** Length of the input text. */\n length: StringIndexOutput;\n /** Text of the entity. */\n text?: string;\n /** Confidence score of the category match. */\n confidenceScore?: number;\n}\n\n/** String index encoding model. */\nexport interface StringIndexOutput {\n /** The offset or length of the substring in UTF-8 encoding */\n utf8: number;\n /**\n * The offset or length of the substring in UTF-16 encoding.\n *\n * Primary encoding used by .NET, Java, and JavaScript.\n */\n utf16: number;\n /**\n * The offset or length of the substring in CodePoint encoding.\n *\n * Primary encoding used by Python.\n */\n codePoint: number;\n}\n\n/** Alias for DeidentificationOperationTypeOutput */\nexport type DeidentificationOperationTypeOutput = string;\n/** Alias for OperationStateOutput */\nexport type OperationStateOutput = string;\n/** Alias for PhiCategoryOutput */\nexport type PhiCategoryOutput = string;\n"]}
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
4
3
  import { createRestError } from "@azure-rest/core-client";
5
4
  /**
6
5
  * returns an async iterator that iterates over results. It also has a `byPage`
@@ -10,7 +9,6 @@ import { createRestError } from "@azure-rest/core-client";
10
9
  * @returns a paged async iterator that iterates over results.
11
10
  */
12
11
  function getPagedAsyncIterator(pagedResult) {
13
- var _a;
14
12
  const iter = getItemAsyncIterator(pagedResult);
15
13
  return {
16
14
  next() {
@@ -19,85 +17,57 @@ function getPagedAsyncIterator(pagedResult) {
19
17
  [Symbol.asyncIterator]() {
20
18
  return this;
21
19
  },
22
- byPage: (_a = pagedResult === null || pagedResult === void 0 ? void 0 : pagedResult.byPage) !== null && _a !== void 0 ? _a : ((settings) => {
23
- const { continuationToken } = settings !== null && settings !== void 0 ? settings : {};
24
- return getPageAsyncIterator(pagedResult, {
25
- pageLink: continuationToken,
26
- });
27
- }),
20
+ byPage: pagedResult?.byPage ??
21
+ ((settings) => {
22
+ const { continuationToken } = settings ?? {};
23
+ return getPageAsyncIterator(pagedResult, {
24
+ pageLink: continuationToken,
25
+ });
26
+ }),
28
27
  };
29
28
  }
30
- function getItemAsyncIterator(pagedResult) {
31
- return __asyncGenerator(this, arguments, function* getItemAsyncIterator_1() {
32
- var _a, e_1, _b, _c, _d, e_2, _e, _f;
33
- const pages = getPageAsyncIterator(pagedResult);
34
- const firstVal = yield __await(pages.next());
35
- // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
36
- if (!Array.isArray(firstVal.value)) {
37
- // can extract elements from this page
38
- const { toElements } = pagedResult;
39
- if (toElements) {
40
- yield __await(yield* __asyncDelegator(__asyncValues(toElements(firstVal.value))));
41
- try {
42
- for (var _g = true, pages_1 = __asyncValues(pages), pages_1_1; pages_1_1 = yield __await(pages_1.next()), _a = pages_1_1.done, !_a; _g = true) {
43
- _c = pages_1_1.value;
44
- _g = false;
45
- const page = _c;
46
- yield __await(yield* __asyncDelegator(__asyncValues(toElements(page))));
47
- }
48
- }
49
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
50
- finally {
51
- try {
52
- if (!_g && !_a && (_b = pages_1.return)) yield __await(_b.call(pages_1));
53
- }
54
- finally { if (e_1) throw e_1.error; }
55
- }
56
- }
57
- else {
58
- yield yield __await(firstVal.value);
59
- // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
60
- yield __await(yield* __asyncDelegator(__asyncValues(pages)));
29
+ async function* getItemAsyncIterator(pagedResult) {
30
+ const pages = getPageAsyncIterator(pagedResult);
31
+ const firstVal = await pages.next();
32
+ // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
33
+ if (!Array.isArray(firstVal.value)) {
34
+ // can extract elements from this page
35
+ const { toElements } = pagedResult;
36
+ if (toElements) {
37
+ yield* toElements(firstVal.value);
38
+ for await (const page of pages) {
39
+ yield* toElements(page);
61
40
  }
62
41
  }
63
42
  else {
64
- yield __await(yield* __asyncDelegator(__asyncValues(firstVal.value)));
65
- try {
66
- for (var _h = true, pages_2 = __asyncValues(pages), pages_2_1; pages_2_1 = yield __await(pages_2.next()), _d = pages_2_1.done, !_d; _h = true) {
67
- _f = pages_2_1.value;
68
- _h = false;
69
- const page = _f;
70
- // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
71
- // it must be the case that `TPage = TElement[]`
72
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
73
- }
74
- }
75
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
76
- finally {
77
- try {
78
- if (!_h && !_d && (_e = pages_2.return)) yield __await(_e.call(pages_2));
79
- }
80
- finally { if (e_2) throw e_2.error; }
81
- }
43
+ yield firstVal.value;
44
+ // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
45
+ yield* pages;
46
+ }
47
+ }
48
+ else {
49
+ yield* firstVal.value;
50
+ for await (const page of pages) {
51
+ // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
52
+ // it must be the case that `TPage = TElement[]`
53
+ yield* page;
82
54
  }
83
- });
55
+ }
84
56
  }
85
- function getPageAsyncIterator(pagedResult_1) {
86
- return __asyncGenerator(this, arguments, function* getPageAsyncIterator_1(pagedResult, options = {}) {
87
- const { pageLink } = options;
88
- let response = yield __await(pagedResult.getPage(pageLink !== null && pageLink !== void 0 ? pageLink : pagedResult.firstPageLink));
57
+ async function* getPageAsyncIterator(pagedResult, options = {}) {
58
+ const { pageLink } = options;
59
+ let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);
60
+ if (!response) {
61
+ return;
62
+ }
63
+ yield response.page;
64
+ while (response.nextPageLink) {
65
+ response = await pagedResult.getPage(response.nextPageLink);
89
66
  if (!response) {
90
- return yield __await(void 0);
67
+ return;
91
68
  }
92
- yield yield __await(response.page);
93
- while (response.nextPageLink) {
94
- response = yield __await(pagedResult.getPage(response.nextPageLink));
95
- if (!response) {
96
- return yield __await(void 0);
97
- }
98
- yield yield __await(response.page);
99
- }
100
- });
69
+ yield response.page;
70
+ }
101
71
  }
102
72
  /**
103
73
  * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
@@ -153,7 +123,7 @@ function getElements(body, itemName) {
153
123
  if (!Array.isArray(value)) {
154
124
  throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
155
125
  }
156
- return value !== null && value !== void 0 ? value : [];
126
+ return value ?? [];
157
127
  }
158
128
  /**
159
129
  * Checks if a request failed
@@ -1 +1 @@
1
- {"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginate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,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,iBAAiB,YAAY,kCAAkC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAc,IAAa,EAAE,QAAgB;IAC/D,MAAM,KAAK,GAAI,IAAgC,CAAC,QAAQ,CAAQ,CAAC;IAEjE,qEAAqE;IACrE,qEAAqE;IACrE,iDAAiD;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kFAAkF,QAAQ,EAAE,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAA+B;IACzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,eAAe,CACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\n\n/**\n * returns an async iterator that iterates over results. It also has a `byPage`\n * method that returns pages of items at once.\n *\n * @param pagedResult - an object that specifies how to get pages.\n * @returns a paged async iterator that iterates over results.\n */\nfunction getPagedAsyncIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n TLink = string,\n>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {\n const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage:\n pagedResult?.byPage ??\n (((settings?: PageSettings) => {\n const { continuationToken } = settings ?? {};\n return getPageAsyncIterator(pagedResult, {\n pageLink: continuationToken as unknown as TLink | undefined,\n });\n }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),\n };\n}\n\nasync function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): AsyncIterableIterator<TElement> {\n const pages = getPageAsyncIterator(pagedResult);\n const firstVal = await pages.next();\n // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is\n if (!Array.isArray(firstVal.value)) {\n // can extract elements from this page\n const { toElements } = pagedResult;\n if (toElements) {\n yield* toElements(firstVal.value) as TElement[];\n for await (const page of pages) {\n yield* toElements(page) as TElement[];\n }\n } else {\n yield firstVal.value;\n // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case\n yield* pages as unknown as AsyncIterableIterator<TElement>;\n }\n } else {\n yield* firstVal.value;\n for await (const page of pages) {\n // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,\n // it must be the case that `TPage = TElement[]`\n yield* page as unknown as TElement[];\n }\n }\n}\n\nasync function* getPageAsyncIterator<TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n options: {\n pageLink?: TLink;\n } = {},\n): AsyncIterableIterator<TPage> {\n const { pageLink } = options;\n let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n while (response.nextPageLink) {\n response = await pagedResult.getPage(response.nextPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n }\n}\n\n/**\n * An interface that tracks the settings for paged iteration\n */\nexport interface PageSettings {\n /**\n * The token that keeps track of where to continue the iterator\n */\n continuationToken?: string;\n}\n\n/**\n * An interface that allows async iterable iteration both to completion and by page.\n */\nexport interface PagedAsyncIterableIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n> {\n /**\n * The next method, part of the iteration protocol\n */\n next(): Promise<IteratorResult<TElement>>;\n /**\n * The connection to the async iterator, part of the iteration protocol\n */\n [Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;\n /**\n * Return an AsyncIterableIterator that works a page at a time\n */\n byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n}\n\n/**\n * An interface that describes how to communicate with the service.\n */\ninterface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {\n /**\n * Link to the first page of results.\n */\n firstPageLink: TLink;\n /**\n * A method that returns a page of results.\n */\n getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;\n /**\n * a function to implement the `byPage` method on the paged async iterator.\n */\n byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n\n /**\n * A function to extract elements from a page.\n */\n toElements?: (page: TPage) => unknown[];\n}\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (pageLink: string) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {},\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`,\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;;;;GAMG;AACH,SAAS,qBAAqB,CAM5B,WAAqD;IAErD,MAAM,IAAI,GAAG,oBAAoB,CAAwC,WAAW,CAAC,CAAC;IACtF,OAAO;QACL,IAAI;YACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EACJ,WAAW,EAAE,MAAM;YAClB,CAAC,CAAC,QAAuB,EAAE,EAAE;gBAC5B,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,IAAI,EAAE,CAAC;gBAC7C,OAAO,oBAAoB,CAAC,WAAW,EAAE;oBACvC,QAAQ,EAAE,iBAAiD;iBAC5D,CAAC,CAAC;YACL,CAAC,CAA2E;KAC/E,CAAC;AACJ,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,oBAAoB,CAClC,WAAqD;IAErD,MAAM,KAAK,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACpC,6FAA6F;IAC7F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,C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B,YAAY,kCAAkC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAc,IAAa,EAAE,QAAgB;IAC/D,MAAM,KAAK,GAAI,IAAgC,CAAC,QAAQ,CAAQ,CAAC;IAEjE,qEAAqE;IACrE,qEAAqE;IACrE,iDAAiD;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kFAAkF,QAAQ,EAAE,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,IAAI,EAAE,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAA+B;IACzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,eAAe,CACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\n\n/**\n * returns an async iterator that iterates over results. It also has a `byPage`\n * method that returns pages of items at once.\n *\n * @param pagedResult - an object that specifies how to get pages.\n * @returns a paged async iterator that iterates over results.\n */\nfunction getPagedAsyncIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n TLink = string,\n>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {\n const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage:\n pagedResult?.byPage ??\n (((settings?: PageSettings) => {\n const { continuationToken } = settings ?? {};\n return getPageAsyncIterator(pagedResult, {\n pageLink: continuationToken as unknown as TLink | undefined,\n });\n }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),\n };\n}\n\nasync function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): AsyncIterableIterator<TElement> {\n const pages = getPageAsyncIterator(pagedResult);\n const firstVal = await pages.next();\n // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is\n if (!Array.isArray(firstVal.value)) {\n // can extract elements from this page\n const { toElements } = pagedResult;\n if (toElements) {\n yield* toElements(firstVal.value) as TElement[];\n for await (const page of pages) {\n yield* toElements(page) as TElement[];\n }\n } else {\n yield firstVal.value;\n // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case\n yield* pages as unknown as AsyncIterableIterator<TElement>;\n }\n } else {\n yield* firstVal.value;\n for await (const page of pages) {\n // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,\n // it must be the case that `TPage = TElement[]`\n yield* page as unknown as TElement[];\n }\n }\n}\n\nasync function* getPageAsyncIterator<TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n options: {\n pageLink?: TLink;\n } = {},\n): AsyncIterableIterator<TPage> {\n const { pageLink } = options;\n let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n while (response.nextPageLink) {\n response = await pagedResult.getPage(response.nextPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n }\n}\n\n/**\n * An interface that tracks the settings for paged iteration\n */\nexport interface PageSettings {\n /**\n * The token that keeps track of where to continue the iterator\n */\n continuationToken?: string;\n}\n\n/**\n * An interface that allows async iterable iteration both to completion and by page.\n */\nexport interface PagedAsyncIterableIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n> {\n /**\n * The next method, part of the iteration protocol\n */\n next(): Promise<IteratorResult<TElement>>;\n /**\n * The connection to the async iterator, part of the iteration protocol\n */\n [Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;\n /**\n * Return an AsyncIterableIterator that works a page at a time\n */\n byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n}\n\n/**\n * An interface that describes how to communicate with the service.\n */\ninterface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {\n /**\n * Link to the first page of results.\n */\n firstPageLink: TLink;\n /**\n * A method that returns a page of results.\n */\n getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;\n /**\n * a function to implement the `byPage` method on the paged async iterator.\n */\n byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n\n /**\n * A function to extract elements from a page.\n */\n toElements?: (page: TPage) => unknown[];\n}\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (pageLink: string) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {},\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`,\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response,\n );\n }\n}\n"]}
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT License.
3
3
  import { createHttpPoller } from "@azure/core-lro";
4
4
  export async function getLongRunningPoller(client, initialResponse, options = {}) {
5
- var _a;
6
5
  const abortController = new AbortController();
7
6
  const poller = {
8
7
  sendInitialRequest: async () => {
@@ -19,31 +18,31 @@ export async function getLongRunningPoller(client, initialResponse, options = {}
19
18
  function abortListener() {
20
19
  abortController.abort();
21
20
  }
22
- const inputAbortSignal = pollOptions === null || pollOptions === void 0 ? void 0 : pollOptions.abortSignal;
21
+ const inputAbortSignal = pollOptions?.abortSignal;
23
22
  const abortSignal = abortController.signal;
24
- if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
23
+ if (inputAbortSignal?.aborted) {
25
24
  abortController.abort();
26
25
  }
27
26
  else if (!abortSignal.aborted) {
28
- inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, {
27
+ inputAbortSignal?.addEventListener("abort", abortListener, {
29
28
  once: true,
30
29
  });
31
30
  }
32
31
  let response;
33
32
  try {
34
33
  response = await client
35
- .pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url)
34
+ .pathUnchecked(path ?? initialResponse.request.url)
36
35
  .get({ abortSignal });
37
36
  }
38
37
  finally {
39
- inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
38
+ inputAbortSignal?.removeEventListener("abort", abortListener);
40
39
  }
41
40
  const lroResponse = getLroResponse(response);
42
41
  lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
43
42
  return lroResponse;
44
43
  },
45
44
  };
46
- options.resolveOnUnsuccessful = (_a = options.resolveOnUnsuccessful) !== null && _a !== void 0 ? _a : true;
45
+ options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
47
46
  const httpPoller = createHttpPoller(poller, options);
48
47
  const simplePoller = {
49
48
  isDone() {
@@ -91,7 +90,11 @@ function getLroResponse(response) {
91
90
  }
92
91
  return {
93
92
  flatResponse: response,
94
- rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body }),
93
+ rawResponse: {
94
+ ...response,
95
+ statusCode: Number.parseInt(response.status),
96
+ body: response.body,
97
+ },
95
98
  };
96
99
  }
97
100
  //# sourceMappingURL=pollingHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pollingHelper.js","sourceRoot":"","sources":["../../src/pollingHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA2FnD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,eAAwB,EACxB,UAAqE,EAAE;;IAEvE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,MAAM,GAA8B;QACxC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,sGAAsG;YACtG,2FAA2F;YAC3F,6BAA6B;YAC7B,OAAO,cAAc,CAAC,eAAe,CAAC,CAAC;QACzC,CAAC;QACD,eAAe,EAAE,KAAK,EAAE,IAAY,EAAE,WAA+C,EAAE,EAAE;YACvF,sEAAsE;YACtE,4EAA4E;YAC5E,0JAA0J;YAC1J,+GAA+G;YAC/G,SAAS,aAAa;gBACpB,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;YACD,MAAM,gBAAgB,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,WAAW,CAAC;YAClD,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC;YAC3C,IAAI,gBAAgB,aAAhB,gBAAgB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ACb,4IAA4I,CAC7I,CAAC;YACJ,CAAC;YACD,OAAO,UAAU,CAAC,cAAc,CAAC;QACnC,CAAC;QACD,SAAS;YACP,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,CAAC;QACD,QAAQ;YACN,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CACb,4IAA4I,CAC7I,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,KAAK,EAAE,UAAU,CAAC,cAAc;aACjC,CAAC,CAAC;QACL,CAAC;QACD,WAAW;YACT,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CACrB,QAAiB;IAEjB,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uDAAuD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,WAAW,kCACN,QAAQ,KACX,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI,GACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n DeidentifyDocuments200Response,\n DeidentifyDocuments201Response,\n DeidentifyDocumentsDefaultResponse,\n DeidentifyDocumentsLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends DeidentifyDocumentsLogicalResponse | DeidentifyDocumentsDefaultResponse,\n>(\n client: Client,\n initialResponse:\n | DeidentifyDocuments200Response\n | DeidentifyDocuments201Response\n | DeidentifyDocumentsDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n const httpPoller = createHttpPoller(poller, options);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"pollingHelper.js","sourceRoot":"","sources":["../../src/pollingHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA2FnD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,eAAwB,EACxB,UAAqE,EAAE;IAEvE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,MAAM,GAA8B;QACxC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,sGAAsG;YACtG,2FAA2F;YAC3F,6BAA6B;YAC7B,OAAO,cAAc,CAAC,eAAe,CAA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QAAQ,CAAC,IAAI;SACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n DeidentifyDocuments200Response,\n DeidentifyDocuments201Response,\n DeidentifyDocumentsDefaultResponse,\n DeidentifyDocumentsLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends DeidentifyDocumentsLogicalResponse | DeidentifyDocumentsDefaultResponse,\n>(\n client: Client,\n initialResponse:\n | DeidentifyDocuments200Response\n | DeidentifyDocuments201Response\n | DeidentifyDocumentsDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n const httpPoller = createHttpPoller(poller, options);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __rest } from "tslib";
4
3
  import { getClient } from "@azure-rest/core-client";
5
4
  import { logger } from "./logger.js";
6
5
  /**
@@ -9,21 +8,24 @@ import { logger } from "./logger.js";
9
8
  * @param credentials - uniquely identify client credential
10
9
  * @param options - the parameter for all optional parameters
11
10
  */
12
- export default function createClient(endpointParam, credentials, _a = {}) {
13
- var _b, _c, _d, _e, _f, _g;
14
- var { apiVersion = "2024-11-15" } = _a, options = __rest(_a, ["apiVersion"]);
15
- const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`;
11
+ export default function createClient(endpointParam, credentials, { apiVersion = "2025-07-15-preview", ...options } = {}) {
12
+ const endpointUrl = options.endpoint ?? `${endpointParam}`;
16
13
  const userAgentInfo = `azsdk-js-health-deidentification-rest/1.0.0-beta.1`;
17
14
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
18
15
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
19
16
  : `${userAgentInfo}`;
20
- options = Object.assign(Object.assign({}, options), { userAgentOptions: {
17
+ options = {
18
+ ...options,
19
+ userAgentOptions: {
21
20
  userAgentPrefix,
22
- }, loggingOptions: {
23
- logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
24
- }, credentials: {
25
- scopes: (_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.scopes) !== null && _g !== void 0 ? _g : ["https://deid.azure.com/.default"],
26
- } });
21
+ },
22
+ loggingOptions: {
23
+ logger: options.loggingOptions?.logger ?? logger.info,
24
+ },
25
+ credentials: {
26
+ scopes: options.credentials?.scopes ?? ["https://deid.azure.com/.default"],
27
+ },
28
+ };
27
29
  const client = getClient(endpointUrl, credentials, options);
28
30
  client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
29
31
  client.pipeline.addPolicy({
@@ -1 +1 @@
1
- {"version":3,"file":"deidentificationClient.js","sourceRoot":"","sources":["../../src/deidentificationClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAA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C,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport type { DeidentificationClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface DeidentificationClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `DeidentificationClient`\n * @param endpointParam - Url of your De-identification Service.\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n credentials: TokenCredential,\n { apiVersion = \"2024-11-15\", ...options }: DeidentificationClientOptions = {},\n): DeidentificationClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-health-deidentification-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://deid.azure.com/.default\"],\n },\n };\n const client = getClient(endpointUrl, credentials, options) as DeidentificationClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
1
+ {"version":3,"file":"deidentificationClient.js","sourceRoot":"","sources":["../../src/deidentificationClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,WAA4B,EAC5B,EAAE,UAAU,GAAG,oBAAoB,EAAE,GAAG,OAAO,KAAoC,EAAE;IAErF,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,GAAG,aAAa,EAAE,CAAC;IAC3D,MAAM,aAAa,GAAG,oDAAoD,CAAC;IAC3E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,GAAG;QACR,GAAG,OAAO;QACV,gBAAgB,EAAE;YAChB,eAAe;SAChB;QACD,cAAc,EAAE;YACd,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,IAAI,MAAM,CAAC,IAAI;SACtD;QACD,WAAW,EAAE;YACX,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,iCAAiC,CAAC;SAC3E;KACF,CAAC;IACF,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAA2B,CAAC;IAEtF,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,qDAAqD;YACrD,yEAAyE;YACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport type { DeidentificationClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface DeidentificationClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `DeidentificationClient`\n * @param endpointParam - Url of your De-identification Service.\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n credentials: TokenCredential,\n { apiVersion = \"2025-07-15-preview\", ...options }: DeidentificationClientOptions = {},\n): DeidentificationClient {\n const endpointUrl = options.endpoint ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-health-deidentification-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://deid.azure.com/.default\"],\n },\n };\n const client = getClient(endpointUrl, credentials, options) as DeidentificationClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
@@ -11,7 +11,7 @@ const responseMap = {
11
11
  };
12
12
  export function isUnexpected(response) {
13
13
  const lroOriginal = response.headers["x-ms-original-url"];
14
- const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
14
+ const url = new URL(lroOriginal ?? response.request.url);
15
15
  const method = response.request.method;
16
16
  let pathDetails = responseMap[`${method} ${url.pathname}`];
17
17
  if (!pathDetails) {
@@ -20,7 +20,6 @@ export function isUnexpected(response) {
20
20
  return !pathDetails.includes(response.status);
21
21
  }
22
22
  function getParametrizedPathSuccess(method, path) {
23
- var _a, _b, _c, _d;
24
23
  const pathParts = path.split("/");
25
24
  // Traverse list to match the longest candidate
26
25
  // matchedLen: the length of candidate path
@@ -39,13 +38,13 @@ function getParametrizedPathSuccess(method, path) {
39
38
  // track if we have found a match to return the values found.
40
39
  let found = true;
41
40
  for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
42
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
43
- const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
41
+ if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
42
+ const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
44
43
  // If the current part of the candidate is a "template" part
45
44
  // Try to use the suffix of pattern to match the path
46
45
  // {guid} ==> $
47
46
  // {guid}:export ==> :export$
48
- const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
47
+ const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
49
48
  if (!isMatched) {
50
49
  found = false;
51
50
  break;