@@ -38,7 +38,8 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
3838 collectionId ,
3939 options ,
4040 ) => {
41- await this . #serviceClient. createTable ( collectionId , {
41+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
42+ await this . #serviceClient. createTable ( tableName , {
4243 abortSignal : options . abortSignal ,
4344 } ) ;
4445 return ;
@@ -49,9 +50,10 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
4950 options ,
5051 ) => {
5152 try {
53+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
5254 const iterator = this . #serviceClient. listTables ( {
5355 abortSignal : options . abortSignal ,
54- queryOptions : { filter : odata `TableName eq ${ collectionId } ` } ,
56+ queryOptions : { filter : odata `TableName eq ${ tableName } ` } ,
5557 } ) ;
5658 for await ( const table of iterator ) {
5759 if ( table . name === collectionId ) {
@@ -69,7 +71,8 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
6971 collectionId ,
7072 options ,
7173 ) => {
72- await this . #serviceClient. deleteTable ( collectionId , {
74+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
75+ await this . #serviceClient. deleteTable ( tableName , {
7376 abortSignal : options . abortSignal ,
7477 } ) ;
7578 return ;
@@ -83,9 +86,11 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
8386 options : DatabaseServiceOptions ,
8487 ) : Promise < Document [ ] > => {
8588 const { filter, limit, select, sort } = listOptions || { } ;
89+
90+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
8691 const tableClient = TableClient . fromConnectionString (
8792 this . #connectionString,
88- collectionId ,
93+ tableName ,
8994 ) ;
9095 const pageIterator = tableClient
9196 . listEntities ( {
@@ -127,9 +132,10 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
127132 documentId : string ,
128133 options : DatabaseServiceOptions ,
129134 ) : Promise < Document > => {
135+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
130136 const tableClient = TableClient . fromConnectionString (
131137 this . #connectionString,
132- collectionId ,
138+ tableName ,
133139 ) ;
134140 const entity = await tableClient . getEntity ( collectionId , documentId , {
135141 abortSignal : options . abortSignal ,
@@ -155,9 +161,10 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
155161 documentData ,
156162 options ,
157163 ) => {
164+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
158165 const tableClient = TableClient . fromConnectionString (
159166 this . #connectionString,
160- collectionId ,
167+ tableName ,
161168 ) ;
162169 await tableClient . createEntity (
163170 {
@@ -176,9 +183,10 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
176183 documentId ,
177184 options ,
178185 ) => {
186+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
179187 const tableClient = TableClient . fromConnectionString (
180188 this . #connectionString,
181- collectionId ,
189+ tableName ,
182190 ) ;
183191 await tableClient . deleteEntity ( collectionId , documentId , {
184192 abortSignal : options . abortSignal ,
@@ -194,9 +202,10 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
194202 documentData ,
195203 options ,
196204 ) => {
205+ const tableName = genTableNameFromCollectionId ( collectionId ) ;
197206 const tableClient = TableClient . fromConnectionString (
198207 this . #connectionString,
199- collectionId ,
208+ tableName ,
200209 ) ;
201210 await tableClient . updateEntity (
202211 { ...documentData , partitionKey : collectionId , rowKey : documentId } ,
@@ -216,3 +225,11 @@ export class AzureDataTablesDatabaseService implements DatabaseService {
216225 } as unknown as Item ;
217226 } ;
218227}
228+
229+ function genTableNameFromCollectionId ( collectionId : string ) : string {
230+ if ( / ^ [ A - Z a - z ] [ A - Z a - z 0 - 9 ] { 2 , 62 } $ / . test ( collectionId ) ) {
231+ return collectionId ;
232+ }
233+
234+ return collectionId . replaceAll ( / \W / g, "" ) . slice ( 0 , 63 ) . padEnd ( 3 , "X" ) ;
235+ }
0 commit comments