@venizia/ignis 0.1.1-5 → 0.1.1-7

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 (84) hide show
  1. package/dist/components/auth/authorize/adapters/base-filtered.d.ts +2 -2
  2. package/dist/components/auth/authorize/adapters/base-filtered.d.ts.map +1 -1
  3. package/dist/components/auth/authorize/adapters/base-filtered.js +11 -4
  4. package/dist/components/auth/authorize/adapters/base-filtered.js.map +1 -1
  5. package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.d.ts +84 -48
  6. package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.d.ts.map +1 -1
  7. package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.js +319 -185
  8. package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.js.map +1 -1
  9. package/dist/components/auth/authorize/adapters/types.d.ts +9 -6
  10. package/dist/components/auth/authorize/adapters/types.d.ts.map +1 -1
  11. package/dist/components/auth/authorize/builders/grant.builder.d.ts +74 -0
  12. package/dist/components/auth/authorize/builders/grant.builder.d.ts.map +1 -0
  13. package/dist/components/auth/authorize/builders/grant.builder.js +229 -0
  14. package/dist/components/auth/authorize/builders/grant.builder.js.map +1 -0
  15. package/dist/components/auth/authorize/builders/index.d.ts +4 -0
  16. package/dist/components/auth/authorize/builders/index.d.ts.map +1 -0
  17. package/dist/components/auth/authorize/builders/index.js +20 -0
  18. package/dist/components/auth/authorize/builders/index.js.map +1 -0
  19. package/dist/components/auth/authorize/{common/permission-builder.d.ts → builders/permission.builder.d.ts} +8 -2
  20. package/dist/components/auth/authorize/builders/permission.builder.d.ts.map +1 -0
  21. package/dist/components/auth/authorize/{common/permission-builder.js → builders/permission.builder.js} +16 -2
  22. package/dist/components/auth/authorize/builders/permission.builder.js.map +1 -0
  23. package/dist/components/auth/authorize/{common/policy-builder.d.ts → builders/policy.builder.d.ts} +32 -3
  24. package/dist/components/auth/authorize/builders/policy.builder.d.ts.map +1 -0
  25. package/dist/components/auth/authorize/{common/policy-builder.js → builders/policy.builder.js} +20 -3
  26. package/dist/components/auth/authorize/builders/policy.builder.js.map +1 -0
  27. package/dist/components/auth/authorize/common/constants.d.ts +13 -6
  28. package/dist/components/auth/authorize/common/constants.d.ts.map +1 -1
  29. package/dist/components/auth/authorize/common/constants.js +18 -7
  30. package/dist/components/auth/authorize/common/constants.js.map +1 -1
  31. package/dist/components/auth/authorize/common/index.d.ts +0 -5
  32. package/dist/components/auth/authorize/common/index.d.ts.map +1 -1
  33. package/dist/components/auth/authorize/common/index.js +0 -5
  34. package/dist/components/auth/authorize/common/index.js.map +1 -1
  35. package/dist/components/auth/authorize/common/types.d.ts +20 -1
  36. package/dist/components/auth/authorize/common/types.d.ts.map +1 -1
  37. package/dist/components/auth/authorize/enforcers/casbin.enforcer.d.ts +3 -6
  38. package/dist/components/auth/authorize/enforcers/casbin.enforcer.d.ts.map +1 -1
  39. package/dist/components/auth/authorize/enforcers/casbin.enforcer.js +26 -35
  40. package/dist/components/auth/authorize/enforcers/casbin.enforcer.js.map +1 -1
  41. package/dist/components/auth/authorize/enforcers/enforcer-registry.d.ts +1 -1
  42. package/dist/components/auth/authorize/enforcers/enforcer-registry.js +2 -2
  43. package/dist/components/auth/authorize/enforcers/index.d.ts +1 -0
  44. package/dist/components/auth/authorize/enforcers/index.d.ts.map +1 -1
  45. package/dist/components/auth/authorize/enforcers/index.js +1 -0
  46. package/dist/components/auth/authorize/enforcers/index.js.map +1 -1
  47. package/dist/components/auth/authorize/enforcers/resource-role-manager.d.ts +30 -0
  48. package/dist/components/auth/authorize/enforcers/resource-role-manager.d.ts.map +1 -0
  49. package/dist/components/auth/authorize/enforcers/resource-role-manager.js +123 -0
  50. package/dist/components/auth/authorize/enforcers/resource-role-manager.js.map +1 -0
  51. package/dist/components/auth/authorize/index.d.ts +1 -0
  52. package/dist/components/auth/authorize/index.d.ts.map +1 -1
  53. package/dist/components/auth/authorize/index.js +1 -0
  54. package/dist/components/auth/authorize/index.js.map +1 -1
  55. package/dist/components/auth/authorize/providers/authorization.provider.d.ts.map +1 -1
  56. package/dist/components/auth/authorize/providers/authorization.provider.js +4 -4
  57. package/dist/components/auth/authorize/providers/authorization.provider.js.map +1 -1
  58. package/dist/components/auth/authorize/providers/index.d.ts +1 -0
  59. package/dist/components/auth/authorize/providers/index.d.ts.map +1 -1
  60. package/dist/components/auth/authorize/providers/index.js +1 -0
  61. package/dist/components/auth/authorize/providers/index.js.map +1 -1
  62. package/dist/components/auth/authorize/{common/resolve-request-domain.d.ts → providers/request-domain.d.ts} +2 -2
  63. package/dist/components/auth/authorize/providers/request-domain.d.ts.map +1 -0
  64. package/dist/components/auth/authorize/{common/resolve-request-domain.js → providers/request-domain.js} +2 -2
  65. package/dist/components/auth/authorize/providers/request-domain.js.map +1 -0
  66. package/dist/components/auth/models/entities/policy-definition.model.d.ts +2 -1
  67. package/dist/components/auth/models/entities/policy-definition.model.d.ts.map +1 -1
  68. package/dist/components/auth/models/entities/policy-definition.model.js +2 -0
  69. package/dist/components/auth/models/entities/policy-definition.model.js.map +1 -1
  70. package/package.json +4 -4
  71. package/dist/components/auth/authorize/common/keys.d.ts +0 -6
  72. package/dist/components/auth/authorize/common/keys.d.ts.map +0 -1
  73. package/dist/components/auth/authorize/common/keys.js +0 -12
  74. package/dist/components/auth/authorize/common/keys.js.map +0 -1
  75. package/dist/components/auth/authorize/common/object-match.d.ts +0 -7
  76. package/dist/components/auth/authorize/common/object-match.d.ts.map +0 -1
  77. package/dist/components/auth/authorize/common/object-match.js +0 -19
  78. package/dist/components/auth/authorize/common/object-match.js.map +0 -1
  79. package/dist/components/auth/authorize/common/permission-builder.d.ts.map +0 -1
  80. package/dist/components/auth/authorize/common/permission-builder.js.map +0 -1
  81. package/dist/components/auth/authorize/common/policy-builder.d.ts.map +0 -1
  82. package/dist/components/auth/authorize/common/policy-builder.js.map +0 -1
  83. package/dist/components/auth/authorize/common/resolve-request-domain.d.ts.map +0 -1
  84. package/dist/components/auth/authorize/common/resolve-request-domain.js.map +0 -1
@@ -3,8 +3,8 @@ import { type FilteredAdapter, type Model } from 'casbin';
3
3
  import type { SQL } from 'drizzle-orm';
4
4
  import type { ICasbinPolicyFilter, ICasbinPolicySource, TCasbinPolicyConnector } from './types';
5
5
  /**
6
- * Read-only base for casbin FilteredAdapters backed by a datasource owns the connector plumbing
7
- * and no-op write methods; subclasses only implement {@link loadFilteredPolicy} per principal.
6
+ * Read-only base for casbin FilteredAdapters backed by a datasource - owns connector plumbing
7
+ * and no-op write methods; subclasses implement {@link loadFilteredPolicy} per principal.
8
8
  */
9
9
  export declare abstract class BaseFilteredAdapter<TFilter = ICasbinPolicyFilter> extends BaseHelper implements FilteredAdapter {
10
10
  protected readonly dataSource: ICasbinPolicySource;
@@ -1 +1 @@
1
- {"version":3,"file":"base-filtered.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/base-filtered.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEhG;;;GAGG;AACH,8BAAsB,mBAAmB,CAAC,OAAO,GAAG,mBAAmB,CACrE,SAAQ,UACR,YAAW,eAAe;IAE1B,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;gBAEvC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,mBAAmB,CAAA;KAAE;IAKpE,SAAS,KAAK,SAAS,IAAI,sBAAsB,CAEhD;IAED;;;OAGG;cACa,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE;QAAE,SAAS,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,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EAAE,IAAI,EAAE;QAAE,SAAS,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAKtE,mGAAmG;IACnG,QAAQ,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAEzE,UAAU,IAAI,OAAO;IAKf,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAC3B,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAG9B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAC1B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAC7B,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3C,+FAA+F;cAC/E,SAAS,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAMlF"}
@@ -4,8 +4,8 @@ exports.BaseFilteredAdapter = void 0;
4
4
  const utilities_1 = require("../../../../utilities");
5
5
  const ignis_helpers_1 = require("@venizia/ignis-helpers");
6
6
  /**
7
- * Read-only base for casbin FilteredAdapters backed by a datasource owns the connector plumbing
8
- * and no-op write methods; subclasses only implement {@link loadFilteredPolicy} per principal.
7
+ * Read-only base for casbin FilteredAdapters backed by a datasource - owns connector plumbing
8
+ * and no-op write methods; subclasses implement {@link loadFilteredPolicy} per principal.
9
9
  */
10
10
  class BaseFilteredAdapter extends ignis_helpers_1.BaseHelper {
11
11
  constructor(opts) {
@@ -13,7 +13,14 @@ class BaseFilteredAdapter extends ignis_helpers_1.BaseHelper {
13
13
  this.dataSource = opts.dataSource;
14
14
  }
15
15
  get connector() {
16
- return this.dataSource.connector;
16
+ const source = this.dataSource;
17
+ const resolved = source.getConnector?.() ?? source.connector;
18
+ if (!resolved) {
19
+ throw (0, ignis_helpers_1.getError)({
20
+ message: '[BaseFilteredAdapter] datasource exposes neither a getConnector() accessor nor a wired connector - pass a datasource whose getConnector() lazily wires the driver.',
21
+ });
22
+ }
23
+ return resolved;
17
24
  }
18
25
  /**
19
26
  * Runs a raw statement and returns its rows. Drizzle's `execute()` shape differs per driver
@@ -26,7 +33,7 @@ class BaseFilteredAdapter extends ignis_helpers_1.BaseHelper {
26
33
  isFiltered() {
27
34
  return true;
28
35
  }
29
- // Read-only adapter write methods are intentional no-ops.
36
+ // Read-only adapter - write methods are intentional no-ops.
30
37
  async loadPolicy() { }
31
38
  async savePolicy() {
32
39
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"base-filtered.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/base-filtered.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,0DAAoD;AAKpD;;;GAGG;AACH,MAAsB,mBACpB,SAAQ,0BAAU;IAKlB,YAAY,IAAwD;QAClE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;IAED,IAAc,SAAS;QACrB,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;IACnC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,KAAK,CAAO,IAAwB;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5D,OAAO,IAAA,0BAAc,EAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAKD,UAAU;QACR,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,SAAS,KAAmB,CAAC;IACnC,KAAK,CAAC,YAAY,KAAmB,CAAC;IACtC,KAAK,CAAC,oBAAoB,KAAmB,CAAC;IAE9C,+FAA+F;IACrF,KAAK,CAAC,SAAS,CAAC,IAAuC;QAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AA/CD,kDA+CC"}
1
+ {"version":3,"file":"base-filtered.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/base-filtered.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,0DAA8D;AAK9D;;;GAGG;AACH,MAAsB,mBACpB,SAAQ,0BAAU;IAKlB,YAAY,IAAwD;QAClE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;IAED,IAAc,SAAS;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,EAAE,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC;QAE7D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAA,wBAAQ,EAAC;gBACb,OAAO,EACL,oKAAoK;aACvK,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,KAAK,CAAO,IAAwB;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5D,OAAO,IAAA,0BAAc,EAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAKD,UAAU;QACR,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,SAAS,KAAmB,CAAC;IACnC,KAAK,CAAC,YAAY,KAAmB,CAAC;IACtC,KAAK,CAAC,oBAAoB,KAAmB,CAAC;IAE9C,+FAA+F;IACrF,KAAK,CAAC,SAAS,CAAC,IAAuC;QAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AAzDD,kDAyDC"}
@@ -1,6 +1,8 @@
1
1
  import type { IdType } from '../../../../base';
2
+ import type { TConstValue, TNullable } from '@venizia/ignis-helpers';
2
3
  import { type Model } from 'casbin';
3
4
  import { type SQL } from 'drizzle-orm';
5
+ import { type TCustomGrantMetadata } from '../common';
4
6
  import { BaseFilteredAdapter } from './base-filtered';
5
7
  import type { ICasbinPolicySource, IScopedCasbinEntities } from './types';
6
8
  export interface IScopedCasbinPolicyFilter {
@@ -9,6 +11,30 @@ export interface IScopedCasbinPolicyFilter {
9
11
  id: IdType;
10
12
  };
11
13
  }
14
+ /** A grant row as fetched, before it becomes casbin lines. Permission columns are null when the join misses. */
15
+ export type TGrantRow = {
16
+ subjectId: IdType;
17
+ objectCode: TNullable<string>;
18
+ objectSubject: TNullable<string>;
19
+ objectMethod: TNullable<string>;
20
+ action: TNullable<string>;
21
+ effect: TNullable<string>;
22
+ domain: TNullable<string>;
23
+ metadata?: unknown;
24
+ };
25
+ export declare class PrincipalPolicyEdges {
26
+ static readonly DIRECT = "direct";
27
+ static readonly ROLE_EDGE = "roleEdge";
28
+ static readonly ROLE_GRANT = "roleGrant";
29
+ static readonly DOMAIN_EDGE = "domainEdge";
30
+ }
31
+ /** A row from the single principal-policy statement; `kind` says which branch produced it. */
32
+ export type TPrincipalPolicyRow = TGrantRow & {
33
+ kind: TConstValue<typeof PrincipalPolicyEdges>;
34
+ variant: string;
35
+ targetType: TNullable<string>;
36
+ targetId: IdType;
37
+ };
12
38
  /**
13
39
  * Filtered casbin adapter for the scoped RBAC model: loads ONE principal's edges (role assignments,
14
40
  * memberships, grants) plus the shared structural hierarchy trees as casbin lines. Read-only.
@@ -20,10 +46,20 @@ export declare class ScopedCasbinAdapter extends BaseFilteredAdapter<IScopedCasb
20
46
  entities: IScopedCasbinEntities;
21
47
  });
22
48
  /**
23
- * Casbin's filtered-load entry point: builds the full line set for one principal (role assignments,
24
- * memberships, direct grants, structural trees) then expands the role closure to fetch inherited grants.
49
+ * One wave: the principal-scoped CTE and the merged structural-edges query are issued together.
50
+ * The role closure is resolved in SQL, so nothing here waits on a previous query's result.
25
51
  */
26
52
  loadFilteredPolicy(model: Model, filter: IScopedCasbinPolicyFilter): Promise<void>;
53
+ /** Route one `direct` row to its casbin line, or to the grant batch. */
54
+ protected collectDirectRow(opts: {
55
+ row: TPrincipalPolicyRow;
56
+ principal: {
57
+ type: string;
58
+ id: IdType;
59
+ };
60
+ lines: string[];
61
+ directGrants: TGrantRow[];
62
+ }): void;
27
63
  /** Schema for a table, defaulting to `public`. */
28
64
  protected schemaOf(table: {
29
65
  schemaName?: string;
@@ -37,66 +73,66 @@ export declare class ScopedCasbinAdapter extends BaseFilteredAdapter<IScopedCasb
37
73
  }): SQL;
38
74
  /**
39
75
  * `AND <alias>.<col> IS NULL` when soft-delete is on, else empty. Alias is emitted raw (unquoted) to
40
- * match the unquoted FROM alias quoting it would fold to a different case and break the join.
76
+ * match the unquoted FROM alias - quoting it would fold to a different case and break the join.
41
77
  */
42
78
  protected softDeleteClause(opts: {
43
79
  alias: string;
44
80
  }): SQL;
45
81
  /**
46
- * Fetch the principal's `assign_role` edges as casbin `g` lines, plus the raw `roleIds` for
47
- * {@link expandRoleClosure}. A null domain widens the assignment to every domain (`*`).
82
+ * One statement for everything scoped to a principal: its own edges, the role_inherits edges
83
+ * reachable from its roles, and the grants of that role closure. `UNION` in the recursive term
84
+ * is what terminates a cyclic role graph.
48
85
  */
49
- protected queryRoleAssignments(opts: {
50
- principal: {
51
- type: string;
52
- id: IdType;
53
- };
54
- }): Promise<{
55
- lines: string[];
56
- roleIds: IdType[];
57
- }>;
58
- /**
59
- * Fetch the principal's `join_domain` edges (restricted to `domainTypes`) as casbin `g2` lines —
60
- * the membership relation the matcher uses to scope `ANY_MEMBER` grants.
61
- */
62
- protected queryMemberships(opts: {
86
+ protected queryPrincipalPolicies(opts: {
63
87
  principal: {
64
88
  type: string;
65
89
  id: IdType;
66
90
  };
91
+ }): Promise<TPrincipalPolicyRow[]>;
92
+ /** Turn fetched grant rows into casbin lines. Shared by the direct and role-closure branches. */
93
+ protected buildGrantLines(opts: {
94
+ subjectType: string;
95
+ rows: TGrantRow[];
67
96
  }): Promise<string[]>;
68
- /**
69
- * Fetch `grant` edges for the given subjects joined to `Permission`, as casbin `p` lines. Rows with
70
- * no `action` are skipped; null effect defaults to allow, null domain to `ANY_MEMBER`.
71
- */
72
- protected queryGrants(opts: {
73
- subject: {
74
- type: string;
75
- ids: IdType[];
97
+ /** Why a custom-looking grant row cannot be honoured, or null when it is well formed. */
98
+ protected rejectCustomRow(opts: {
99
+ row: {
100
+ subjectId: IdType;
101
+ objectCode: string;
102
+ objectMethod: string;
76
103
  };
104
+ parsed: TCustomGrantMetadata | null;
105
+ isCustomAction: boolean;
106
+ metadataColumnName?: string;
107
+ }): string | null;
108
+ /** Resolve every custom row's ops in one catalog query, then emit one line per resolved operation. */
109
+ protected expandCustomGrants(opts: {
110
+ subjectType: string;
111
+ customRows: Array<{
112
+ subjectId: IdType;
113
+ objectSubject: string;
114
+ ops: string[];
115
+ domain: string;
116
+ effect: string;
117
+ }>;
77
118
  }): Promise<string[]>;
78
- /** Load the system-wide hierarchy edges (role/resource/action/domain inherits), read fresh every call. */
79
- protected loadStructuralTrees(): Promise<string[]>;
80
- /** Every `role_inherits` edge as a casbin `g` line with a wildcard domain; seeds {@link expandRoleClosure}. */
81
- protected queryRoleInherits(): Promise<string[]>;
82
- /**
83
- * Every `resource_inherits` edge as a casbin `g4` line (resource codes, `obj` axis) — a permission
84
- * on a parent resource also covers its children.
85
- */
86
- protected queryResourceInherits(): Promise<string[]>;
119
+ /** Resolve `(subject, method)` pairs to catalogued operations. One query for the whole extraction. */
120
+ protected queryOperationCatalog(opts: {
121
+ pairs: Array<{
122
+ subject: string;
123
+ method: string;
124
+ }>;
125
+ }): Promise<Array<{
126
+ subject: string;
127
+ method: string;
128
+ code: string;
129
+ action: string;
130
+ }>>;
87
131
  /**
88
- * Every `action_inherits` edge as a casbin `g5` line (`act` axis, e.g. `manage` implies `read`).
89
- * Kept separate from resource_inherits so resource x action doesn't explode into combined edges.
132
+ * The two code-fixed structural trees only (`g4` resource, `g5` action) - a few hundred rows,
133
+ * constant regardless of tenant count. Domain edges (`g3`) are principal-scoped in
134
+ * {@link queryPrincipalPolicies} instead, since that tree grows with the domain count.
90
135
  */
91
- protected queryActionInherits(): Promise<string[]>;
92
- /** Every `domain_inherits` edge as a casbin `g3` line — lets a grant on a parent domain cascade down. */
93
- protected queryDomainInherits(): Promise<string[]>;
94
- /** BFS over role_inherits edges to collect a role set + all transitive parents. Cycle-safe. */
95
- protected expandRoleClosure(opts: {
96
- role: {
97
- ids: IdType[];
98
- edges: string[];
99
- };
100
- }): IdType[];
136
+ protected queryEdgePolicies(): Promise<string[]>;
101
137
  }
102
138
  //# sourceMappingURL=scoped-casbin.adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scoped-casbin.adapter.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/scoped-casbin.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,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CAAC;KACzC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAmCnD;;;OAGG;cACa,gBAAgB,CAAC,IAAI,EAAE;QACrC,SAAS,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;KACzC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA8BrB;;;OAGG;cACa,WAAW,CAAC,IAAI,EAAE;QAChC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;KAC1C,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqDrB,0GAA0G;cAC1F,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAWxD,+GAA+G;cAC/F,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAsBtD;;;OAGG;cACa,qBAAqB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAsB1D;;;OAGG;cACa,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAmBxD,yGAAyG;cACzF,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IA2BxD,+FAA+F;IAC/F,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,EAAE,CAAC;YAAC,KAAK,EAAE,MAAM,EAAE,CAAA;SAAE,CAAA;KAAE,GAAG,MAAM,EAAE;CA0C1F"}
1
+ {"version":3,"file":"scoped-casbin.adapter.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/scoped-casbin.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAA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