@acorex/platform 20.5.0-next.0 → 20.5.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4412,6 +4412,131 @@ class AXPEntitySearchDefinitionProvider {
4412
4412
  }
4413
4413
  }
4414
4414
 
4415
+ /**
4416
+ * Error type that can be thrown by middlewares to abort the chain with a structured payload.
4417
+ */
4418
+ class AXPMiddlewareAbortError extends Error {
4419
+ constructor(message, options = {}) {
4420
+ super(message);
4421
+ this.message = message;
4422
+ this.options = options;
4423
+ this.name = 'AXPMiddlewareAbortError';
4424
+ }
4425
+ toResponse() {
4426
+ return {
4427
+ success: false,
4428
+ error: {
4429
+ code: this.options.code,
4430
+ message: this.message,
4431
+ status: this.options.status,
4432
+ details: this.options.details,
4433
+ },
4434
+ };
4435
+ }
4436
+ }
4437
+ /** Type guard for AXPMiddlewareAbortError */
4438
+ function isAXPMiddlewareAbortError(error) {
4439
+ return error instanceof AXPMiddlewareAbortError;
4440
+ }
4441
+ //#endregion
4442
+
4443
+ const AXP_ENTITY_STORAGE_BACKEND = new InjectionToken('AXP_ENTITY_STORAGE_BACKEND');
4444
+ const AXP_ENTITY_STORAGE_MIDDLEWARE = new InjectionToken('AXP_ENTITY_STORAGE_MIDDLEWARE');
4445
+
4446
+ class AXPMiddlewareEntityStorageService extends AXPEntityStorageService {
4447
+ constructor() {
4448
+ super(...arguments);
4449
+ this.backend = inject(AXP_ENTITY_STORAGE_BACKEND);
4450
+ this.allMiddlewares = (inject(AXP_ENTITY_STORAGE_MIDDLEWARE, { optional: true }) || []).slice();
4451
+ this.injector = inject(EnvironmentInjector);
4452
+ }
4453
+ get dbName() {
4454
+ return this.backend.dbName;
4455
+ }
4456
+ filterMiddlewares(ctx) {
4457
+ return this.allMiddlewares
4458
+ .filter((mw) => {
4459
+ const t = mw.target;
4460
+ if (!t)
4461
+ return true;
4462
+ if (t.ops && !t.ops.includes(ctx.op))
4463
+ return false;
4464
+ if (t.entity) {
4465
+ if (typeof t.entity === 'string' && t.entity !== ctx.entityName)
4466
+ return false;
4467
+ if (t.entity instanceof RegExp && !t.entity.test(ctx.entityName))
4468
+ return false;
4469
+ }
4470
+ if (t.predicate && !t.predicate(ctx))
4471
+ return false;
4472
+ return true;
4473
+ })
4474
+ .sort((a, b) => (a.target?.order ?? 0) - (b.target?.order ?? 0));
4475
+ }
4476
+ compose(mws, leaf, ctx) {
4477
+ return mws
4478
+ .slice()
4479
+ .reverse()
4480
+ .reduce((next, mw) => {
4481
+ return async () => runInInjectionContext(this.injector, () => mw.execute(ctx, next));
4482
+ }, leaf);
4483
+ }
4484
+ async run(ctx, delegate) {
4485
+ const chain = this.compose(this.filterMiddlewares(ctx), async () => {
4486
+ ctx.result = await delegate();
4487
+ }, ctx);
4488
+ await chain();
4489
+ return ctx.result;
4490
+ }
4491
+ createCtx(op, entityName, init) {
4492
+ return {
4493
+ op,
4494
+ entityName,
4495
+ locals: new Map(),
4496
+ backend: {
4497
+ getOne: (name, id) => this.backend.getOne(name, id),
4498
+ insertOne: (name, e) => this.backend.insertOne(name, e),
4499
+ query: (name, request) => this.backend.query(name, request),
4500
+ updateOne: (name, id, data) => this.backend.updateOne(name, id, data),
4501
+ },
4502
+ ...init,
4503
+ };
4504
+ }
4505
+ async initial(entityName, collection, options) {
4506
+ const ctx = this.createCtx('initial', entityName, { data: collection });
4507
+ return this.run(ctx, () => this.backend.initial(entityName, ctx.data, options));
4508
+ }
4509
+ async getOne(entityName, id) {
4510
+ const ctx = this.createCtx('getOne', entityName, { id });
4511
+ return this.run(ctx, () => this.backend.getOne(entityName, id));
4512
+ }
4513
+ async updateOne(entityName, id, keyValues) {
4514
+ const ctx = this.createCtx('update', entityName, { id, data: keyValues });
4515
+ return this.run(ctx, () => this.backend.updateOne(entityName, id, ctx.data));
4516
+ }
4517
+ async deleteOne(entityName, id) {
4518
+ const ctx = this.createCtx('delete', entityName, { id });
4519
+ return this.run(ctx, () => this.backend.deleteOne(entityName, id));
4520
+ }
4521
+ async insertOne(entityName, entity) {
4522
+ const ctx = this.createCtx('create', entityName, { data: entity });
4523
+ return this.run(ctx, () => this.backend.insertOne(entityName, ctx.data));
4524
+ }
4525
+ async getAll(entityName) {
4526
+ const ctx = this.createCtx('getAll', entityName);
4527
+ return this.run(ctx, () => this.backend.getAll(entityName));
4528
+ }
4529
+ async query(entityName, request) {
4530
+ const ctx = this.createCtx('query', entityName, { request });
4531
+ return this.run(ctx, () => this.backend.query(entityName, request));
4532
+ }
4533
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
4534
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService }); }
4535
+ }
4536
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService, decorators: [{
4537
+ type: Injectable
4538
+ }] });
4539
+
4415
4540
  //#region ---- Column Mapping Helpers ----
4416
4541
  /**
4417
4542
  * Maps an entity property to a list widget column configuration.
@@ -7080,6 +7205,8 @@ class AXPEntityModule {
7080
7205
  useClass: AXPEntityCommandSearchDefinitionProvider,
7081
7206
  multi: true,
7082
7207
  },
7208
+ // Bind the middleware wrapper as the public storage service
7209
+ { provide: AXPEntityStorageService, useClass: AXPMiddlewareEntityStorageService },
7083
7210
  {
7084
7211
  provide: AXP_ENTITY_MODIFIER,
7085
7212
  useValue: columnWidthMiddlewareProvider,
@@ -7199,6 +7326,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImpor
7199
7326
  useClass: AXPEntityCommandSearchDefinitionProvider,
7200
7327
  multi: true,
7201
7328
  },
7329
+ // Bind the middleware wrapper as the public storage service
7330
+ { provide: AXPEntityStorageService, useClass: AXPMiddlewareEntityStorageService },
7202
7331
  {
7203
7332
  provide: AXP_ENTITY_MODIFIER,
7204
7333
  useValue: columnWidthMiddlewareProvider,
@@ -7604,131 +7733,6 @@ function toCompatFormFieldBuilder(field) {
7604
7733
  };
7605
7734
  }
7606
7735
 
7607
- /**
7608
- * Error type that can be thrown by middlewares to abort the chain with a structured payload.
7609
- */
7610
- class AXPMiddlewareAbortError extends Error {
7611
- constructor(message, options = {}) {
7612
- super(message);
7613
- this.message = message;
7614
- this.options = options;
7615
- this.name = 'AXPMiddlewareAbortError';
7616
- }
7617
- toResponse() {
7618
- return {
7619
- success: false,
7620
- error: {
7621
- code: this.options.code,
7622
- message: this.message,
7623
- status: this.options.status,
7624
- details: this.options.details,
7625
- },
7626
- };
7627
- }
7628
- }
7629
- /** Type guard for AXPMiddlewareAbortError */
7630
- function isAXPMiddlewareAbortError(error) {
7631
- return error instanceof AXPMiddlewareAbortError;
7632
- }
7633
- //#endregion
7634
-
7635
- const AXP_ENTITY_STORAGE_BACKEND = new InjectionToken('AXP_ENTITY_STORAGE_BACKEND');
7636
- const AXP_ENTITY_STORAGE_MIDDLEWARE = new InjectionToken('AXP_ENTITY_STORAGE_MIDDLEWARE');
7637
-
7638
- class AXPMiddlewareEntityStorageService extends AXPEntityStorageService {
7639
- constructor() {
7640
- super(...arguments);
7641
- this.backend = inject(AXP_ENTITY_STORAGE_BACKEND);
7642
- this.allMiddlewares = (inject(AXP_ENTITY_STORAGE_MIDDLEWARE, { optional: true }) || []).slice();
7643
- this.injector = inject(EnvironmentInjector);
7644
- }
7645
- get dbName() {
7646
- return this.backend.dbName;
7647
- }
7648
- filterMiddlewares(ctx) {
7649
- return this.allMiddlewares
7650
- .filter((mw) => {
7651
- const t = mw.target;
7652
- if (!t)
7653
- return true;
7654
- if (t.ops && !t.ops.includes(ctx.op))
7655
- return false;
7656
- if (t.entity) {
7657
- if (typeof t.entity === 'string' && t.entity !== ctx.entityName)
7658
- return false;
7659
- if (t.entity instanceof RegExp && !t.entity.test(ctx.entityName))
7660
- return false;
7661
- }
7662
- if (t.predicate && !t.predicate(ctx))
7663
- return false;
7664
- return true;
7665
- })
7666
- .sort((a, b) => (a.target?.order ?? 0) - (b.target?.order ?? 0));
7667
- }
7668
- compose(mws, leaf, ctx) {
7669
- return mws
7670
- .slice()
7671
- .reverse()
7672
- .reduce((next, mw) => {
7673
- return async () => runInInjectionContext(this.injector, () => mw.execute(ctx, next));
7674
- }, leaf);
7675
- }
7676
- async run(ctx, delegate) {
7677
- const chain = this.compose(this.filterMiddlewares(ctx), async () => {
7678
- ctx.result = await delegate();
7679
- }, ctx);
7680
- await chain();
7681
- return ctx.result;
7682
- }
7683
- createCtx(op, entityName, init) {
7684
- return {
7685
- op,
7686
- entityName,
7687
- locals: new Map(),
7688
- backend: {
7689
- getOne: (name, id) => this.backend.getOne(name, id),
7690
- insertOne: (name, e) => this.backend.insertOne(name, e),
7691
- query: (name, request) => this.backend.query(name, request),
7692
- updateOne: (name, id, data) => this.backend.updateOne(name, id, data),
7693
- },
7694
- ...init,
7695
- };
7696
- }
7697
- async initial(entityName, collection, options) {
7698
- const ctx = this.createCtx('initial', entityName, { data: collection });
7699
- return this.run(ctx, () => this.backend.initial(entityName, ctx.data, options));
7700
- }
7701
- async getOne(entityName, id) {
7702
- const ctx = this.createCtx('getOne', entityName, { id });
7703
- return this.run(ctx, () => this.backend.getOne(entityName, id));
7704
- }
7705
- async updateOne(entityName, id, keyValues) {
7706
- const ctx = this.createCtx('update', entityName, { id, data: keyValues });
7707
- return this.run(ctx, () => this.backend.updateOne(entityName, id, ctx.data));
7708
- }
7709
- async deleteOne(entityName, id) {
7710
- const ctx = this.createCtx('delete', entityName, { id });
7711
- return this.run(ctx, () => this.backend.deleteOne(entityName, id));
7712
- }
7713
- async insertOne(entityName, entity) {
7714
- const ctx = this.createCtx('create', entityName, { data: entity });
7715
- return this.run(ctx, () => this.backend.insertOne(entityName, ctx.data));
7716
- }
7717
- async getAll(entityName) {
7718
- const ctx = this.createCtx('getAll', entityName);
7719
- return this.run(ctx, () => this.backend.getAll(entityName));
7720
- }
7721
- async query(entityName, request) {
7722
- const ctx = this.createCtx('query', entityName, { request });
7723
- return this.run(ctx, () => this.backend.query(entityName, request));
7724
- }
7725
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
7726
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService }); }
7727
- }
7728
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXPMiddlewareEntityStorageService, decorators: [{
7729
- type: Injectable
7730
- }] });
7731
-
7732
7736
  // #region Master
7733
7737
  function entityMasterCreateAction() {
7734
7738
  return {