@webiny/api-aco-sql 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.292eb6dc15

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.
@@ -0,0 +1,13 @@
1
+ import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
2
+ /** The `aco` schema setup step: the folder-level permissions table. */
3
+ declare class AcoSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {
4
+ private readonly knex;
5
+ private readonly schemaConfig?;
6
+ readonly name = "aco";
7
+ constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
8
+ setup(): Promise<void>;
9
+ }
10
+ export declare const AcoSqlSchemaSetup: typeof AcoSqlSchemaSetupImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core-sql/schemaSetup/abstractions.js").ISqlSchemaSetup>;
12
+ };
13
+ export {};
@@ -0,0 +1,33 @@
1
+ import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
2
+ import { tenantNeutralScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
3
+ import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
4
+ class AcoSqlSchemaSetupImpl {
5
+ constructor(knex, schemaConfig){
6
+ this.knex = knex;
7
+ this.schemaConfig = schemaConfig;
8
+ this.name = "aco";
9
+ }
10
+ setup() {
11
+ const operations = new FolderLevelPermissionsStorageOperations({
12
+ knex: this.knex.client,
13
+ tableNamePrefix: this.schemaConfig?.tableNamePrefix,
14
+ scopeTenant: tenantNeutralScopeTenant
15
+ });
16
+ return operations.setupSchema();
17
+ }
18
+ }
19
+ const AcoSqlSchemaSetup = SqlSchemaSetup.createImplementation({
20
+ implementation: AcoSqlSchemaSetupImpl,
21
+ dependencies: [
22
+ KnexClient,
23
+ [
24
+ SqlSchemaConfig,
25
+ {
26
+ optional: true
27
+ }
28
+ ]
29
+ ]
30
+ });
31
+ export { AcoSqlSchemaSetup };
32
+
33
+ //# sourceMappingURL=AcoSqlSchemaSetup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcoSqlSchemaSetup.js","sources":["../src/AcoSqlSchemaSetup.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from \"@webiny/api-core-sql\";\nimport { tenantNeutralScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** The `aco` schema setup step: the folder-level permissions table. */\nclass AcoSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"aco\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public setup(): Promise<void> {\n const operations = new FolderLevelPermissionsStorageOperations({\n knex: this.knex.client,\n tableNamePrefix: this.schemaConfig?.tableNamePrefix,\n // The setup runs in no tenant, and only creates the table.\n scopeTenant: tenantNeutralScopeTenant\n });\n return operations.setupSchema();\n }\n}\n\nexport const AcoSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: AcoSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["AcoSqlSchemaSetupImpl","knex","schemaConfig","operations","FolderLevelPermissionsStorageOperations","tenantNeutralScopeTenant","AcoSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;AAKA,MAAMA;IAGF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;aAJL,IAAI,GAAG;IAKpB;IAEI,QAAuB;QAC1B,MAAMC,aAAa,IAAIC,wCAAwC;YAC3D,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YACtB,iBAAiB,IAAI,CAAC,YAAY,EAAE;YAEpC,aAAaC;QACjB;QACA,OAAOF,WAAW,WAAW;IACjC;AACJ;AAEO,MAAMG,oBAAoBC,eAAe,oBAAoB,CAAC;IACjE,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -1,20 +1,33 @@
1
1
  import type { Knex } from "knex";
2
2
  import type { AcoFolderLevelPermissionsStorageOperations, FolderLevelPermission, StorageOperationsBatchUpdateFlpParams, StorageOperationsCreateFlpParams, StorageOperationsDeleteFlpParams, StorageOperationsGetFlpParams, StorageOperationsListFlpsParams, StorageOperationsUpdateFlpParams } from "@webiny/api-aco/types.js";
3
+ import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
3
4
  export interface StorageOperationsConfig {
4
5
  knex: Knex;
5
6
  tableNamePrefix?: string;
7
+ /**
8
+ * The schema was set up before the API took traffic (see `SqlSchemaConfig` in
9
+ * `@webiny/api-core-sql`): the table is never checked for or created at runtime.
10
+ */
11
+ schemaManaged?: boolean;
12
+ /** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */
13
+ scopeTenant: ScopeTenant.Interface;
6
14
  }
7
15
  export declare class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {
8
16
  private readonly knex;
9
17
  private readonly tableName;
10
- constructor({ knex, tableNamePrefix }: StorageOperationsConfig);
11
- list({ where: { tenant, type, path_startsWith, parentId } }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]>;
12
- get({ tenant, id }: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null>;
13
- create({ data }: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission>;
18
+ private readonly schemaManaged;
19
+ private readonly scopeTenant;
20
+ constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }: StorageOperationsConfig);
21
+ list({ where }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]>;
22
+ get(params: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null>;
23
+ create(params: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission>;
14
24
  update({ data: inputData, original }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission>;
15
- delete({ flp }: StorageOperationsDeleteFlpParams): Promise<void>;
25
+ delete(params: StorageOperationsDeleteFlpParams): Promise<void>;
16
26
  batchUpdate({ items }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]>;
17
27
  private ensureTable;
28
+ setupSchema(): Promise<void>;
29
+ /** The permission with its scope's tenant, whatever tenant it carries. */
30
+ private inScope;
18
31
  private toRow;
19
32
  private fromRow;
20
33
  }
@@ -1,11 +1,15 @@
1
1
  import { WebinyError } from "@webiny/error";
2
2
  const BASE_TABLE_NAME = "webiny_aco_flp";
3
3
  class FolderLevelPermissionsStorageOperations {
4
- constructor({ knex, tableNamePrefix }){
4
+ constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }){
5
5
  this.knex = knex;
6
+ this.scopeTenant = scopeTenant;
7
+ this.schemaManaged = true === schemaManaged;
6
8
  this.tableName = tableNamePrefix ? `${tableNamePrefix}_${BASE_TABLE_NAME}` : BASE_TABLE_NAME;
7
9
  }
8
- async list({ where: { tenant, type, path_startsWith, parentId } }) {
10
+ async list({ where }) {
11
+ const { type, path_startsWith, parentId } = where;
12
+ const tenant = this.scopeTenant.getId();
9
13
  try {
10
14
  await this.ensureTable();
11
15
  if (parentId) {
@@ -16,6 +20,10 @@ class FolderLevelPermissionsStorageOperations {
16
20
  const rows = await this.knex(this.tableName).where("tenant", tenant).andWhere("type", type).andWhere("path", "like", path_startsWith + "%");
17
21
  return rows.map((row)=>this.fromRow(row));
18
22
  }
23
+ if (type) {
24
+ const rows = await this.knex(this.tableName).where("tenant", tenant).andWhere("type", type);
25
+ return rows.map((row)=>this.fromRow(row));
26
+ }
19
27
  throw new WebinyError("Missing required parameters.", "LIST_FLP_MISSING_PARAMETERS", {
20
28
  tenant,
21
29
  type,
@@ -29,7 +37,9 @@ class FolderLevelPermissionsStorageOperations {
29
37
  });
30
38
  }
31
39
  }
32
- async get({ tenant, id }) {
40
+ async get(params) {
41
+ const { id } = params;
42
+ const tenant = this.scopeTenant.getId();
33
43
  try {
34
44
  await this.ensureTable();
35
45
  const row = await this.knex(this.tableName).where("tenant", tenant).andWhere("id", id).first();
@@ -46,7 +56,8 @@ class FolderLevelPermissionsStorageOperations {
46
56
  });
47
57
  }
48
58
  }
49
- async create({ data }) {
59
+ async create(params) {
60
+ const data = this.inScope(params.data);
50
61
  try {
51
62
  await this.ensureTable();
52
63
  await this.knex(this.tableName).insert(this.toRow(data));
@@ -62,12 +73,12 @@ class FolderLevelPermissionsStorageOperations {
62
73
  }
63
74
  }
64
75
  async update({ data: inputData, original }) {
76
+ const data = this.inScope({
77
+ ...original,
78
+ ...inputData
79
+ });
65
80
  try {
66
81
  await this.ensureTable();
67
- const data = {
68
- ...original,
69
- ...inputData
70
- };
71
82
  await this.knex(this.tableName).where("tenant", data.tenant).andWhere("id", data.id).update(this.toRow(data));
72
83
  return data;
73
84
  } catch (err) {
@@ -81,7 +92,8 @@ class FolderLevelPermissionsStorageOperations {
81
92
  });
82
93
  }
83
94
  }
84
- async delete({ flp }) {
95
+ async delete(params) {
96
+ const flp = this.inScope(params.flp);
85
97
  try {
86
98
  await this.ensureTable();
87
99
  await this.knex(this.tableName).where("tenant", flp.tenant).andWhere("id", flp.id).delete();
@@ -96,20 +108,20 @@ class FolderLevelPermissionsStorageOperations {
96
108
  }
97
109
  }
98
110
  async batchUpdate({ items }) {
111
+ const scopedItems = items.map(({ original, data: inputData })=>this.inScope({
112
+ ...original,
113
+ ...inputData
114
+ }));
99
115
  try {
100
116
  await this.ensureTable();
101
- const updatedItems = [];
102
- await this.knex.transaction(async (trx)=>{
103
- for (const { original, data: inputData } of items){
104
- const data = {
105
- ...original,
106
- ...inputData
107
- };
117
+ return await this.knex.transaction(async (trx)=>{
118
+ const updatedItems = [];
119
+ for (const data of scopedItems){
108
120
  await trx(this.tableName).where("tenant", data.tenant).andWhere("id", data.id).update(this.toRow(data));
109
121
  updatedItems.push(data);
110
122
  }
123
+ return updatedItems;
111
124
  });
112
- return updatedItems;
113
125
  } catch (err) {
114
126
  throw WebinyError.from(err, {
115
127
  message: "Could not batch update folder level permissions.",
@@ -121,6 +133,10 @@ class FolderLevelPermissionsStorageOperations {
121
133
  }
122
134
  }
123
135
  async ensureTable() {
136
+ if (this.schemaManaged) return;
137
+ await this.setupSchema();
138
+ }
139
+ async setupSchema() {
124
140
  const exists = await this.knex.schema.hasTable(this.tableName);
125
141
  if (exists) return;
126
142
  await this.knex.schema.createTable(this.tableName, (table)=>{
@@ -137,6 +153,12 @@ class FolderLevelPermissionsStorageOperations {
137
153
  ]);
138
154
  });
139
155
  }
156
+ inScope(record) {
157
+ return {
158
+ ...record,
159
+ tenant: this.scopeTenant.getId()
160
+ };
161
+ }
140
162
  toRow(data) {
141
163
  return {
142
164
  id: data.id,
@@ -1 +1 @@
1
- {"version":3,"file":"FolderLevelPermissionsStorageOperations.js","sources":["../src/FolderLevelPermissionsStorageOperations.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n AcoFolderLevelPermissionsStorageOperations,\n FolderLevelPermission,\n StorageOperationsBatchUpdateFlpParams,\n StorageOperationsCreateFlpParams,\n StorageOperationsDeleteFlpParams,\n StorageOperationsGetFlpParams,\n StorageOperationsListFlpsParams,\n StorageOperationsUpdateFlpParams\n} from \"@webiny/api-aco/types.js\";\n\ninterface FlpRow {\n id: string;\n tenant: string;\n type: string;\n slug: string;\n path: string;\n parentId: string;\n permissions: string;\n}\n\nconst BASE_TABLE_NAME = \"webiny_aco_flp\";\n\nexport interface StorageOperationsConfig {\n knex: Knex;\n tableNamePrefix?: string;\n}\n\nexport class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {\n private readonly knex: Knex;\n private readonly tableName: string;\n\n constructor({ knex, tableNamePrefix }: StorageOperationsConfig) {\n this.knex = knex;\n this.tableName = tableNamePrefix\n ? `${tableNamePrefix}_${BASE_TABLE_NAME}`\n : BASE_TABLE_NAME;\n }\n\n public async list({\n where: { tenant, type, path_startsWith, parentId }\n }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]> {\n try {\n await this.ensureTable();\n\n if (parentId) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"parentId\", parentId);\n\n return rows.map(row => this.fromRow(row));\n }\n\n if (path_startsWith) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type)\n .andWhere(\"path\", \"like\", path_startsWith + \"%\");\n\n return rows.map(row => this.fromRow(row));\n }\n\n throw new WebinyError(\"Missing required parameters.\", \"LIST_FLP_MISSING_PARAMETERS\", {\n tenant,\n type,\n path_startsWith,\n parentId\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list folder level permissions.\",\n code: \"LIST_FLP_ERROR\"\n });\n }\n }\n\n public async get({\n tenant,\n id\n }: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null> {\n try {\n await this.ensureTable();\n\n const row = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"id\", id)\n .first();\n\n if (!row) {\n return null;\n }\n\n return this.fromRow(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load folder level permission.\",\n code: \"GET_FLP_ERROR\",\n data: { tenant, id }\n });\n }\n }\n\n public async create({\n data\n }: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission> {\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName).insert(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create folder level permission.\",\n code: \"CREATE_FLP_ERROR\",\n data: { data }\n });\n }\n }\n\n public async update({\n data: inputData,\n original\n }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission> {\n try {\n await this.ensureTable();\n\n const data = {\n ...original,\n ...inputData\n };\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update folder level permission.\",\n code: \"UPDATE_FLP_ERROR\",\n data: { inputData, original }\n });\n }\n }\n\n public async delete({ flp }: StorageOperationsDeleteFlpParams): Promise<void> {\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", flp.tenant)\n .andWhere(\"id\", flp.id)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete folder level permission.\",\n code: \"DELETE_FLP_ERROR\",\n data: { flp }\n });\n }\n }\n\n public async batchUpdate({\n items\n }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]> {\n try {\n await this.ensureTable();\n\n const updatedItems: FolderLevelPermission[] = [];\n\n await this.knex.transaction(async trx => {\n for (const { original, data: inputData } of items) {\n const data = {\n ...original,\n ...inputData\n };\n\n await trx<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n updatedItems.push(data);\n }\n });\n\n return updatedItems;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not batch update folder level permissions.\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: { items }\n });\n }\n }\n\n private async ensureTable(): Promise<void> {\n const exists = await this.knex.schema.hasTable(this.tableName);\n if (exists) {\n return;\n }\n\n await this.knex.schema.createTable(this.tableName, table => {\n table.text(\"id\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"type\").notNullable();\n table.text(\"slug\").notNullable();\n table.text(\"path\").notNullable();\n table.text(\"parentId\").notNullable();\n table.text(\"permissions\").notNullable();\n table.primary([\"tenant\", \"id\"]);\n });\n }\n\n private toRow(data: FolderLevelPermission & { tenant: string }): FlpRow {\n return {\n id: data.id,\n tenant: data.tenant,\n type: data.type,\n slug: data.slug,\n path: data.path,\n parentId: data.parentId,\n permissions: JSON.stringify(data.permissions)\n };\n }\n\n private fromRow(row: FlpRow): FolderLevelPermission {\n return {\n id: row.id,\n parentId: row.parentId,\n slug: row.slug,\n path: row.path,\n permissions: JSON.parse(row.permissions),\n type: row.type\n };\n }\n}\n"],"names":["BASE_TABLE_NAME","FolderLevelPermissionsStorageOperations","knex","tableNamePrefix","tenant","type","path_startsWith","parentId","rows","row","WebinyError","err","id","data","inputData","original","flp","items","updatedItems","trx","exists","table","JSON"],"mappings":";AAuBA,MAAMA,kBAAkB;AAOjB,MAAMC;IAIT,YAAY,EAAEC,IAAI,EAAEC,eAAe,EAA2B,CAAE;QAC5D,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,SAAS,GAAGC,kBACX,GAAGA,gBAAgB,CAAC,EAAEH,iBAAiB,GACvCA;IACV;IAEA,MAAa,KAAK,EACd,OAAO,EAAEI,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAEC,QAAQ,EAAE,EACpB,EAAoC;QAClE,IAAI;YACA,MAAM,IAAI,CAAC,WAAW;YAEtB,IAAIA,UAAU;gBACV,MAAMC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUJ,QAChB,QAAQ,CAAC,YAAYG;gBAE1B,OAAOC,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,IAAIH,iBAAiB;gBACjB,MAAME,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUJ,QAChB,QAAQ,CAAC,QAAQC,MACjB,QAAQ,CAAC,QAAQ,QAAQC,kBAAkB;gBAEhD,OAAOE,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,MAAM,IAAIC,YAAY,gCAAgC,+BAA+B;gBACjFN;gBACAC;g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AAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS;QAC7D,IAAIA,QACA;QAGJ,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAEC,CAAAA;YAC/CA,MAAM,IAAI,CAAC,MAAM,WAAW;YAC5BA,MAAM,IAAI,CAAC,UAAU,WAAW;YAChCA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,YAAY,WAAW;YAClCA,MAAM,IAAI,CAAC,eAAe,WAAW;YACrCA,MAAM,OAAO,CAAC;gBAAC;gBAAU;aAAK;QAClC;IACJ;IAEQ,MAAMR,IAAgD,EAAU;QACpE,OAAO;YACH,IAAIA,KAAK,EAAE;YACX,QAAQA,KAAK,MAAM;YACnB,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;YACvB,aAAaS,KAAK,SAAS,CAACT,KAAK,WAAW;QAChD;IACJ;IAEQ,QAAQJ,GAAW,EAAyB;QAChD,OAAO;YACH,IAAIA,IAAI,EAAE;YACV,UAAUA,IAAI,QAAQ;YACtB,MAAMA,IAAI,IAAI;YACd,MAAMA,IAAI,IAAI;YACd,aAAaa,KAAK,KAAK,CAACb,IAAI,WAAW;YACvC,MAAMA,IAAI,IAAI;QAClB;IACJ;AACJ"}
1
+ {"version":3,"file":"FolderLevelPermissionsStorageOperations.js","sources":["../src/FolderLevelPermissionsStorageOperations.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n AcoFolderLevelPermissionsStorageOperations,\n FolderLevelPermission,\n StorageOperationsBatchUpdateFlpParams,\n StorageOperationsCreateFlpParams,\n StorageOperationsDeleteFlpParams,\n StorageOperationsGetFlpParams,\n StorageOperationsListFlpsParams,\n StorageOperationsUpdateFlpParams\n} from \"@webiny/api-aco/types.js\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\ninterface FlpRow {\n id: string;\n tenant: string;\n type: string;\n slug: string;\n path: string;\n parentId: string;\n permissions: string;\n}\n\nconst BASE_TABLE_NAME = \"webiny_aco_flp\";\n\nexport interface StorageOperationsConfig {\n knex: Knex;\n tableNamePrefix?: string;\n /**\n * The schema was set up before the API took traffic (see `SqlSchemaConfig` in\n * `@webiny/api-core-sql`): the table is never checked for or created at runtime.\n */\n schemaManaged?: boolean;\n /** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */\n scopeTenant: ScopeTenant.Interface;\n}\n\nexport class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {\n private readonly knex: Knex;\n private readonly tableName: string;\n private readonly schemaManaged: boolean;\n private readonly scopeTenant: ScopeTenant.Interface;\n\n constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }: StorageOperationsConfig) {\n this.knex = knex;\n this.scopeTenant = scopeTenant;\n this.schemaManaged = schemaManaged === true;\n this.tableName = tableNamePrefix\n ? `${tableNamePrefix}_${BASE_TABLE_NAME}`\n : BASE_TABLE_NAME;\n }\n\n public async list({\n where\n }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]> {\n const { type, path_startsWith, parentId } = where;\n const tenant = this.scopeTenant.getId();\n try {\n await this.ensureTable();\n\n if (parentId) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"parentId\", parentId);\n\n return rows.map(row => this.fromRow(row));\n }\n\n if (path_startsWith) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type)\n .andWhere(\"path\", \"like\", path_startsWith + \"%\");\n\n return rows.map(row => this.fromRow(row));\n }\n\n // All folder level permissions of a folder type.\n if (type) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type);\n\n return rows.map(row => this.fromRow(row));\n }\n\n throw new WebinyError(\"Missing required parameters.\", \"LIST_FLP_MISSING_PARAMETERS\", {\n tenant,\n type,\n path_startsWith,\n parentId\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list folder level permissions.\",\n code: \"LIST_FLP_ERROR\"\n });\n }\n }\n\n public async get(params: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null> {\n const { id } = params;\n const tenant = this.scopeTenant.getId();\n try {\n await this.ensureTable();\n\n const row = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"id\", id)\n .first();\n\n if (!row) {\n return null;\n }\n\n return this.fromRow(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load folder level permission.\",\n code: \"GET_FLP_ERROR\",\n data: { tenant, id }\n });\n }\n }\n\n public async create(params: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission> {\n const data = this.inScope(params.data);\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName).insert(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create folder level permission.\",\n code: \"CREATE_FLP_ERROR\",\n data: { data }\n });\n }\n }\n\n public async update({\n data: inputData,\n original\n }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission> {\n const data = this.inScope({\n ...original,\n ...inputData\n });\n\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update folder level permission.\",\n code: \"UPDATE_FLP_ERROR\",\n data: { inputData, original }\n });\n }\n }\n\n public async delete(params: StorageOperationsDeleteFlpParams): Promise<void> {\n const flp = this.inScope(params.flp);\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", flp.tenant)\n .andWhere(\"id\", flp.id)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete folder level permission.\",\n code: \"DELETE_FLP_ERROR\",\n data: { flp }\n });\n }\n }\n\n public async batchUpdate({\n items\n }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]> {\n const scopedItems = items.map(({ original, data: inputData }) => {\n return this.inScope({\n ...original,\n ...inputData\n });\n });\n\n try {\n await this.ensureTable();\n\n // Built inside the callback: a transaction that loses its connection runs it again.\n return await this.knex.transaction(async trx => {\n const updatedItems: FolderLevelPermission[] = [];\n for (const data of scopedItems) {\n await trx<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n updatedItems.push(data);\n }\n return updatedItems;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not batch update folder level permissions.\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: { items }\n });\n }\n }\n\n private async ensureTable(): Promise<void> {\n // Set up before the API took traffic, so don't check for it on every call.\n if (this.schemaManaged) {\n return;\n }\n await this.setupSchema();\n }\n\n /* Creates the table if missing, whatever the mode (deploy-time schema setup). */\n public async setupSchema(): Promise<void> {\n const exists = await this.knex.schema.hasTable(this.tableName);\n if (exists) {\n return;\n }\n\n await this.knex.schema.createTable(this.tableName, table => {\n table.text(\"id\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"type\").notNullable();\n table.text(\"slug\").notNullable();\n table.text(\"path\").notNullable();\n table.text(\"parentId\").notNullable();\n table.text(\"permissions\").notNullable();\n table.primary([\"tenant\", \"id\"]);\n });\n }\n\n /** The permission with its scope's tenant, whatever tenant it carries. */\n private inScope<T extends { tenant?: string | null }>(record: T): T & { tenant: string } {\n return { ...record, tenant: this.scopeTenant.getId() };\n }\n\n private toRow(data: FolderLevelPermission & { tenant: string }): FlpRow {\n return {\n id: data.id,\n tenant: data.tenant,\n type: data.type,\n slug: data.slug,\n path: data.path,\n parentId: data.parentId,\n permissions: JSON.stringify(data.permissions)\n };\n }\n\n private fromRow(row: FlpRow): FolderLevelPermission {\n return {\n id: row.id,\n parentId: row.parentId,\n slug: row.slug,\n path: row.path,\n permissions: JSON.parse(row.permissions),\n type: row.type\n };\n }\n}\n"],"names":["BASE_TABLE_NAME","FolderLevelPermissionsStorageOperations","knex","tableNamePrefix","schemaManaged","scopeTenant","where","type","path_startsWith","parentId","tenant","rows","row","WebinyError","err","params","id","data","inputData","original","flp","items","scopedItems","trx","updatedItems","exists","table","record","JSON"],"mappings":";AAwBA,MAAMA,kBAAkB;AAcjB,MAAMC;IAMT,YAAY,EAAEC,IAAI,EAAEC,eAAe,EAAEC,aAAa,EAAEC,WAAW,EAA2B,CAAE;QACxF,IAAI,CAAC,IAAI,GAAGH;QACZ,IAAI,CAAC,WAAW,GAAGG;QACnB,IAAI,CAAC,aAAa,GAAGD,AAAkB,SAAlBA;QACrB,IAAI,CAAC,SAAS,GAAGD,kBACX,GAAGA,gBAAgB,CAAC,EAAEH,iBAAiB,GACvCA;IACV;IAEA,MAAa,KAAK,EACdM,KAAK,EACyB,EAAoC;QAClE,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAEC,QAAQ,EAAE,GAAGH;QAC5C,MAAMI,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,IAAI;YACA,MAAM,IAAI,CAAC,WAAW;YAEtB,IAAID,UAAU;gBACV,MAAME,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUD,QAChB,QAAQ,CAAC,YAAYD;gBAE1B,OAAOE,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,IAAIJ,iBAAiB;gBACjB,MAAMG,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUD,QAChB,QAAQ,CAAC,QAAQH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8CC,MAAS,EAA0B;QACrF,OAAO;YAAE,GAAGA,MAAM;YAAE,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK;QAAG;IACzD;IAEQ,MAAMV,IAAgD,EAAU;QACpE,OAAO;YACH,IAAIA,KAAK,EAAE;YACX,QAAQA,KAAK,MAAM;YACnB,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;YACvB,aAAaW,KAAK,SAAS,CAACX,KAAK,WAAW;QAChD;IACJ;IAEQ,QAAQL,GAAW,EAAyB;QAChD,OAAO;YACH,IAAIA,IAAI,EAAE;YACV,UAAUA,IAAI,QAAQ;YACtB,MAAMA,IAAI,IAAI;YACd,MAAMA,IAAI,IAAI;YACd,aAAagB,KAAK,KAAK,CAAChB,IAAI,WAAW;YACvC,MAAMA,IAAI,IAAI;QAClB;IACJ;AACJ"}
@@ -0,0 +1,12 @@
1
+ import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
2
+ import { FlpStorageOperations } from "@webiny/api-aco/features/folder/shared/abstractions.js";
3
+ import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
4
+ import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
5
+ /** Folder-level permissions on the container's connection and table prefix, for its scope's tenant. */
6
+ declare class SqlFlpStorageOperationsImpl extends FolderLevelPermissionsStorageOperations implements FlpStorageOperations.Interface {
7
+ constructor(knex: KnexClient.Interface, scopeTenant: ScopeTenant.Interface, schemaConfig?: SqlSchemaConfig.Interface);
8
+ }
9
+ export declare const SqlFlpStorageOperations: typeof SqlFlpStorageOperationsImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-aco/types.js").AcoFolderLevelPermissionsStorageOperations>;
11
+ };
12
+ export {};
@@ -0,0 +1,30 @@
1
+ import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
2
+ import { FlpStorageOperations } from "@webiny/api-aco/features/folder/shared/abstractions.js";
3
+ import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
4
+ import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
5
+ class SqlFlpStorageOperationsImpl extends FolderLevelPermissionsStorageOperations {
6
+ constructor(knex, scopeTenant, schemaConfig){
7
+ super({
8
+ knex: knex.client,
9
+ scopeTenant,
10
+ tableNamePrefix: schemaConfig?.tableNamePrefix,
11
+ schemaManaged: schemaConfig?.isManaged() === true
12
+ });
13
+ }
14
+ }
15
+ const SqlFlpStorageOperations = FlpStorageOperations.createImplementation({
16
+ implementation: SqlFlpStorageOperationsImpl,
17
+ dependencies: [
18
+ KnexClient,
19
+ ScopeTenant,
20
+ [
21
+ SqlSchemaConfig,
22
+ {
23
+ optional: true
24
+ }
25
+ ]
26
+ ]
27
+ });
28
+ export { SqlFlpStorageOperations };
29
+
30
+ //# sourceMappingURL=SqlFlpStorageOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqlFlpStorageOperations.js","sources":["../src/SqlFlpStorageOperations.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { FlpStorageOperations } from \"@webiny/api-aco/features/folder/shared/abstractions.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** Folder-level permissions on the container's connection and table prefix, for its scope's tenant. */\nclass SqlFlpStorageOperationsImpl\n extends FolderLevelPermissionsStorageOperations\n implements FlpStorageOperations.Interface\n{\n public constructor(\n knex: KnexClient.Interface,\n scopeTenant: ScopeTenant.Interface,\n schemaConfig?: SqlSchemaConfig.Interface\n ) {\n super({\n knex: knex.client,\n scopeTenant,\n tableNamePrefix: schemaConfig?.tableNamePrefix,\n schemaManaged: schemaConfig?.isManaged() === true\n });\n }\n}\n\nexport const SqlFlpStorageOperations = FlpStorageOperations.createImplementation({\n implementation: SqlFlpStorageOperationsImpl,\n dependencies: [KnexClient, ScopeTenant, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["SqlFlpStorageOperationsImpl","FolderLevelPermissionsStorageOperations","knex","scopeTenant","schemaConfig","SqlFlpStorageOperations","FlpStorageOperations","KnexClient","ScopeTenant","SqlSchemaConfig"],"mappings":";;;;AAMA,MAAMA,oCACMC;IAGR,YACIC,IAA0B,EAC1BC,WAAkC,EAClCC,YAAwC,CAC1C;QACE,KAAK,CAAC;YACF,MAAMF,KAAK,MAAM;YACjBC;YACA,iBAAiBC,cAAc;YAC/B,eAAeA,cAAc,gBAAgB;QACjD;IACJ;AACJ;AAEO,MAAMC,0BAA0BC,qBAAqB,oBAAoB,CAAC;IAC7E,gBAAgBN;IAChB,cAAc;QAACO;QAAYC;QAAa;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAClF"}
package/feature.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * ACO folder-level permissions on SQL, and the `aco` schema setup step. Registered per request, it
3
+ * runs on the connection (`KnexClient`) and the table settings (`SqlSchemaConfig`) the SQL storage
4
+ * keeps in the root. Folder-level permissions on this storage use the task-maintained FLP catalog.
5
+ */
6
+ export declare const AcoSqlFeature: {
7
+ name: string;
8
+ register(container: import("@webiny/di").Container): void;
9
+ };
10
+ /** `AcoSqlFeature` as an extension plugin, for setups that register storages that way. */
11
+ export declare const registerAcoSqlStorageOperations: () => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
package/feature.js ADDED
@@ -0,0 +1,19 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
3
+ import { TaskCatalogFlpFeature } from "@webiny/api-aco/flpTaskCatalog/index.js";
4
+ import { SqlFlpStorageOperations } from "./SqlFlpStorageOperations.js";
5
+ import { AcoSqlSchemaSetup } from "./AcoSqlSchemaSetup.js";
6
+ const AcoSqlFeature = createFeature({
7
+ name: "AcoSql",
8
+ register (container) {
9
+ container.register(SqlFlpStorageOperations);
10
+ container.register(AcoSqlSchemaSetup);
11
+ TaskCatalogFlpFeature.register(container);
12
+ }
13
+ });
14
+ const registerAcoSqlStorageOperations = ()=>createRegisterExtensionPlugin((context)=>{
15
+ AcoSqlFeature.register(context.container);
16
+ });
17
+ export { AcoSqlFeature, registerAcoSqlStorageOperations };
18
+
19
+ //# sourceMappingURL=feature.js.map
package/feature.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { TaskCatalogFlpFeature } from \"@webiny/api-aco/flpTaskCatalog/index.js\";\nimport { SqlFlpStorageOperations } from \"./SqlFlpStorageOperations.js\";\nimport { AcoSqlSchemaSetup } from \"./AcoSqlSchemaSetup.js\";\n\n/**\n * ACO folder-level permissions on SQL, and the `aco` schema setup step. Registered per request, it\n * runs on the connection (`KnexClient`) and the table settings (`SqlSchemaConfig`) the SQL storage\n * keeps in the root. Folder-level permissions on this storage use the task-maintained FLP catalog.\n */\nexport const AcoSqlFeature = createFeature({\n name: \"AcoSql\",\n register(container) {\n container.register(SqlFlpStorageOperations);\n container.register(AcoSqlSchemaSetup);\n TaskCatalogFlpFeature.register(container);\n }\n});\n\n/** `AcoSqlFeature` as an extension plugin, for setups that register storages that way. */\nexport const registerAcoSqlStorageOperations = () => {\n return createRegisterExtensionPlugin(context => {\n AcoSqlFeature.register(context.container);\n });\n};\n"],"names":["AcoSqlFeature","createFeature","container","SqlFlpStorageOperations","AcoSqlSchemaSetup","TaskCatalogFlpFeature","registerAcoSqlStorageOperations","createRegisterExtensionPlugin","context"],"mappings":";;;;;AAWO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBC,sBAAsB,QAAQ,CAACH;IACnC;AACJ;AAGO,MAAMI,kCAAkC,IACpCC,8BAA8BC,CAAAA;QACjCR,cAAc,QAAQ,CAACQ,QAAQ,SAAS;IAC5C"}
package/index.d.ts CHANGED
@@ -1,7 +1 @@
1
- import type { Knex } from "knex";
2
- interface RegisterAcoSqlStorageOperationsParams {
3
- knex: Knex;
4
- tableNamePrefix?: string;
5
- }
6
- export declare const registerAcoSqlStorageOperations: (params: RegisterAcoSqlStorageOperationsParams) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
7
- export {};
1
+ export { AcoSqlFeature, registerAcoSqlStorageOperations } from "./feature.js";
package/index.js CHANGED
@@ -1,13 +1 @@
1
- import { createRegisterExtensionPlugin } from "@webiny/handler";
2
- import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
3
- import { FlpStorageOperations } from "@webiny/api-aco/features/folder/shared/abstractions.js";
4
- const registerAcoSqlStorageOperations = (params)=>createRegisterExtensionPlugin((context)=>{
5
- const flpStorageOperations = new FolderLevelPermissionsStorageOperations({
6
- knex: params.knex,
7
- tableNamePrefix: params.tableNamePrefix
8
- });
9
- context.container.registerInstance(FlpStorageOperations, flpStorageOperations);
10
- });
11
- export { registerAcoSqlStorageOperations };
12
-
13
- //# sourceMappingURL=index.js.map
1
+ export { AcoSqlFeature, registerAcoSqlStorageOperations } from "./feature.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-aco-sql",
3
- "version": "0.0.0-unstable.0d717d18dd",
3
+ "version": "0.0.0-unstable.292eb6dc15",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "@webiny/api-aco",
@@ -20,18 +20,20 @@
20
20
  "./*": "./*"
21
21
  },
22
22
  "dependencies": {
23
- "@webiny/api-aco": "0.0.0-unstable.0d717d18dd",
24
- "@webiny/error": "0.0.0-unstable.0d717d18dd",
25
- "@webiny/handler": "0.0.0-unstable.0d717d18dd",
23
+ "@webiny/api-aco": "0.0.0-unstable.292eb6dc15",
24
+ "@webiny/api-core": "0.0.0-unstable.292eb6dc15",
25
+ "@webiny/api-core-sql": "0.0.0-unstable.292eb6dc15",
26
+ "@webiny/error": "0.0.0-unstable.292eb6dc15",
27
+ "@webiny/feature": "0.0.0-unstable.292eb6dc15",
28
+ "@webiny/handler": "0.0.0-unstable.292eb6dc15",
26
29
  "knex": "3.3.0"
27
30
  },
28
31
  "devDependencies": {
29
- "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
30
- "@webiny/project-utils": "0.0.0-unstable.0d717d18dd",
31
- "better-sqlite3": "13.0.2",
32
- "rimraf": "6.1.3",
32
+ "@webiny/build-tools": "0.0.0-unstable.292eb6dc15",
33
+ "better-sqlite3": "13.2.0",
34
+ "rimraf": "6.1.4",
33
35
  "typescript": "7.0.2",
34
- "vitest": "4.1.10"
36
+ "vitest": "5.1.1"
35
37
  },
36
38
  "publishConfig": {
37
39
  "access": "public"
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\nimport { FlpStorageOperations } from \"@webiny/api-aco/features/folder/shared/abstractions.js\";\n\ninterface RegisterAcoSqlStorageOperationsParams {\n knex: Knex;\n tableNamePrefix?: string;\n}\n\nexport const registerAcoSqlStorageOperations = (params: RegisterAcoSqlStorageOperationsParams) => {\n return createRegisterExtensionPlugin(context => {\n const flpStorageOperations = new FolderLevelPermissionsStorageOperations({\n knex: params.knex,\n tableNamePrefix: params.tableNamePrefix\n });\n\n context.container.registerInstance(FlpStorageOperations, flpStorageOperations);\n });\n};\n"],"names":["registerAcoSqlStorageOperations","params","createRegisterExtensionPlugin","context","flpStorageOperations","FolderLevelPermissionsStorageOperations","FlpStorageOperations"],"mappings":";;;AAUO,MAAMA,kCAAkC,CAACC,SACrCC,8BAA8BC,CAAAA;QACjC,MAAMC,uBAAuB,IAAIC,wCAAwC;YACrE,MAAMJ,OAAO,IAAI;YACjB,iBAAiBA,OAAO,eAAe;QAC3C;QAEAE,QAAQ,SAAS,CAAC,gBAAgB,CAACG,sBAAsBF;IAC7D"}