@buildplease/webkit 1.0.2 → 1.0.4

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.
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("reflect-metadata");let e=require("@buildplease/core"),t=require("inversify");function n(){return[]}`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}`;const r={DI:{}},i=e.CoreL10nResource;var a=class{mode;pendingEntries=[];activeEntries=new Set;interruption;isSerialOperationRunning=!1;constructor(e=`parallel`){this.mode=e}execute(t){if(this.interruption)return Promise.reject(new e.CanceledError);let n=this.createEntry(t);return this.mode===`serial`?(this.pendingEntries.push(n),this.startNextSerialOperation()):this.startEntry(n),n.promise}cancelAll(e){let t=this.pendingEntries.splice(0);for(let n of t)this.cancelEntry(n,e);for(let t of this.activeEntries)this.cancelEntry(t,e)}async interrupt(e){if(!this.interruption){let t=Promise.resolve().then(e).finally(()=>{this.interruption===t&&(this.interruption=void 0,this.startNextSerialOperation())});this.interruption=t,this.cancelAll()}await this.interruption}createEntry(e){let t,n;return{operation:e,promise:new Promise((e,r)=>{t=e,n=r}),resolve:e=>t?.(e),reject:e=>n?.(e),canceled:!1,settled:!1}}startEntry(e){if(e.canceled||this.interruption){this.cancelEntry(e);return}this.activeEntries.add(e),this.mode===`serial`&&(this.isSerialOperationRunning=!0),Promise.resolve().then(e.operation).then(t=>{e.canceled||this.resolveEntry(e,t)},t=>{e.canceled||this.rejectEntry(e,t)}).finally(()=>{this.activeEntries.delete(e),this.mode===`serial`&&(this.isSerialOperationRunning=!1,this.startNextSerialOperation())})}startNextSerialOperation(){if(this.mode!==`serial`||this.isSerialOperationRunning||this.interruption)return;let e=this.pendingEntries.shift();e&&this.startEntry(e)}cancelEntry(t,n){t.canceled||(t.canceled=!0,t.settled||this.rejectEntry(t,new e.CanceledError({cause:n})))}resolveEntry(e,t){e.settled||(e.settled=!0,e.resolve(t))}rejectEntry(e,t){e.settled||(e.settled=!0,e.reject(t))}},o=class extends Error{statusCode;code;details;constructor(e){super(e.message),this.name=`HttpError`,this.statusCode=e.statusCode,this.code=e.code,this.details=e.details,e.cause!==void 0&&(this.cause=e.cause)}},s=class{interceptors;constructor(e=[],t){this.interceptors=this.resolveInterceptors(e,t)}async intercept(e){let t=e;for(let e of this.interceptors)t=await e.intercept(t);return t}resolveInterceptors(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i.identity)){t?.(`Duplicate HTTP request interceptor ignored: ${String(i.identity)}`);continue}n.add(i.identity),r.push(i)}return Object.freeze(r)}};const c={credentials:!0,headers:{}};var l=class{requestOptions;interceptorPipeline;asyncQueue;unauthorized;constructor(e={}){this.requestOptions=e.requestOptions??{},this.interceptorPipeline=e.interceptorPipeline??new s,this.asyncQueue=e.asyncQueue??new a,this.unauthorized=e.unauthorized}execute(e,t){return this.asyncQueue.execute(async()=>{let n=await this.makeRequestOptions(e,t);try{let t=this.createClient(n);return await e.execute(t)}catch(e){throw this.handleError(e)}})}handleError(t){return t instanceof o||t instanceof e.NetworkError||t instanceof e.TimeoutError||t instanceof e.CanceledError||t instanceof e.UnknownError?t:new e.UnknownError({message:t instanceof Error?t.message:void 0,cause:t})}async makeRequestOptions(e,t){let n=this.mergeRequestOptions(c,this.requestOptions);return n=await this.interceptorPipeline.intercept(n),n=this.mergeRequestOptions(n,e.options),n=this.mergeRequestOptions(n,t),n}mergeRequestOptions(e,t){return t?{credentials:t.credentials??e.credentials,headers:{...e.headers,...t.headers}}:e}};function u(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let p=class{endpoint;httpClient;constructor(e,t){this.endpoint=e,this.httpClient=t}async execute(e,t){let n=await this.convertOrThrow(()=>this.endpoint.convertInput(e)),r=this.endpoint.makeRequest(n),i=await this.httpClient.execute(r,t);return await this.convertOrThrow(()=>this.endpoint.convertOutput(i))}async convertOrThrow(t){try{return await t()}catch(t){throw new e.ConversionError({cause:t})}}};p=f([(0,t.injectable)(),d(0,(0,t.unmanaged)()),d(1,(0,t.unmanaged)()),u(`design:paramtypes`,[Object,Object])],p);let m=class extends p{constructor(e,t){super(e,t)}};m=f([(0,t.injectable)(),u(`design:paramtypes`,[Object,Object])],m);let h=class extends p{constructor(e,t){super(e,t)}async execute(t,n){try{return await super.execute(t,n)}catch(t){if(!(t instanceof o))throw t;let n=this.httpClient.unauthorized;throw!n||!n.statusCodes.includes(t.statusCode)?t:n.cancelAll?(await this.httpClient.asyncQueue.interrupt(()=>n.handler.handle(t)),new e.CanceledError({cause:t})):(await n.handler.handle(t),t)}}};h=f([(0,t.injectable)(),u(`design:paramtypes`,[Object,Object])],h);function g(){let t=(0,e.coreAssembly)(),r=n();return[...t,...r]}exports.AsyncQueueImpl=a,exports.HttpClient=l,exports.HttpError=o,exports.HttpRequestInterceptorPipeline=s,Object.defineProperty(exports,"PublicRemoteResource",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"RemoteResource",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"SecuredRemoteResource",{enumerable:!0,get:function(){return h}}),exports.WebKitL10nResource=i,exports.WebKitSymbols=r,exports.webkitAssembly=g,Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("reflect-metadata");let e=require("@buildplease/core"),t=require("inversify");function n(){return[]}`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}`;const r={DI:{}},i=e.CoreL10nResource;var a=class{mode;pendingEntries=[];activeEntries=new Set;interruption;isSerialOperationRunning=!1;constructor(e=`parallel`){this.mode=e}execute(t){if(this.interruption)return Promise.reject(new e.CanceledError);let n=this.createEntry(t);return this.mode===`serial`?(this.pendingEntries.push(n),this.startNextSerialOperation()):this.startEntry(n),n.promise}cancelAll(e){let t=this.pendingEntries.splice(0);for(let n of t)this.cancelEntry(n,e);for(let t of this.activeEntries)this.cancelEntry(t,e)}async interrupt(e){if(!this.interruption){let t=Promise.resolve().then(e).finally(()=>{this.interruption===t&&(this.interruption=void 0,this.startNextSerialOperation())});this.interruption=t,this.cancelAll()}await this.interruption}createEntry(e){let t,n;return{operation:e,promise:new Promise((e,r)=>{t=e,n=r}),resolve:e=>t?.(e),reject:e=>n?.(e),canceled:!1,settled:!1}}startEntry(e){if(e.canceled||this.interruption){this.cancelEntry(e);return}this.activeEntries.add(e),this.mode===`serial`&&(this.isSerialOperationRunning=!0),Promise.resolve().then(e.operation).then(t=>{e.canceled||this.resolveEntry(e,t)},t=>{e.canceled||this.rejectEntry(e,t)}).finally(()=>{this.activeEntries.delete(e),this.mode===`serial`&&(this.isSerialOperationRunning=!1,this.startNextSerialOperation())})}startNextSerialOperation(){if(this.mode!==`serial`||this.isSerialOperationRunning||this.interruption)return;let e=this.pendingEntries.shift();e&&this.startEntry(e)}cancelEntry(t,n){t.canceled||(t.canceled=!0,t.settled||this.rejectEntry(t,new e.CanceledError({cause:n})))}resolveEntry(e,t){e.settled||(e.settled=!0,e.resolve(t))}rejectEntry(e,t){e.settled||(e.settled=!0,e.reject(t))}},o=class extends Error{statusCode;code;details;constructor(e){super(e.message),this.name=`HttpError`,this.statusCode=e.statusCode,this.code=e.code,this.details=e.details,e.cause!==void 0&&(this.cause=e.cause)}},s=class{interceptors;constructor(e=[],t){this.interceptors=this.resolveInterceptors(e,t)}async intercept(e){let t=e;for(let e of this.interceptors)t=await e.intercept(t);return t}resolveInterceptors(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i.identity)){t?.(`Duplicate HTTP request interceptor ignored: ${String(i.identity)}`);continue}n.add(i.identity),r.push(i)}return Object.freeze(r)}};const c={credentials:!0,headers:{}};var l=class{requestOptions;interceptorPipeline;asyncQueue;unauthorized;constructor(e={}){this.requestOptions=e.requestOptions??{},this.interceptorPipeline=e.interceptorPipeline??new s,this.asyncQueue=e.asyncQueue??new a,this.unauthorized=e.unauthorized}execute(e,t){return this.asyncQueue.execute(async()=>{let n=await this.makeRequestOptions(e,t);try{let t=this.createClient(n);return await e.execute(t)}catch(e){throw this.handleError(e)}})}handleError(t){return t instanceof o||t instanceof e.NetworkError||t instanceof e.TimeoutError||t instanceof e.CanceledError||t instanceof e.UnknownError?t:new e.UnknownError({message:t instanceof Error?t.message:void 0,cause:t})}async makeRequestOptions(e,t){let n=this.mergeRequestOptions(c,this.requestOptions);return n=await this.interceptorPipeline.intercept(n),n=this.mergeRequestOptions(n,e.options),n=this.mergeRequestOptions(n,t),n}mergeRequestOptions(e,t){return t?{credentials:t.credentials??e.credentials,headers:{...e.headers,...t.headers}}:e}};function u(e,t){return{execute:t=>e(t),options:t}}function d(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let m=class{endpoint;httpClient;constructor(e,t){this.endpoint=e,this.httpClient=t}async execute(e,t){let n=await this.convertOrThrow(()=>this.endpoint.convertInput(e)),r=this.endpoint.makeRequest(n),i=await this.httpClient.execute(r,t);return await this.convertOrThrow(()=>this.endpoint.convertOutput(i))}async convertOrThrow(t){try{return await t()}catch(t){throw new e.ConversionError({cause:t})}}};m=p([(0,t.injectable)(),f(0,(0,t.unmanaged)()),f(1,(0,t.unmanaged)()),d(`design:paramtypes`,[Object,Object])],m);let h=class extends m{constructor(e,t){super(e,t)}};h=p([(0,t.injectable)(),d(`design:paramtypes`,[Object,Object])],h);let g=class extends m{constructor(e,t){super(e,t)}async execute(t,n){try{return await super.execute(t,n)}catch(t){if(!(t instanceof o))throw t;let n=this.httpClient.unauthorized;throw!n||!n.statusCodes.includes(t.statusCode)?t:n.cancelAll?(await this.httpClient.asyncQueue.interrupt(()=>n.handler.handle(t)),new e.CanceledError({cause:t})):(await n.handler.handle(t),t)}}};g=p([(0,t.injectable)(),d(`design:paramtypes`,[Object,Object])],g);function _(){let t=(0,e.coreAssembly)(),r=n();return[...t,...r]}exports.AsyncQueueImpl=a,exports.HttpClient=l,exports.HttpError=o,exports.HttpRequestInterceptorPipeline=s,Object.defineProperty(exports,"PublicRemoteResource",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"RemoteResource",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"SecuredRemoteResource",{enumerable:!0,get:function(){return g}}),exports.WebKitL10nResource=i,exports.WebKitSymbols=r,exports.defineHttpRequest=u,exports.webkitAssembly=_,Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
@@ -373,11 +373,11 @@ interface HttpRequestOptions {
373
373
  }
374
374
  //#endregion
375
375
  //#region src/networking/http-request.d.ts
376
- interface HttpRequest<Client, Output> {
376
+ interface HttpRequest<Output> {
377
377
  /**
378
- * Executes the request using the configured client.
378
+ * Executes the request using the client created by the configured HTTP client.
379
379
  */
380
- readonly execute: (client: Client) => Promise<Output>;
380
+ readonly execute: (client: unknown) => Promise<Output>;
381
381
  /**
382
382
  * Options applied specifically to this request.
383
383
  *
@@ -385,6 +385,11 @@ interface HttpRequest<Client, Output> {
385
385
  */
386
386
  readonly options?: HttpRequestOptions;
387
387
  }
388
+ /**
389
+ * Creates a transport-typed HTTP request while keeping the transport type internal
390
+ * to the request implementation.
391
+ */
392
+ declare function defineHttpRequest<Client, Output>(execute: (client: Client) => Promise<Output>, options?: HttpRequestOptions): HttpRequest<Output>;
388
393
  //#endregion
389
394
  //#region src/networking/http-request-interceptor.d.ts
390
395
  /**
@@ -405,28 +410,34 @@ declare class HttpRequestInterceptorPipeline {
405
410
  //#endregion
406
411
  //#region src/networking/http-error.d.ts
407
412
  interface HttpErrorOptions {
408
- /** HTTP status code returned by the remote system. */
413
+ /** HTTP status code. */
409
414
  readonly statusCode: number;
410
- /** Machine-readable error code for programmatic handling. */
411
- readonly code: string;
412
- /** Human-readable error description. */
413
- readonly message: string;
414
415
  /**
415
- * Structured error details.
416
- *
416
+ * Error code.
417
417
  * @default undefined
418
+ * @example "not_found"
418
419
  */
419
- readonly details?: Readonly<Record<string, string[]>>;
420
+ readonly code?: string;
420
421
  /**
421
- * Original transport error.
422
- *
422
+ * Error message.
423
+ * @default undefined
424
+ * @example "Not found"
425
+ */
426
+ readonly message?: string;
427
+ /**
428
+ * Error details.
429
+ * @default undefined
430
+ */
431
+ readonly details?: unknown;
432
+ /**
433
+ * Original error.
423
434
  * @default undefined
424
435
  */
425
436
  readonly cause?: unknown;
426
437
  }
427
438
  declare class HttpError extends Error {
428
439
  readonly statusCode: HttpErrorOptions['statusCode'];
429
- readonly code: HttpErrorOptions['code'];
440
+ readonly code?: HttpErrorOptions['code'];
430
441
  readonly details?: HttpErrorOptions['details'];
431
442
  constructor(options: HttpErrorOptions);
432
443
  }
@@ -471,15 +482,15 @@ interface HttpClientOptions {
471
482
  */
472
483
  readonly unauthorized?: UnauthorizedOptions;
473
484
  }
474
- declare abstract class HttpClient<Client> {
485
+ declare abstract class HttpClient {
475
486
  private readonly requestOptions;
476
487
  private readonly interceptorPipeline;
477
488
  readonly asyncQueue: AsyncQueue;
478
489
  readonly unauthorized?: UnauthorizedOptions;
479
490
  constructor(options?: HttpClientOptions);
480
- execute<Output>(request: HttpRequest<Client, Output>, options?: HttpRequestOptions): Promise<Output>;
481
- /** Creates the concrete client for the resolved request options. */
482
- protected abstract createClient(options: HttpRequestOptions): Client;
491
+ execute<Output>(request: HttpRequest<Output>, options?: HttpRequestOptions): Promise<Output>;
492
+ /** Creates the concrete transport client for the resolved request options. */
493
+ protected abstract createClient(options: HttpRequestOptions): unknown;
483
494
  /** Maps a transport-specific failure to a BuildPlease error. */
484
495
  protected handleError(error: unknown): Error;
485
496
  private makeRequestOptions;
@@ -490,36 +501,36 @@ declare abstract class HttpClient<Client> {
490
501
  /**
491
502
  * Defines conversion and request creation for a remote operation.
492
503
  */
493
- interface RemoteEndpoint<Input, InputDto, Output, OutputDto, Client> {
504
+ interface RemoteEndpoint<Input, InputDto, Output, OutputDto> {
494
505
  /** Converts operation input to the request DTO. */
495
506
  convertInput(input: Input): Promise<InputDto>;
496
507
  /** Creates the HTTP request for the converted input. */
497
- makeRequest(input: InputDto): HttpRequest<Client, OutputDto>;
508
+ makeRequest(input: InputDto): HttpRequest<OutputDto>;
498
509
  /** Converts the response DTO to the operation output. */
499
510
  convertOutput(response: OutputDto): Promise<Output>;
500
511
  }
501
512
  //#endregion
502
513
  //#region src/networking/remote-resource.d.ts
503
- declare abstract class RemoteResource<Input, Output, Client> implements AsyncOperation<Input, Output, HttpRequestOptions> {
504
- protected readonly endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>;
505
- protected readonly httpClient: HttpClient<Client>;
506
- protected constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
514
+ declare abstract class RemoteResource<Input, Output> implements AsyncOperation<Input, Output, HttpRequestOptions> {
515
+ protected readonly endpoint: RemoteEndpoint<Input, unknown, Output, unknown>;
516
+ protected readonly httpClient: HttpClient;
517
+ protected constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
507
518
  execute(input: Input, options?: HttpRequestOptions): Promise<Output>;
508
519
  private convertOrThrow;
509
520
  }
510
521
  //#endregion
511
- //#region src/networking/public-remote-resource.d.ts
512
- declare class PublicRemoteResource<Input, Output, Client> extends RemoteResource<Input, Output, Client> {
513
- constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
522
+ //#region src/networking/remote-resource-public.d.ts
523
+ declare class PublicRemoteResource<Input, Output> extends RemoteResource<Input, Output> {
524
+ constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
514
525
  }
515
526
  //#endregion
516
- //#region src/networking/secured-remote-resource.d.ts
517
- declare class SecuredRemoteResource<Input, Output, Client> extends RemoteResource<Input, Output, Client> {
518
- constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
527
+ //#region src/networking/remote-resource-secured.d.ts
528
+ declare class SecuredRemoteResource<Input, Output> extends RemoteResource<Input, Output> {
529
+ constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
519
530
  execute(input: Input, options?: HttpRequestOptions): Promise<Output>;
520
531
  }
521
532
  //#endregion
522
533
  //#region src/index.d.ts
523
534
  declare function webkitAssembly(): Assembly[];
524
535
  //#endregion
525
- export { AsyncQueue, AsyncQueueImpl, AsyncQueueMode, HttpClient, HttpClientOptions, HttpError, HttpErrorOptions, HttpRequest, HttpRequestInterceptor, HttpRequestInterceptorPipeline, HttpRequestOptions, PublicRemoteResource, RemoteEndpoint, RemoteResource, SecuredRemoteResource, TableDataModel, TablePaginationModel, UnauthorizedHandler, UnauthorizedOptions, WebKitL10nResource, WebKitSymbols, webkitAssembly };
536
+ export { AsyncQueue, AsyncQueueImpl, AsyncQueueMode, HttpClient, HttpClientOptions, HttpError, HttpErrorOptions, HttpRequest, HttpRequestInterceptor, HttpRequestInterceptorPipeline, HttpRequestOptions, PublicRemoteResource, RemoteEndpoint, RemoteResource, SecuredRemoteResource, TableDataModel, TablePaginationModel, UnauthorizedHandler, UnauthorizedOptions, WebKitL10nResource, WebKitSymbols, defineHttpRequest, webkitAssembly };
@@ -373,11 +373,11 @@ interface HttpRequestOptions {
373
373
  }
374
374
  //#endregion
375
375
  //#region src/networking/http-request.d.ts
376
- interface HttpRequest<Client, Output> {
376
+ interface HttpRequest<Output> {
377
377
  /**
378
- * Executes the request using the configured client.
378
+ * Executes the request using the client created by the configured HTTP client.
379
379
  */
380
- readonly execute: (client: Client) => Promise<Output>;
380
+ readonly execute: (client: unknown) => Promise<Output>;
381
381
  /**
382
382
  * Options applied specifically to this request.
383
383
  *
@@ -385,6 +385,11 @@ interface HttpRequest<Client, Output> {
385
385
  */
386
386
  readonly options?: HttpRequestOptions;
387
387
  }
388
+ /**
389
+ * Creates a transport-typed HTTP request while keeping the transport type internal
390
+ * to the request implementation.
391
+ */
392
+ declare function defineHttpRequest<Client, Output>(execute: (client: Client) => Promise<Output>, options?: HttpRequestOptions): HttpRequest<Output>;
388
393
  //#endregion
389
394
  //#region src/networking/http-request-interceptor.d.ts
390
395
  /**
@@ -405,28 +410,34 @@ declare class HttpRequestInterceptorPipeline {
405
410
  //#endregion
406
411
  //#region src/networking/http-error.d.ts
407
412
  interface HttpErrorOptions {
408
- /** HTTP status code returned by the remote system. */
413
+ /** HTTP status code. */
409
414
  readonly statusCode: number;
410
- /** Machine-readable error code for programmatic handling. */
411
- readonly code: string;
412
- /** Human-readable error description. */
413
- readonly message: string;
414
415
  /**
415
- * Structured error details.
416
- *
416
+ * Error code.
417
417
  * @default undefined
418
+ * @example "not_found"
418
419
  */
419
- readonly details?: Readonly<Record<string, string[]>>;
420
+ readonly code?: string;
420
421
  /**
421
- * Original transport error.
422
- *
422
+ * Error message.
423
+ * @default undefined
424
+ * @example "Not found"
425
+ */
426
+ readonly message?: string;
427
+ /**
428
+ * Error details.
429
+ * @default undefined
430
+ */
431
+ readonly details?: unknown;
432
+ /**
433
+ * Original error.
423
434
  * @default undefined
424
435
  */
425
436
  readonly cause?: unknown;
426
437
  }
427
438
  declare class HttpError extends Error {
428
439
  readonly statusCode: HttpErrorOptions['statusCode'];
429
- readonly code: HttpErrorOptions['code'];
440
+ readonly code?: HttpErrorOptions['code'];
430
441
  readonly details?: HttpErrorOptions['details'];
431
442
  constructor(options: HttpErrorOptions);
432
443
  }
@@ -471,15 +482,15 @@ interface HttpClientOptions {
471
482
  */
472
483
  readonly unauthorized?: UnauthorizedOptions;
473
484
  }
474
- declare abstract class HttpClient<Client> {
485
+ declare abstract class HttpClient {
475
486
  private readonly requestOptions;
476
487
  private readonly interceptorPipeline;
477
488
  readonly asyncQueue: AsyncQueue;
478
489
  readonly unauthorized?: UnauthorizedOptions;
479
490
  constructor(options?: HttpClientOptions);
480
- execute<Output>(request: HttpRequest<Client, Output>, options?: HttpRequestOptions): Promise<Output>;
481
- /** Creates the concrete client for the resolved request options. */
482
- protected abstract createClient(options: HttpRequestOptions): Client;
491
+ execute<Output>(request: HttpRequest<Output>, options?: HttpRequestOptions): Promise<Output>;
492
+ /** Creates the concrete transport client for the resolved request options. */
493
+ protected abstract createClient(options: HttpRequestOptions): unknown;
483
494
  /** Maps a transport-specific failure to a BuildPlease error. */
484
495
  protected handleError(error: unknown): Error;
485
496
  private makeRequestOptions;
@@ -490,36 +501,36 @@ declare abstract class HttpClient<Client> {
490
501
  /**
491
502
  * Defines conversion and request creation for a remote operation.
492
503
  */
493
- interface RemoteEndpoint<Input, InputDto, Output, OutputDto, Client> {
504
+ interface RemoteEndpoint<Input, InputDto, Output, OutputDto> {
494
505
  /** Converts operation input to the request DTO. */
495
506
  convertInput(input: Input): Promise<InputDto>;
496
507
  /** Creates the HTTP request for the converted input. */
497
- makeRequest(input: InputDto): HttpRequest<Client, OutputDto>;
508
+ makeRequest(input: InputDto): HttpRequest<OutputDto>;
498
509
  /** Converts the response DTO to the operation output. */
499
510
  convertOutput(response: OutputDto): Promise<Output>;
500
511
  }
501
512
  //#endregion
502
513
  //#region src/networking/remote-resource.d.ts
503
- declare abstract class RemoteResource<Input, Output, Client> implements AsyncOperation<Input, Output, HttpRequestOptions> {
504
- protected readonly endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>;
505
- protected readonly httpClient: HttpClient<Client>;
506
- protected constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
514
+ declare abstract class RemoteResource<Input, Output> implements AsyncOperation<Input, Output, HttpRequestOptions> {
515
+ protected readonly endpoint: RemoteEndpoint<Input, unknown, Output, unknown>;
516
+ protected readonly httpClient: HttpClient;
517
+ protected constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
507
518
  execute(input: Input, options?: HttpRequestOptions): Promise<Output>;
508
519
  private convertOrThrow;
509
520
  }
510
521
  //#endregion
511
- //#region src/networking/public-remote-resource.d.ts
512
- declare class PublicRemoteResource<Input, Output, Client> extends RemoteResource<Input, Output, Client> {
513
- constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
522
+ //#region src/networking/remote-resource-public.d.ts
523
+ declare class PublicRemoteResource<Input, Output> extends RemoteResource<Input, Output> {
524
+ constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
514
525
  }
515
526
  //#endregion
516
- //#region src/networking/secured-remote-resource.d.ts
517
- declare class SecuredRemoteResource<Input, Output, Client> extends RemoteResource<Input, Output, Client> {
518
- constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown, Client>, httpClient: HttpClient<Client>);
527
+ //#region src/networking/remote-resource-secured.d.ts
528
+ declare class SecuredRemoteResource<Input, Output> extends RemoteResource<Input, Output> {
529
+ constructor(endpoint: RemoteEndpoint<Input, unknown, Output, unknown>, httpClient: HttpClient);
519
530
  execute(input: Input, options?: HttpRequestOptions): Promise<Output>;
520
531
  }
521
532
  //#endregion
522
533
  //#region src/index.d.ts
523
534
  declare function webkitAssembly(): Assembly[];
524
535
  //#endregion
525
- export { AsyncQueue, AsyncQueueImpl, AsyncQueueMode, HttpClient, HttpClientOptions, HttpError, HttpErrorOptions, HttpRequest, HttpRequestInterceptor, HttpRequestInterceptorPipeline, HttpRequestOptions, PublicRemoteResource, RemoteEndpoint, RemoteResource, SecuredRemoteResource, TableDataModel, TablePaginationModel, UnauthorizedHandler, UnauthorizedOptions, WebKitL10nResource, WebKitSymbols, webkitAssembly };
536
+ export { AsyncQueue, AsyncQueueImpl, AsyncQueueMode, HttpClient, HttpClientOptions, HttpError, HttpErrorOptions, HttpRequest, HttpRequestInterceptor, HttpRequestInterceptorPipeline, HttpRequestOptions, PublicRemoteResource, RemoteEndpoint, RemoteResource, SecuredRemoteResource, TableDataModel, TablePaginationModel, UnauthorizedHandler, UnauthorizedOptions, WebKitL10nResource, WebKitSymbols, defineHttpRequest, webkitAssembly };
package/dist/src/index.js CHANGED
@@ -1 +1 @@
1
- import"reflect-metadata";import{CanceledError as e,ConversionError as t,CoreL10nResource as n,NetworkError as r,TimeoutError as i,UnknownError as a,coreAssembly as o}from"@buildplease/core";import{injectable as s,unmanaged as c}from"inversify";export*from"@buildplease/core";function l(){return[]}`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}`;const u={DI:{}},d=n;var f=class{mode;pendingEntries=[];activeEntries=new Set;interruption;isSerialOperationRunning=!1;constructor(e=`parallel`){this.mode=e}execute(t){if(this.interruption)return Promise.reject(new e);let n=this.createEntry(t);return this.mode===`serial`?(this.pendingEntries.push(n),this.startNextSerialOperation()):this.startEntry(n),n.promise}cancelAll(e){let t=this.pendingEntries.splice(0);for(let n of t)this.cancelEntry(n,e);for(let t of this.activeEntries)this.cancelEntry(t,e)}async interrupt(e){if(!this.interruption){let t=Promise.resolve().then(e).finally(()=>{this.interruption===t&&(this.interruption=void 0,this.startNextSerialOperation())});this.interruption=t,this.cancelAll()}await this.interruption}createEntry(e){let t,n;return{operation:e,promise:new Promise((e,r)=>{t=e,n=r}),resolve:e=>t?.(e),reject:e=>n?.(e),canceled:!1,settled:!1}}startEntry(e){if(e.canceled||this.interruption){this.cancelEntry(e);return}this.activeEntries.add(e),this.mode===`serial`&&(this.isSerialOperationRunning=!0),Promise.resolve().then(e.operation).then(t=>{e.canceled||this.resolveEntry(e,t)},t=>{e.canceled||this.rejectEntry(e,t)}).finally(()=>{this.activeEntries.delete(e),this.mode===`serial`&&(this.isSerialOperationRunning=!1,this.startNextSerialOperation())})}startNextSerialOperation(){if(this.mode!==`serial`||this.isSerialOperationRunning||this.interruption)return;let e=this.pendingEntries.shift();e&&this.startEntry(e)}cancelEntry(t,n){t.canceled||(t.canceled=!0,t.settled||this.rejectEntry(t,new e({cause:n})))}resolveEntry(e,t){e.settled||(e.settled=!0,e.resolve(t))}rejectEntry(e,t){e.settled||(e.settled=!0,e.reject(t))}},p=class extends Error{statusCode;code;details;constructor(e){super(e.message),this.name=`HttpError`,this.statusCode=e.statusCode,this.code=e.code,this.details=e.details,e.cause!==void 0&&(this.cause=e.cause)}},m=class{interceptors;constructor(e=[],t){this.interceptors=this.resolveInterceptors(e,t)}async intercept(e){let t=e;for(let e of this.interceptors)t=await e.intercept(t);return t}resolveInterceptors(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i.identity)){t?.(`Duplicate HTTP request interceptor ignored: ${String(i.identity)}`);continue}n.add(i.identity),r.push(i)}return Object.freeze(r)}};const h={credentials:!0,headers:{}};var g=class{requestOptions;interceptorPipeline;asyncQueue;unauthorized;constructor(e={}){this.requestOptions=e.requestOptions??{},this.interceptorPipeline=e.interceptorPipeline??new m,this.asyncQueue=e.asyncQueue??new f,this.unauthorized=e.unauthorized}execute(e,t){return this.asyncQueue.execute(async()=>{let n=await this.makeRequestOptions(e,t);try{let t=this.createClient(n);return await e.execute(t)}catch(e){throw this.handleError(e)}})}handleError(t){return t instanceof p||t instanceof r||t instanceof i||t instanceof e||t instanceof a?t:new a({message:t instanceof Error?t.message:void 0,cause:t})}async makeRequestOptions(e,t){let n=this.mergeRequestOptions(h,this.requestOptions);return n=await this.interceptorPipeline.intercept(n),n=this.mergeRequestOptions(n,e.options),n=this.mergeRequestOptions(n,t),n}mergeRequestOptions(e,t){return t?{credentials:t.credentials??e.credentials,headers:{...e.headers,...t.headers}}:e}};function _(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=class{endpoint;httpClient;constructor(e,t){this.endpoint=e,this.httpClient=t}async execute(e,t){let n=await this.convertOrThrow(()=>this.endpoint.convertInput(e)),r=this.endpoint.makeRequest(n),i=await this.httpClient.execute(r,t);return await this.convertOrThrow(()=>this.endpoint.convertOutput(i))}async convertOrThrow(e){try{return await e()}catch(e){throw new t({cause:e})}}};b=y([s(),v(0,c()),v(1,c()),_(`design:paramtypes`,[Object,Object])],b);let x=class extends b{constructor(e,t){super(e,t)}};x=y([s(),_(`design:paramtypes`,[Object,Object])],x);let S=class extends b{constructor(e,t){super(e,t)}async execute(t,n){try{return await super.execute(t,n)}catch(t){if(!(t instanceof p))throw t;let n=this.httpClient.unauthorized;throw!n||!n.statusCodes.includes(t.statusCode)?t:n.cancelAll?(await this.httpClient.asyncQueue.interrupt(()=>n.handler.handle(t)),new e({cause:t})):(await n.handler.handle(t),t)}}};S=y([s(),_(`design:paramtypes`,[Object,Object])],S);function C(){let e=o(),t=l();return[...e,...t]}export{f as AsyncQueueImpl,g as HttpClient,p as HttpError,m as HttpRequestInterceptorPipeline,x as PublicRemoteResource,b as RemoteResource,S as SecuredRemoteResource,d as WebKitL10nResource,u as WebKitSymbols,C as webkitAssembly};
1
+ import"reflect-metadata";import{CanceledError as e,ConversionError as t,CoreL10nResource as n,NetworkError as r,TimeoutError as i,UnknownError as a,coreAssembly as o}from"@buildplease/core";import{injectable as s,unmanaged as c}from"inversify";export*from"@buildplease/core";function l(){return[]}`${{name:`buildplease`,displayName:`BuildPlease`,scope:`@buildplease`}.name}`;const u={DI:{}},d=n;var f=class{mode;pendingEntries=[];activeEntries=new Set;interruption;isSerialOperationRunning=!1;constructor(e=`parallel`){this.mode=e}execute(t){if(this.interruption)return Promise.reject(new e);let n=this.createEntry(t);return this.mode===`serial`?(this.pendingEntries.push(n),this.startNextSerialOperation()):this.startEntry(n),n.promise}cancelAll(e){let t=this.pendingEntries.splice(0);for(let n of t)this.cancelEntry(n,e);for(let t of this.activeEntries)this.cancelEntry(t,e)}async interrupt(e){if(!this.interruption){let t=Promise.resolve().then(e).finally(()=>{this.interruption===t&&(this.interruption=void 0,this.startNextSerialOperation())});this.interruption=t,this.cancelAll()}await this.interruption}createEntry(e){let t,n;return{operation:e,promise:new Promise((e,r)=>{t=e,n=r}),resolve:e=>t?.(e),reject:e=>n?.(e),canceled:!1,settled:!1}}startEntry(e){if(e.canceled||this.interruption){this.cancelEntry(e);return}this.activeEntries.add(e),this.mode===`serial`&&(this.isSerialOperationRunning=!0),Promise.resolve().then(e.operation).then(t=>{e.canceled||this.resolveEntry(e,t)},t=>{e.canceled||this.rejectEntry(e,t)}).finally(()=>{this.activeEntries.delete(e),this.mode===`serial`&&(this.isSerialOperationRunning=!1,this.startNextSerialOperation())})}startNextSerialOperation(){if(this.mode!==`serial`||this.isSerialOperationRunning||this.interruption)return;let e=this.pendingEntries.shift();e&&this.startEntry(e)}cancelEntry(t,n){t.canceled||(t.canceled=!0,t.settled||this.rejectEntry(t,new e({cause:n})))}resolveEntry(e,t){e.settled||(e.settled=!0,e.resolve(t))}rejectEntry(e,t){e.settled||(e.settled=!0,e.reject(t))}},p=class extends Error{statusCode;code;details;constructor(e){super(e.message),this.name=`HttpError`,this.statusCode=e.statusCode,this.code=e.code,this.details=e.details,e.cause!==void 0&&(this.cause=e.cause)}},m=class{interceptors;constructor(e=[],t){this.interceptors=this.resolveInterceptors(e,t)}async intercept(e){let t=e;for(let e of this.interceptors)t=await e.intercept(t);return t}resolveInterceptors(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i.identity)){t?.(`Duplicate HTTP request interceptor ignored: ${String(i.identity)}`);continue}n.add(i.identity),r.push(i)}return Object.freeze(r)}};const h={credentials:!0,headers:{}};var g=class{requestOptions;interceptorPipeline;asyncQueue;unauthorized;constructor(e={}){this.requestOptions=e.requestOptions??{},this.interceptorPipeline=e.interceptorPipeline??new m,this.asyncQueue=e.asyncQueue??new f,this.unauthorized=e.unauthorized}execute(e,t){return this.asyncQueue.execute(async()=>{let n=await this.makeRequestOptions(e,t);try{let t=this.createClient(n);return await e.execute(t)}catch(e){throw this.handleError(e)}})}handleError(t){return t instanceof p||t instanceof r||t instanceof i||t instanceof e||t instanceof a?t:new a({message:t instanceof Error?t.message:void 0,cause:t})}async makeRequestOptions(e,t){let n=this.mergeRequestOptions(h,this.requestOptions);return n=await this.interceptorPipeline.intercept(n),n=this.mergeRequestOptions(n,e.options),n=this.mergeRequestOptions(n,t),n}mergeRequestOptions(e,t){return t?{credentials:t.credentials??e.credentials,headers:{...e.headers,...t.headers}}:e}};function _(e,t){return{execute:t=>e(t),options:t}}function v(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class{endpoint;httpClient;constructor(e,t){this.endpoint=e,this.httpClient=t}async execute(e,t){let n=await this.convertOrThrow(()=>this.endpoint.convertInput(e)),r=this.endpoint.makeRequest(n),i=await this.httpClient.execute(r,t);return await this.convertOrThrow(()=>this.endpoint.convertOutput(i))}async convertOrThrow(e){try{return await e()}catch(e){throw new t({cause:e})}}};x=b([s(),y(0,c()),y(1,c()),v(`design:paramtypes`,[Object,Object])],x);let S=class extends x{constructor(e,t){super(e,t)}};S=b([s(),v(`design:paramtypes`,[Object,Object])],S);let C=class extends x{constructor(e,t){super(e,t)}async execute(t,n){try{return await super.execute(t,n)}catch(t){if(!(t instanceof p))throw t;let n=this.httpClient.unauthorized;throw!n||!n.statusCodes.includes(t.statusCode)?t:n.cancelAll?(await this.httpClient.asyncQueue.interrupt(()=>n.handler.handle(t)),new e({cause:t})):(await n.handler.handle(t),t)}}};C=b([s(),v(`design:paramtypes`,[Object,Object])],C);function w(){let e=o(),t=l();return[...e,...t]}export{f as AsyncQueueImpl,g as HttpClient,p as HttpError,m as HttpRequestInterceptorPipeline,S as PublicRemoteResource,x as RemoteResource,C as SecuredRemoteResource,d as WebKitL10nResource,u as WebKitSymbols,_ as defineHttpRequest,w as webkitAssembly};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildplease/webkit",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "keywords": [],
5
5
  "repository": {
6
6
  "type": "git",