@webiny/api-core-sql 0.0.0-unstable.0156a4c312 → 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.
Files changed (107) hide show
  1. package/TableManager.d.ts +30 -12
  2. package/TableManager.js +34 -30
  3. package/TableManager.js.map +1 -1
  4. package/adminUsers/index.d.ts +3 -0
  5. package/adminUsers/index.js +68 -16
  6. package/adminUsers/index.js.map +1 -1
  7. package/connection/SqlConnectionFeature.d.ts +32 -0
  8. package/connection/SqlConnectionFeature.js +30 -0
  9. package/connection/SqlConnectionFeature.js.map +1 -0
  10. package/connection/index.d.ts +2 -0
  11. package/connection/index.js +1 -0
  12. package/connectionRetry/index.d.ts +3 -0
  13. package/connectionRetry/index.js +2 -0
  14. package/connectionRetry/isConnectionError.d.ts +1 -0
  15. package/connectionRetry/isConnectionError.js +28 -0
  16. package/connectionRetry/isConnectionError.js.map +1 -0
  17. package/connectionRetry/withPgConnectionRetry.d.ts +49 -0
  18. package/connectionRetry/withPgConnectionRetry.js +175 -0
  19. package/connectionRetry/withPgConnectionRetry.js.map +1 -0
  20. package/coreStorage/CoreSqlSchemaSetup.d.ts +18 -0
  21. package/coreStorage/CoreSqlSchemaSetup.js +36 -0
  22. package/coreStorage/CoreSqlSchemaSetup.js.map +1 -0
  23. package/coreStorage/SqlApiCoreStorageOperationsFactory.d.ts +15 -0
  24. package/coreStorage/SqlApiCoreStorageOperationsFactory.js +33 -0
  25. package/coreStorage/SqlApiCoreStorageOperationsFactory.js.map +1 -0
  26. package/coreStorage/SqlTenancyStorageOperationsFactory.d.ts +18 -0
  27. package/coreStorage/SqlTenancyStorageOperationsFactory.js +36 -0
  28. package/coreStorage/SqlTenancyStorageOperationsFactory.js.map +1 -0
  29. package/coreStorage/SqlTenantStorageReadiness.d.ts +19 -0
  30. package/coreStorage/SqlTenantStorageReadiness.js +48 -0
  31. package/coreStorage/SqlTenantStorageReadiness.js.map +1 -0
  32. package/coreStorage/feature.d.ts +14 -0
  33. package/coreStorage/feature.js +17 -0
  34. package/coreStorage/feature.js.map +1 -0
  35. package/coreStorage/index.d.ts +1 -0
  36. package/coreStorage/index.js +1 -0
  37. package/createApiCoreSql.d.ts +19 -1
  38. package/createApiCoreSql.js +12 -10
  39. package/createApiCoreSql.js.map +1 -1
  40. package/feature/SqlDialect/abstractions.d.ts +15 -0
  41. package/feature/SqlDialect/abstractions.js +5 -0
  42. package/feature/SqlDialect/abstractions.js.map +1 -0
  43. package/feature/SqlDialect/index.d.ts +2 -0
  44. package/feature/SqlDialect/index.js +1 -0
  45. package/index.d.ts +26 -4
  46. package/index.js +18 -4
  47. package/index.js.map +1 -1
  48. package/keyValueStore/index.js +19 -17
  49. package/keyValueStore/index.js.map +1 -1
  50. package/package.json +9 -8
  51. package/schemaConfig/abstractions.d.ts +22 -0
  52. package/schemaConfig/abstractions.js +5 -0
  53. package/schemaConfig/abstractions.js.map +1 -0
  54. package/schemaConfig/index.d.ts +1 -0
  55. package/schemaConfig/index.js +1 -0
  56. package/schemaMemory/ensureTable.d.ts +35 -0
  57. package/schemaMemory/ensureTable.js +46 -0
  58. package/schemaMemory/ensureTable.js.map +1 -0
  59. package/schemaMemory/getConnectionKey.d.ts +8 -0
  60. package/schemaMemory/getConnectionKey.js +15 -0
  61. package/schemaMemory/getConnectionKey.js.map +1 -0
  62. package/schemaMemory/getSchemaMemory.d.ts +37 -0
  63. package/schemaMemory/getSchemaMemory.js +53 -0
  64. package/schemaMemory/getSchemaMemory.js.map +1 -0
  65. package/schemaSetup/abstractions.d.ts +79 -0
  66. package/schemaSetup/abstractions.js +6 -0
  67. package/schemaSetup/abstractions.js.map +1 -0
  68. package/schemaSetup/index.d.ts +6 -0
  69. package/schemaSetup/index.js +3 -0
  70. package/schemaSetup/runSchemaSetupSteps.d.ts +43 -0
  71. package/schemaSetup/runSchemaSetupSteps.js +39 -0
  72. package/schemaSetup/runSchemaSetupSteps.js.map +1 -0
  73. package/schemaSetup/runSqlSchemaSetups.d.ts +22 -0
  74. package/schemaSetup/runSqlSchemaSetups.js +24 -0
  75. package/schemaSetup/runSqlSchemaSetups.js.map +1 -0
  76. package/scopeStorage/abstractions.d.ts +19 -0
  77. package/scopeStorage/abstractions.js +5 -0
  78. package/scopeStorage/abstractions.js.map +1 -0
  79. package/scopeStorage/index.d.ts +3 -0
  80. package/scopeStorage/index.js +2 -0
  81. package/scopeStorage/isPostgresScope.d.ts +14 -0
  82. package/scopeStorage/isPostgresScope.js +8 -0
  83. package/scopeStorage/isPostgresScope.js.map +1 -0
  84. package/security/index.d.ts +3 -0
  85. package/security/index.js +68 -47
  86. package/security/index.js.map +1 -1
  87. package/serviceDiscovery/SqlServiceManifestLoader.d.ts +1 -1
  88. package/serviceDiscovery/SqlServiceManifestLoader.js +3 -8
  89. package/serviceDiscovery/SqlServiceManifestLoader.js.map +1 -1
  90. package/serviceDiscovery/SqlServiceManifestWriter.d.ts +16 -0
  91. package/serviceDiscovery/SqlServiceManifestWriter.js +27 -0
  92. package/serviceDiscovery/SqlServiceManifestWriter.js.map +1 -0
  93. package/serviceDiscovery/index.d.ts +1 -0
  94. package/serviceDiscovery/index.js +1 -0
  95. package/serviceDiscovery/serviceManifestsTable.d.ts +13 -0
  96. package/serviceDiscovery/serviceManifestsTable.js +8 -0
  97. package/serviceDiscovery/serviceManifestsTable.js.map +1 -0
  98. package/storage/sqlTenantStorage.d.ts +44 -0
  99. package/storage/sqlTenantStorage.js +32 -0
  100. package/storage/sqlTenantStorage.js.map +1 -0
  101. package/storage/types.d.ts +31 -0
  102. package/storage/types.js +0 -0
  103. package/tenancy/index.js +59 -17
  104. package/tenancy/index.js.map +1 -1
  105. package/ApiCoreSqlFeature.d.ts +0 -18
  106. package/ApiCoreSqlFeature.js +0 -18
  107. package/ApiCoreSqlFeature.js.map +0 -1
@@ -0,0 +1,175 @@
1
+ import { isConnectionError } from "./isConnectionError.js";
2
+ const DELAYS_MS = [
3
+ 100,
4
+ 250,
5
+ 500,
6
+ 1000,
7
+ 2000
8
+ ];
9
+ const IN_PROGRESS_CHECKS = 5;
10
+ const RETRY_INSTALLED = Symbol.for("webiny.pgConnectionRetry");
11
+ const READ_STATEMENT = /^\s*(select|show|explain|set|with)\b/i;
12
+ const WRITE_KEYWORDS = /\b(insert\s+into|update\s+\S+\s+set|delete\s+from|merge\s+into|truncate|create|alter|drop|grant|revoke|copy|nextval|setval|pg_advisory_lock|pg_try_advisory_lock)\b/i;
13
+ const mayWrite = (sql)=>!READ_STATEMENT.test(sql) || WRITE_KEYWORDS.test(sql);
14
+ const READ_METHODS = new Set([
15
+ "select",
16
+ "first",
17
+ "pluck"
18
+ ]);
19
+ const isReadOnlyBuilder = (builder)=>{
20
+ if ("string" == typeof builder._method) return READ_METHODS.has(builder._method);
21
+ if ("string" == typeof builder.sql) return /^\s*(select|show|explain)\b/i.test(builder.sql) && !mayWrite(builder.sql);
22
+ return false;
23
+ };
24
+ class StopRetrying {
25
+ constructor(error){
26
+ this.error = error;
27
+ }
28
+ }
29
+ const sleep = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms));
30
+ const withPgConnectionRetry = (knex, options = {})=>{
31
+ const target = knex;
32
+ const clientName = String(knex.client.config?.client);
33
+ if (target[RETRY_INSTALLED] || ![
34
+ "pg",
35
+ "postgres",
36
+ "postgresql"
37
+ ].includes(clientName)) return knex;
38
+ target[RETRY_INSTALLED] = true;
39
+ const maxRetryMs = options.maxRetryMs ?? 15000;
40
+ const emit = (event)=>{
41
+ try {
42
+ options.onEvent?.(event);
43
+ } catch {}
44
+ };
45
+ const retrying = async (operation, attempt)=>{
46
+ let firstFailureAt;
47
+ for(let attemptNumber = 0;; attemptNumber++)try {
48
+ return await attempt(attemptNumber);
49
+ } catch (error) {
50
+ if (error instanceof StopRetrying) throw error.error;
51
+ if (!isConnectionError(error)) throw error;
52
+ firstFailureAt ??= Date.now();
53
+ const delayMs = DELAYS_MS[Math.min(attemptNumber, DELAYS_MS.length - 1)];
54
+ if (Date.now() - firstFailureAt + delayMs > maxRetryMs) {
55
+ emit({
56
+ type: "gaveUp",
57
+ operation,
58
+ attempt: attemptNumber,
59
+ error
60
+ });
61
+ throw error;
62
+ }
63
+ emit({
64
+ type: "retry",
65
+ operation,
66
+ attempt: attemptNumber,
67
+ delayMs,
68
+ error
69
+ });
70
+ await sleep(delayMs);
71
+ }
72
+ };
73
+ const client = knex.client;
74
+ const originalRunner = client.runner;
75
+ client.runner = function(builder) {
76
+ const runner = originalRunner.call(this, builder);
77
+ if (!isReadOnlyBuilder(builder)) return runner;
78
+ const firstRun = runner.run.bind(runner);
79
+ runner.run = ()=>retrying("query", (attemptNumber)=>0 === attemptNumber ? firstRun() : originalRunner.call(client, builder).run());
80
+ return runner;
81
+ };
82
+ const originalTransaction = knex.transaction;
83
+ const transactionOutcome = async (xid, pid)=>{
84
+ for(let check = 0; check < IN_PROGRESS_CHECKS; check++){
85
+ const result = await knex.raw("SELECT pg_xact_status(?::xid8)::text AS status", [
86
+ xid
87
+ ]);
88
+ const status = result.rows[0]?.status ?? null;
89
+ if ("in progress" !== status) return status;
90
+ if (null !== pid) await knex.raw(`SELECT pg_terminate_backend(pid) FROM pg_stat_activity
91
+ WHERE pid = ? AND backend_xid = (?::xid8)::xid AND state LIKE 'idle in transaction%'`, [
92
+ pid,
93
+ xid
94
+ ]);
95
+ await sleep(DELAYS_MS[Math.min(check, DELAYS_MS.length - 1)]);
96
+ }
97
+ return null;
98
+ };
99
+ const runTransactionOnce = async (callback, config, attemptNumber)=>{
100
+ const state = {
101
+ committing: false,
102
+ wrote: false,
103
+ xid: null,
104
+ pid: null,
105
+ result: void 0
106
+ };
107
+ try {
108
+ return await originalTransaction.call(knex, async (trx)=>{
109
+ trx.on("query", (query)=>{
110
+ if (!state.wrote && "string" == typeof query.sql && mayWrite(query.sql)) state.wrote = true;
111
+ });
112
+ const result = await callback(trx);
113
+ state.result = result;
114
+ if (state.wrote) {
115
+ const ids = await trx.raw("SELECT pg_current_xact_id_if_assigned()::text AS xid, pg_backend_pid() AS pid");
116
+ state.xid = ids.rows[0]?.xid ?? null;
117
+ state.pid = ids.rows[0]?.pid ?? null;
118
+ }
119
+ state.committing = true;
120
+ return result;
121
+ }, config);
122
+ } catch (error) {
123
+ if (!state.committing || !isConnectionError(error)) throw error;
124
+ if (!state.xid) {
125
+ emit({
126
+ type: "readOnlyCommitIgnored",
127
+ operation: "transaction",
128
+ attempt: attemptNumber,
129
+ error
130
+ });
131
+ return state.result;
132
+ }
133
+ const outcome = await transactionOutcome(state.xid, state.pid);
134
+ if ("committed" === outcome) {
135
+ emit({
136
+ type: "commitConfirmed",
137
+ operation: "transaction",
138
+ attempt: attemptNumber,
139
+ error
140
+ });
141
+ return state.result;
142
+ }
143
+ if ("aborted" === outcome) {
144
+ emit({
145
+ type: "commitRolledBack",
146
+ operation: "transaction",
147
+ attempt: attemptNumber,
148
+ error
149
+ });
150
+ throw error;
151
+ }
152
+ emit({
153
+ type: "gaveUp",
154
+ operation: "transaction",
155
+ attempt: attemptNumber,
156
+ error
157
+ });
158
+ throw new StopRetrying(error);
159
+ }
160
+ };
161
+ Object.defineProperty(knex, "transaction", {
162
+ configurable: true,
163
+ enumerable: true,
164
+ writable: false,
165
+ value: function(...args) {
166
+ const [callback, config] = args;
167
+ if ("function" != typeof callback) return originalTransaction.apply(knex, args);
168
+ return retrying("transaction", (attemptNumber)=>runTransactionOnce(callback, config, attemptNumber));
169
+ }
170
+ });
171
+ return knex;
172
+ };
173
+ export { withPgConnectionRetry };
174
+
175
+ //# sourceMappingURL=withPgConnectionRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectionRetry/withPgConnectionRetry.js","sources":["../../src/connectionRetry/withPgConnectionRetry.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { isConnectionError } from \"./isConnectionError.js\";\n\n/**\n * Makes a Postgres knex instance survive a lost connection (a database failover, a dropped proxy\n * connection, a server restart) without failing the API request, where that is safe:\n *\n * - A transaction (`knex.transaction(async trx => …)`) that loses its connection before COMMIT is sent\n * is run again: the server rolled it back, so nothing of it was kept.\n * - A transaction that loses its connection during COMMIT may or may not have committed. Before\n * COMMIT, the transaction reads its own ID; after the failure, the wrapper asks the server for that\n * transaction's outcome (`pg_xact_status`) on a new connection. Committed: the result is returned\n * as is, and the work is not repeated. Rolled back: the transaction is run again. Unknown: the\n * error is thrown.\n * - A read-only transaction that fails at COMMIT returns its result: there was nothing to commit.\n * - A read outside a transaction (a SELECT) is run again.\n *\n * Retries wait 100 ms, 250 ms, 500 ms, 1 s, then every 2 s, until `maxRetryMs` has passed since the\n * first failure; then the last error is thrown. Errors that aren't about the connection (a constraint\n * violation, a syntax error, a timeout of the statement itself) are never retried.\n *\n * A transaction's callback is run again on a retry, so it must only change the database: a call to\n * another service inside it would be repeated.\n *\n * Writes outside a transaction are not retried: their outcome can't be checked.\n */\n\nexport type PgConnectionRetryEventType =\n /** A connection error; the operation runs again after `delayMs`. */\n | \"retry\"\n /** COMMIT failed, but the server confirmed that the transaction committed: no retry needed. */\n | \"commitConfirmed\"\n /** COMMIT failed, and the server confirmed that the transaction was rolled back: it runs again. */\n | \"commitRolledBack\"\n /** COMMIT failed for a transaction that changed nothing: its result is returned. */\n | \"readOnlyCommitIgnored\"\n /** Retries ran out (time or an unknown transaction outcome): the error is thrown. */\n | \"gaveUp\";\n\nexport interface IPgConnectionRetryEvent {\n type: PgConnectionRetryEventType;\n operation: \"transaction\" | \"query\";\n /** Retries so far for this operation. */\n attempt: number;\n delayMs?: number;\n error: unknown;\n}\n\nexport interface IPgConnectionRetryOptions {\n /** How long to keep retrying after an operation's first connection error. Default: 15,000 ms. */\n maxRetryMs?: number;\n onEvent?: (event: IPgConnectionRetryEvent) => void;\n}\n\nconst DELAYS_MS = [100, 250, 500, 1000, 2000];\n/** How often to ask again while the server still reports the transaction as in progress. */\nconst IN_PROGRESS_CHECKS = 5;\n\nconst RETRY_INSTALLED = Symbol.for(\"webiny.pgConnectionRetry\");\n\n/* Statements that can't change data, so a transaction made only of them has nothing to lose. */\nconst READ_STATEMENT = /^\\s*(select|show|explain|set|with)\\b/i;\n/* Anything in a statement that changes data or takes a session lock. */\nconst WRITE_KEYWORDS =\n /\\b(insert\\s+into|update\\s+\\S+\\s+set|delete\\s+from|merge\\s+into|truncate|create|alter|drop|grant|revoke|copy|nextval|setval|pg_advisory_lock|pg_try_advisory_lock)\\b/i;\n\nconst mayWrite = (sql: string): boolean => {\n return !READ_STATEMENT.test(sql) || WRITE_KEYWORDS.test(sql);\n};\n\nconst READ_METHODS = new Set([\"select\", \"first\", \"pluck\"]);\n\n/* A query builder or raw statement that only reads. */\nconst isReadOnlyBuilder = (builder: { _method?: unknown; sql?: unknown }): boolean => {\n if (typeof builder._method === \"string\") {\n return READ_METHODS.has(builder._method);\n }\n if (typeof builder.sql === \"string\") {\n return /^\\s*(select|show|explain)\\b/i.test(builder.sql) && !mayWrite(builder.sql);\n }\n return false;\n};\n\n/* Thrown inside an attempt to stop retrying; carries the error to throw. */\nclass StopRetrying {\n public constructor(public readonly error: unknown) {}\n}\n\nconst sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));\n\ntype TransactionCallback = (trx: Knex.Transaction) => Promise<unknown> | unknown;\n\ninterface IRunner {\n run(): Promise<unknown>;\n}\n\ninterface IClientWithRunner {\n runner(builder: unknown): IRunner;\n}\n\ninterface ITransactionState {\n /* COMMIT has been sent (or is about to be). */\n committing: boolean;\n /* A statement that may have changed data ran. */\n wrote: boolean;\n xid: string | null;\n pid: number | null;\n result: unknown;\n}\n\nexport const withPgConnectionRetry = (\n knex: Knex,\n options: IPgConnectionRetryOptions = {}\n): Knex => {\n const target = knex as Knex & { [RETRY_INSTALLED]?: boolean };\n const clientName = String((knex.client as { config?: { client?: unknown } }).config?.client);\n if (target[RETRY_INSTALLED] || ![\"pg\", \"postgres\", \"postgresql\"].includes(clientName)) {\n return knex;\n }\n target[RETRY_INSTALLED] = true;\n\n const maxRetryMs = options.maxRetryMs ?? 15_000;\n const emit = (event: IPgConnectionRetryEvent) => {\n try {\n options.onEvent?.(event);\n } catch {\n // A failing listener must not change the outcome of the query.\n }\n };\n\n /* Runs `attempt` until it succeeds, throws a non-connection error, or time runs out. */\n const retrying = async <T>(\n operation: IPgConnectionRetryEvent[\"operation\"],\n attempt: (attemptNumber: number) => Promise<T>\n ): Promise<T> => {\n let firstFailureAt: number | undefined;\n for (let attemptNumber = 0; ; attemptNumber++) {\n try {\n return await attempt(attemptNumber);\n } catch (error) {\n if (error instanceof StopRetrying) {\n throw error.error;\n }\n if (!isConnectionError(error)) {\n throw error;\n }\n firstFailureAt ??= Date.now();\n const delayMs = DELAYS_MS[Math.min(attemptNumber, DELAYS_MS.length - 1)];\n if (Date.now() - firstFailureAt + delayMs > maxRetryMs) {\n emit({ type: \"gaveUp\", operation, attempt: attemptNumber, error });\n throw error;\n }\n emit({ type: \"retry\", operation, attempt: attemptNumber, delayMs, error });\n await sleep(delayMs);\n }\n }\n };\n\n // Reads outside a transaction. Transactions run their queries on their own client object (knex\n // creates it from the client's prototype), so this only sees statements outside transactions.\n const client = knex.client as unknown as IClientWithRunner;\n const originalRunner = client.runner;\n client.runner = function (this: IClientWithRunner, builder: unknown): IRunner {\n const runner = originalRunner.call(this, builder);\n if (!isReadOnlyBuilder(builder as Parameters<typeof isReadOnlyBuilder>[0])) {\n return runner;\n }\n const firstRun = runner.run.bind(runner);\n runner.run = () => {\n return retrying(\"query\", attemptNumber => {\n return attemptNumber === 0\n ? firstRun()\n : originalRunner.call(client, builder).run();\n });\n };\n return runner;\n };\n\n const originalTransaction = knex.transaction;\n\n /* The outcome of a transaction whose COMMIT failed: \"committed\", \"aborted\" or null (unknown). */\n const transactionOutcome = async (xid: string, pid: number | null): Promise<string | null> => {\n for (let check = 0; check < IN_PROGRESS_CHECKS; check++) {\n // A read outside a transaction: retried on connection errors by the runner above.\n const result = await knex.raw<{ rows: { status: string | null }[] }>(\n \"SELECT pg_xact_status(?::xid8)::text AS status\",\n [xid]\n );\n const status = result.rows[0]?.status ?? null;\n if (status !== \"in progress\") {\n return status;\n }\n // The server still has the transaction open. If its session is idle (the COMMIT never\n // arrived), end the session: the transaction is rolled back, and the next check says so.\n if (pid !== null) {\n await knex.raw(\n `SELECT pg_terminate_backend(pid) FROM pg_stat_activity\n WHERE pid = ? AND backend_xid = (?::xid8)::xid AND state LIKE 'idle in transaction%'`,\n [pid, xid]\n );\n }\n await sleep(DELAYS_MS[Math.min(check, DELAYS_MS.length - 1)]);\n }\n return null;\n };\n\n const runTransactionOnce = async (\n callback: TransactionCallback,\n config: Knex.TransactionConfig | undefined,\n attemptNumber: number\n ): Promise<unknown> => {\n const state: ITransactionState = {\n committing: false,\n wrote: false,\n xid: null,\n pid: null,\n result: undefined\n };\n try {\n return await originalTransaction.call(\n knex,\n async (trx: Knex.Transaction) => {\n trx.on(\"query\", (query: { sql?: string }) => {\n if (!state.wrote && typeof query.sql === \"string\" && mayWrite(query.sql)) {\n state.wrote = true;\n }\n });\n const result = await callback(trx);\n state.result = result;\n if (state.wrote) {\n // The transaction's ID, if it has one (it gets one when it changes data), so\n // its outcome can be checked if COMMIT fails.\n const ids = await trx.raw<{ rows: { xid: string | null; pid: number }[] }>(\n \"SELECT pg_current_xact_id_if_assigned()::text AS xid, pg_backend_pid() AS pid\"\n );\n state.xid = ids.rows[0]?.xid ?? null;\n state.pid = ids.rows[0]?.pid ?? null;\n }\n state.committing = true;\n return result;\n },\n config\n );\n } catch (error) {\n if (!state.committing || !isConnectionError(error)) {\n // Before COMMIT, a connection error is retried by the caller: the server rolled the\n // transaction back. Other errors are thrown.\n throw error;\n }\n if (!state.xid) {\n emit({\n type: \"readOnlyCommitIgnored\",\n operation: \"transaction\",\n attempt: attemptNumber,\n error\n });\n return state.result;\n }\n const outcome = await transactionOutcome(state.xid, state.pid);\n if (outcome === \"committed\") {\n emit({\n type: \"commitConfirmed\",\n operation: \"transaction\",\n attempt: attemptNumber,\n error\n });\n return state.result;\n }\n if (outcome === \"aborted\") {\n emit({\n type: \"commitRolledBack\",\n operation: \"transaction\",\n attempt: attemptNumber,\n error\n });\n throw error;\n }\n emit({ type: \"gaveUp\", operation: \"transaction\", attempt: attemptNumber, error });\n throw new StopRetrying(error);\n }\n };\n\n Object.defineProperty(knex, \"transaction\", {\n configurable: true,\n enumerable: true,\n writable: false,\n value: function transaction(this: Knex, ...args: unknown[]) {\n const [callback, config] = args;\n if (typeof callback !== \"function\") {\n // No callback: the caller commits and rolls back by hand; nothing to retry.\n return (originalTransaction as (...a: unknown[]) => unknown).apply(knex, args);\n }\n return retrying(\"transaction\", attemptNumber => {\n return runTransactionOnce(\n callback as TransactionCallback,\n config as Knex.TransactionConfig | undefined,\n attemptNumber\n );\n });\n }\n });\n\n return knex;\n};\n"],"names":["DELAYS_MS","IN_PROGRESS_CHECKS","RETRY_INSTALLED","Symbol","READ_STATEMENT","WRITE_KEYWORDS","mayWrite","sql","READ_METHODS","Set","isReadOnlyBuilder","builder","StopRetrying","error","sleep","ms","Promise","resolve","setTimeout","withPgConnectionRetry","knex","options","target","clientName","String","maxRetryMs","emit","event","retrying","operation","attempt","firstFailureAt","attemptNumber","isConnectionError","Date","delayMs","Math","client","originalRunner","runner","firstRun","originalTransaction","transactionOutcome","xid","pid","check","result","status","runTransactionOnce","callback","config","state","undefined","trx","query","ids","outcome","Object","args"],"mappings":"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"}
@@ -0,0 +1,18 @@
1
+ import { KnexClient } from "../feature/KnexClient/index.js";
2
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
3
+ import { SqlSchemaSetup } from "../schemaSetup/index.js";
4
+ /**
5
+ * The `core` schema setup step: the tables of users, tenancy, security, the key-value store and the
6
+ * service manifests, on the container's connection.
7
+ */
8
+ declare class CoreSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {
9
+ private readonly knex;
10
+ private readonly schemaConfig?;
11
+ readonly name = "core";
12
+ constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
13
+ setup(): Promise<void>;
14
+ }
15
+ export declare const CoreSqlSchemaSetup: typeof CoreSqlSchemaSetupImpl & {
16
+ __abstraction: import("@webiny/di").Abstraction<import("../schemaSetup/abstractions").ISqlSchemaSetup>;
17
+ };
18
+ export {};
@@ -0,0 +1,36 @@
1
+ import { createApiCoreSqlOperations } from "../createApiCoreSql.js";
2
+ import { KnexClient } from "../feature/KnexClient/index.js";
3
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
4
+ import { SqlSchemaSetup } from "../schemaSetup/index.js";
5
+ import { TableManager } from "../TableManager.js";
6
+ import { defineServiceManifestsTable } from "../serviceDiscovery/serviceManifestsTable.js";
7
+ import { tenantNeutralScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
8
+ class CoreSqlSchemaSetupImpl {
9
+ constructor(knex, schemaConfig){
10
+ this.knex = knex;
11
+ this.schemaConfig = schemaConfig;
12
+ this.name = "core";
13
+ }
14
+ async setup() {
15
+ const knex = this.knex.client;
16
+ const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix);
17
+ createApiCoreSqlOperations(knex, tableManager, tenantNeutralScopeTenant);
18
+ defineServiceManifestsTable(tableManager);
19
+ await tableManager.setup();
20
+ }
21
+ }
22
+ const CoreSqlSchemaSetup = SqlSchemaSetup.createImplementation({
23
+ implementation: CoreSqlSchemaSetupImpl,
24
+ dependencies: [
25
+ KnexClient,
26
+ [
27
+ SqlSchemaConfig,
28
+ {
29
+ optional: true
30
+ }
31
+ ]
32
+ ]
33
+ });
34
+ export { CoreSqlSchemaSetup };
35
+
36
+ //# sourceMappingURL=CoreSqlSchemaSetup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreStorage/CoreSqlSchemaSetup.js","sources":["../../src/coreStorage/CoreSqlSchemaSetup.ts"],"sourcesContent":["import { createApiCoreSqlOperations } from \"~/createApiCoreSql.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { SqlSchemaSetup } from \"~/schemaSetup/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\nimport { defineServiceManifestsTable } from \"~/serviceDiscovery/serviceManifestsTable.js\";\nimport { tenantNeutralScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\n/**\n * The `core` schema setup step: the tables of users, tenancy, security, the key-value store and the\n * service manifests, on the container's connection.\n */\nclass CoreSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"core\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public async setup(): Promise<void> {\n const knex = this.knex.client;\n const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix);\n // Building them declares their tables on the manager. The setup runs in no tenant.\n createApiCoreSqlOperations(knex, tableManager, tenantNeutralScopeTenant);\n defineServiceManifestsTable(tableManager);\n await tableManager.setup();\n }\n}\n\nexport const CoreSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: CoreSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["CoreSqlSchemaSetupImpl","knex","schemaConfig","tableManager","TableManager","createApiCoreSqlOperations","tenantNeutralScopeTenant","defineServiceManifestsTable","CoreSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;;;;;AAYA,MAAMA;IAGF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;aAJL,IAAI,GAAG;IAKpB;IAEH,MAAa,QAAuB;QAChC,MAAMD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;QAC7B,MAAME,eAAe,IAAIC,aAAaH,MAAM,IAAI,CAAC,YAAY,EAAE;QAE/DI,2BAA2BJ,MAAME,cAAcG;QAC/CC,4BAA4BJ;QAC5B,MAAMA,aAAa,KAAK;IAC5B;AACJ;AAEO,MAAMK,qBAAqBC,eAAe,oBAAoB,CAAC;IAClE,gBAAgBT;IAChB,cAAc;QAACU;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -0,0 +1,15 @@
1
+ import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
2
+ import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
3
+ import { KnexClient } from "../feature/KnexClient/index.js";
4
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
5
+ /** Builds the core storage operations on the container's connection and table prefix. */
6
+ declare class SqlApiCoreStorageOperationsFactoryImpl implements ApiCoreStorageOperationsFactory.Interface {
7
+ private readonly knex;
8
+ private readonly schemaConfig?;
9
+ constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
10
+ create({ scopeTenant }: ApiCoreStorageOperationsFactory.Params): ApiCoreStorageOperations;
11
+ }
12
+ export declare const SqlApiCoreStorageOperationsFactory: typeof SqlApiCoreStorageOperationsFactoryImpl & {
13
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/storageOperations/abstractions").IApiCoreStorageOperationsFactory>;
14
+ };
15
+ export {};
@@ -0,0 +1,33 @@
1
+ import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
2
+ import { createApiCoreSql } from "../createApiCoreSql.js";
3
+ import { KnexClient } from "../feature/KnexClient/index.js";
4
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
5
+ class SqlApiCoreStorageOperationsFactoryImpl {
6
+ constructor(knex, schemaConfig){
7
+ this.knex = knex;
8
+ this.schemaConfig = schemaConfig;
9
+ }
10
+ create({ scopeTenant }) {
11
+ return createApiCoreSql({
12
+ scopeTenant,
13
+ knex: this.knex.client,
14
+ tableNamePrefix: this.schemaConfig?.tableNamePrefix,
15
+ schemaManaged: this.schemaConfig?.isManaged() === true
16
+ });
17
+ }
18
+ }
19
+ const SqlApiCoreStorageOperationsFactory = ApiCoreStorageOperationsFactory.createImplementation({
20
+ implementation: SqlApiCoreStorageOperationsFactoryImpl,
21
+ dependencies: [
22
+ KnexClient,
23
+ [
24
+ SqlSchemaConfig,
25
+ {
26
+ optional: true
27
+ }
28
+ ]
29
+ ]
30
+ });
31
+ export { SqlApiCoreStorageOperationsFactory };
32
+
33
+ //# sourceMappingURL=SqlApiCoreStorageOperationsFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreStorage/SqlApiCoreStorageOperationsFactory.js","sources":["../../src/coreStorage/SqlApiCoreStorageOperationsFactory.ts"],"sourcesContent":["import { ApiCoreStorageOperationsFactory } from \"@webiny/api-core\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport { createApiCoreSql } from \"~/createApiCoreSql.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\n\n/** Builds the core storage operations on the container's connection and table prefix. */\nclass SqlApiCoreStorageOperationsFactoryImpl implements ApiCoreStorageOperationsFactory.Interface {\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public create({\n scopeTenant\n }: ApiCoreStorageOperationsFactory.Params): ApiCoreStorageOperations {\n return createApiCoreSql({\n scopeTenant,\n knex: this.knex.client,\n tableNamePrefix: this.schemaConfig?.tableNamePrefix,\n schemaManaged: this.schemaConfig?.isManaged() === true\n });\n }\n}\n\nexport const SqlApiCoreStorageOperationsFactory =\n ApiCoreStorageOperationsFactory.createImplementation({\n implementation: SqlApiCoreStorageOperationsFactoryImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n });\n"],"names":["SqlApiCoreStorageOperationsFactoryImpl","knex","schemaConfig","scopeTenant","createApiCoreSql","SqlApiCoreStorageOperationsFactory","ApiCoreStorageOperationsFactory","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAOA,MAAMA;IACF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;IAClB;IAEI,OAAO,EACVC,WAAW,EAC0B,EAA4B;QACjE,OAAOC,iBAAiB;YACpBD;YACA,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YACtB,iBAAiB,IAAI,CAAC,YAAY,EAAE;YACpC,eAAe,IAAI,CAAC,YAAY,EAAE,gBAAgB;QACtD;IACJ;AACJ;AAEO,MAAME,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBN;IAChB,cAAc;QAACO;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -0,0 +1,18 @@
1
+ import { TenancyStorageOperationsFactory } from "@webiny/api-core/features/storageOperations/abstractions.js";
2
+ import type { TenancyStorageOperations } from "@webiny/api-core/types/tenancy.js";
3
+ import { KnexClient } from "../feature/KnexClient/index.js";
4
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
5
+ /**
6
+ * The tenant registry's storage on the container's connection: the tenants table only. Root's scope
7
+ * reads every tenant's record from it, the request's tenant's included.
8
+ */
9
+ declare class SqlTenancyStorageOperationsFactoryImpl implements TenancyStorageOperationsFactory.Interface {
10
+ private readonly knex;
11
+ private readonly schemaConfig?;
12
+ constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
13
+ create(): TenancyStorageOperations;
14
+ }
15
+ export declare const SqlTenancyStorageOperationsFactory: typeof SqlTenancyStorageOperationsFactoryImpl & {
16
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/storageOperations/abstractions.js").ITenancyStorageOperationsFactory>;
17
+ };
18
+ export {};
@@ -0,0 +1,36 @@
1
+ import { TenancyStorageOperationsFactory } from "@webiny/api-core/features/storageOperations/abstractions.js";
2
+ import { KnexClient } from "../feature/KnexClient/index.js";
3
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
4
+ import { TableManager } from "../TableManager.js";
5
+ import { createStorageOperations } from "../tenancy/index.js";
6
+ class SqlTenancyStorageOperationsFactoryImpl {
7
+ constructor(knex, schemaConfig){
8
+ this.knex = knex;
9
+ this.schemaConfig = schemaConfig;
10
+ }
11
+ create() {
12
+ const knex = this.knex.client;
13
+ const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix, {
14
+ schemaManaged: this.schemaConfig?.isManaged() === true
15
+ });
16
+ return createStorageOperations({
17
+ knex,
18
+ tableManager
19
+ });
20
+ }
21
+ }
22
+ const SqlTenancyStorageOperationsFactory = TenancyStorageOperationsFactory.createImplementation({
23
+ implementation: SqlTenancyStorageOperationsFactoryImpl,
24
+ dependencies: [
25
+ KnexClient,
26
+ [
27
+ SqlSchemaConfig,
28
+ {
29
+ optional: true
30
+ }
31
+ ]
32
+ ]
33
+ });
34
+ export { SqlTenancyStorageOperationsFactory };
35
+
36
+ //# sourceMappingURL=SqlTenancyStorageOperationsFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreStorage/SqlTenancyStorageOperationsFactory.js","sources":["../../src/coreStorage/SqlTenancyStorageOperationsFactory.ts"],"sourcesContent":["// A deep import: the package root pulls in all of api-core.\nimport { TenancyStorageOperationsFactory } from \"@webiny/api-core/features/storageOperations/abstractions.js\";\nimport type { TenancyStorageOperations } from \"@webiny/api-core/types/tenancy.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"~/tenancy/index.js\";\n\n/**\n * The tenant registry's storage on the container's connection: the tenants table only. Root's scope\n * reads every tenant's record from it, the request's tenant's included.\n */\nclass SqlTenancyStorageOperationsFactoryImpl implements TenancyStorageOperationsFactory.Interface {\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public create(): TenancyStorageOperations {\n const knex = this.knex.client;\n const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix, {\n schemaManaged: this.schemaConfig?.isManaged() === true\n });\n return createTenancyStorageOperations({ knex, tableManager });\n }\n}\n\nexport const SqlTenancyStorageOperationsFactory =\n TenancyStorageOperationsFactory.createImplementation({\n implementation: SqlTenancyStorageOperationsFactoryImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n });\n"],"names":["SqlTenancyStorageOperationsFactoryImpl","knex","schemaConfig","tableManager","TableManager","createTenancyStorageOperations","SqlTenancyStorageOperationsFactory","TenancyStorageOperationsFactory","KnexClient","SqlSchemaConfig"],"mappings":";;;;;AAYA,MAAMA;IACF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;IAClB;IAEI,SAAmC;QACtC,MAAMD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;QAC7B,MAAME,eAAe,IAAIC,aAAaH,MAAM,IAAI,CAAC,YAAY,EAAE,iBAAiB;YAC5E,eAAe,IAAI,CAAC,YAAY,EAAE,gBAAgB;QACtD;QACA,OAAOI,wBAA+B;YAAEJ;YAAME;QAAa;IAC/D;AACJ;AAEO,MAAMG,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -0,0 +1,19 @@
1
+ import { TenantStorageNotReadyError, TenantStorageReadiness } from "@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js";
2
+ import { Result } from "@webiny/feature/api";
3
+ import { KnexClient } from "../feature/KnexClient/index.js";
4
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
5
+ /**
6
+ * A SQL storage can take a new tenant when its database answers and, when its schema is managed (set
7
+ * up before the API took traffic, so nothing creates tables at runtime), the schema setup ran on it.
8
+ * An unmanaged schema creates its tables on first use, so there's nothing more to check.
9
+ */
10
+ declare class SqlTenantStorageReadinessImpl implements TenantStorageReadiness.Interface {
11
+ private knexClient;
12
+ private schemaConfig;
13
+ constructor(knexClient: KnexClient.Interface, schemaConfig: SqlSchemaConfig.Interface | undefined);
14
+ check(): Promise<Result<void, TenantStorageNotReadyError>>;
15
+ }
16
+ export declare const SqlTenantStorageReadiness: typeof SqlTenantStorageReadinessImpl & {
17
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/tenancy/TenantStorageReadiness/abstractions").ITenantStorageReadiness>;
18
+ };
19
+ export {};
@@ -0,0 +1,48 @@
1
+ import { TenantStorageNotReadyError, TenantStorageReadiness } from "@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js";
2
+ import { Result } from "@webiny/feature/api";
3
+ import { KnexClient } from "../feature/KnexClient/index.js";
4
+ import { SqlSchemaConfig } from "../schemaConfig/index.js";
5
+ const ROLES_TABLE = "webiny_core_roles";
6
+ class SqlTenantStorageReadinessImpl {
7
+ constructor(knexClient, schemaConfig){
8
+ this.knexClient = knexClient;
9
+ this.schemaConfig = schemaConfig;
10
+ }
11
+ async check() {
12
+ const knex = this.knexClient.client;
13
+ try {
14
+ await knex.raw("SELECT 1");
15
+ } catch (error) {
16
+ return Result.fail(TenantStorageNotReadyError.unreachable(`the database is not reachable (${messageOf(error)}).`));
17
+ }
18
+ if (!this.schemaConfig?.isManaged()) return Result.ok();
19
+ const prefix = this.schemaConfig.tableNamePrefix;
20
+ const table = prefix ? `${prefix}_${ROLES_TABLE}` : ROLES_TABLE;
21
+ let hasTable;
22
+ try {
23
+ hasTable = await knex.schema.hasTable(table);
24
+ } catch (error) {
25
+ return Result.fail(TenantStorageNotReadyError.unreachable(`the database is not reachable (${messageOf(error)}).`));
26
+ }
27
+ if (!hasTable) return Result.fail(TenantStorageNotReadyError.notSetUp(`its schema is not set up (table "${table}" is missing).`));
28
+ return Result.ok();
29
+ }
30
+ }
31
+ function messageOf(error) {
32
+ return error instanceof Error ? error.message : String(error);
33
+ }
34
+ const SqlTenantStorageReadiness = TenantStorageReadiness.createImplementation({
35
+ implementation: SqlTenantStorageReadinessImpl,
36
+ dependencies: [
37
+ KnexClient,
38
+ [
39
+ SqlSchemaConfig,
40
+ {
41
+ optional: true
42
+ }
43
+ ]
44
+ ]
45
+ });
46
+ export { SqlTenantStorageReadiness };
47
+
48
+ //# sourceMappingURL=SqlTenantStorageReadiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreStorage/SqlTenantStorageReadiness.js","sources":["../../src/coreStorage/SqlTenantStorageReadiness.ts"],"sourcesContent":["// A deep import: the package root pulls in all of api-core.\nimport {\n TenantStorageNotReadyError,\n TenantStorageReadiness\n} from \"@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\n\n/** A table every installation writes to (the security installer's roles). */\nconst ROLES_TABLE = \"webiny_core_roles\";\n\n/**\n * A SQL storage can take a new tenant when its database answers and, when its schema is managed (set\n * up before the API took traffic, so nothing creates tables at runtime), the schema setup ran on it.\n * An unmanaged schema creates its tables on first use, so there's nothing more to check.\n */\nclass SqlTenantStorageReadinessImpl implements TenantStorageReadiness.Interface {\n constructor(\n private knexClient: KnexClient.Interface,\n private schemaConfig: SqlSchemaConfig.Interface | undefined\n ) {}\n\n async check(): Promise<Result<void, TenantStorageNotReadyError>> {\n const knex = this.knexClient.client;\n try {\n await knex.raw(\"SELECT 1\");\n } catch (error) {\n return Result.fail(\n TenantStorageNotReadyError.unreachable(\n `the database is not reachable (${messageOf(error)}).`\n )\n );\n }\n\n if (!this.schemaConfig?.isManaged()) {\n return Result.ok();\n }\n const prefix = this.schemaConfig.tableNamePrefix;\n const table = prefix ? `${prefix}_${ROLES_TABLE}` : ROLES_TABLE;\n let hasTable: boolean;\n try {\n hasTable = await knex.schema.hasTable(table);\n } catch (error) {\n return Result.fail(\n TenantStorageNotReadyError.unreachable(\n `the database is not reachable (${messageOf(error)}).`\n )\n );\n }\n if (!hasTable) {\n return Result.fail(\n TenantStorageNotReadyError.notSetUp(\n `its schema is not set up (table \"${table}\" is missing).`\n )\n );\n }\n return Result.ok();\n }\n}\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nexport const SqlTenantStorageReadiness = TenantStorageReadiness.createImplementation({\n implementation: SqlTenantStorageReadinessImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["ROLES_TABLE","SqlTenantStorageReadinessImpl","knexClient","schemaConfig","knex","error","Result","TenantStorageNotReadyError","messageOf","prefix","table","hasTable","Error","String","SqlTenantStorageReadiness","TenantStorageReadiness","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAUA,MAAMA,cAAc;AAOpB,MAAMC;IACF,YACYC,UAAgC,EAChCC,YAAmD,CAC7D;aAFUD,UAAU,GAAVA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,QAA2D;QAC7D,MAAMC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM;QACnC,IAAI;YACA,MAAMA,KAAK,GAAG,CAAC;QACnB,EAAE,OAAOC,OAAO;YACZ,OAAOC,OAAO,IAAI,CACdC,2BAA2B,WAAW,CAClC,CAAC,+BAA+B,EAAEC,UAAUH,OAAO,EAAE,CAAC;QAGlE;QAEA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,aACpB,OAAOC,OAAO,EAAE;QAEpB,MAAMG,SAAS,IAAI,CAAC,YAAY,CAAC,eAAe;QAChD,MAAMC,QAAQD,SAAS,GAAGA,OAAO,CAAC,EAAET,aAAa,GAAGA;QACpD,IAAIW;QACJ,IAAI;YACAA,WAAW,MAAMP,KAAK,MAAM,CAAC,QAAQ,CAACM;QAC1C,EAAE,OAAOL,OAAO;YACZ,OAAOC,OAAO,IAAI,CACdC,2BAA2B,WAAW,CAClC,CAAC,+BAA+B,EAAEC,UAAUH,OAAO,EAAE,CAAC;QAGlE;QACA,IAAI,CAACM,UACD,OAAOL,OAAO,IAAI,CACdC,2BAA2B,QAAQ,CAC/B,CAAC,iCAAiC,EAAEG,MAAM,cAAc,CAAC;QAIrE,OAAOJ,OAAO,EAAE;IACpB;AACJ;AAEA,SAASE,UAAUH,KAAc;IAC7B,OAAOA,iBAAiBO,QAAQP,MAAM,OAAO,GAAGQ,OAAOR;AAC3D;AAEO,MAAMS,4BAA4BC,uBAAuB,oBAAoB,CAAC;IACjF,gBAAgBd;IAChB,cAAc;QAACe;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The SQL core storage of a tenant scope: the implementation of `ApiCoreStorageOperationsFactory`,
3
+ * which `ApiCoreFeature.register` resolves and builds, the tenant registry's
4
+ * (`TenancyStorageOperationsFactory`, used in root's scope and the default storage's), and the `core`
5
+ * schema setup step. Mirrors `ApiCoreDdbFeature`.
6
+ *
7
+ * Registered per request (by the SQL storage's `RequestStorage`). It runs on what the root holds:
8
+ * the connection (`KnexClient`) and the table prefix and schema-managed setting (`SqlSchemaConfig`),
9
+ * both registered by `SqlConnectionFeature`.
10
+ */
11
+ export declare const ApiCoreSqlFeature: {
12
+ name: string;
13
+ register(container: import("@webiny/di").Container): void;
14
+ };
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { SqlApiCoreStorageOperationsFactory } from "./SqlApiCoreStorageOperationsFactory.js";
3
+ import { CoreSqlSchemaSetup } from "./CoreSqlSchemaSetup.js";
4
+ import { SqlTenancyStorageOperationsFactory } from "./SqlTenancyStorageOperationsFactory.js";
5
+ import { SqlTenantStorageReadiness } from "./SqlTenantStorageReadiness.js";
6
+ const ApiCoreSqlFeature = createFeature({
7
+ name: "ApiCoreSql",
8
+ register (container) {
9
+ container.register(SqlApiCoreStorageOperationsFactory);
10
+ container.register(SqlTenancyStorageOperationsFactory);
11
+ container.register(CoreSqlSchemaSetup);
12
+ container.register(SqlTenantStorageReadiness);
13
+ }
14
+ });
15
+ export { ApiCoreSqlFeature };
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreStorage/feature.js","sources":["../../src/coreStorage/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SqlApiCoreStorageOperationsFactory } from \"./SqlApiCoreStorageOperationsFactory.js\";\nimport { CoreSqlSchemaSetup } from \"./CoreSqlSchemaSetup.js\";\nimport { SqlTenancyStorageOperationsFactory } from \"./SqlTenancyStorageOperationsFactory.js\";\nimport { SqlTenantStorageReadiness } from \"./SqlTenantStorageReadiness.js\";\n\n/**\n * The SQL core storage of a tenant scope: the implementation of `ApiCoreStorageOperationsFactory`,\n * which `ApiCoreFeature.register` resolves and builds, the tenant registry's\n * (`TenancyStorageOperationsFactory`, used in root's scope and the default storage's), and the `core`\n * schema setup step. Mirrors `ApiCoreDdbFeature`.\n *\n * Registered per request (by the SQL storage's `RequestStorage`). It runs on what the root holds:\n * the connection (`KnexClient`) and the table prefix and schema-managed setting (`SqlSchemaConfig`),\n * both registered by `SqlConnectionFeature`.\n */\nexport const ApiCoreSqlFeature = createFeature({\n name: \"ApiCoreSql\",\n register(container) {\n container.register(SqlApiCoreStorageOperationsFactory);\n container.register(SqlTenancyStorageOperationsFactory);\n container.register(CoreSqlSchemaSetup);\n container.register(SqlTenantStorageReadiness);\n }\n});\n"],"names":["ApiCoreSqlFeature","createFeature","container","SqlApiCoreStorageOperationsFactory","SqlTenancyStorageOperationsFactory","CoreSqlSchemaSetup","SqlTenantStorageReadiness"],"mappings":";;;;;AAgBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;IACvB;AACJ"}
@@ -0,0 +1 @@
1
+ export { ApiCoreSqlFeature } from "./feature.js";
@@ -0,0 +1 @@
1
+ export { ApiCoreSqlFeature } from "./feature.js";
@@ -1,8 +1,26 @@
1
1
  import type { Knex } from "knex";
2
2
  import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
3
+ import { TableManager } from "./TableManager.js";
4
+ import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
3
5
  interface CreateApiCoreSqlParams {
4
6
  knex: Knex;
5
7
  tableNamePrefix?: string;
8
+ /** The schema was set up before the API took traffic: no table checks at runtime. */
9
+ schemaManaged?: boolean;
10
+ /**
11
+ * The tenant the storage acts on: its tenant scope's. The tenant records and the key-value store
12
+ * don't use it (the tenant registry is tenant-neutral, and the store is keyed by its own scope).
13
+ */
14
+ scopeTenant: ScopeTenant.Interface;
6
15
  }
7
- export declare const createApiCoreSql: ({ knex, tableNamePrefix }: CreateApiCoreSqlParams) => ApiCoreStorageOperations;
16
+ /**
17
+ * The core storage operations (users, tenancy, security, key-value store) on `tableManager`, which
18
+ * they declare their tables on.
19
+ */
20
+ export declare const createApiCoreSqlOperations: (knex: Knex, tableManager: TableManager, scopeTenant: ScopeTenant.Interface) => ApiCoreStorageOperations;
21
+ /**
22
+ * The core storage operations on a connection. Cheap to build: what the table checks learn is kept
23
+ * for the process (see `TableManager`), so they are built per request.
24
+ */
25
+ export declare const createApiCoreSql: ({ knex, tableNamePrefix, schemaManaged, scopeTenant }: CreateApiCoreSqlParams) => ApiCoreStorageOperations;
8
26
  export {};
@@ -1,17 +1,13 @@
1
- import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
2
1
  import { createStorageOperations } from "./adminUsers/index.js";
3
2
  import { createStorageOperations as index_js_createStorageOperations } from "./tenancy/index.js";
4
3
  import { createStorageOperations as external_security_index_js_createStorageOperations } from "./security/index.js";
5
4
  import { createStorageOperations as external_keyValueStore_index_js_createStorageOperations } from "./keyValueStore/index.js";
6
5
  import { TableManager } from "./TableManager.js";
7
- import { SqlServiceManifestLoader } from "./serviceDiscovery/index.js";
8
- const createApiCoreSql = ({ knex, tableNamePrefix })=>{
9
- const tableManager = new TableManager(knex, tableNamePrefix);
10
- ServiceDiscovery.setLoader(new SqlServiceManifestLoader(knex, tableManager));
11
- return {
6
+ const createApiCoreSqlOperations = (knex, tableManager, scopeTenant)=>({
12
7
  usersStorageOperations: createStorageOperations({
13
8
  knex,
14
- tableManager
9
+ tableManager,
10
+ scopeTenant
15
11
  }),
16
12
  tenancyStorageOperations: index_js_createStorageOperations({
17
13
  knex,
@@ -19,14 +15,20 @@ const createApiCoreSql = ({ knex, tableNamePrefix })=>{
19
15
  }),
20
16
  securityStorageOperations: external_security_index_js_createStorageOperations({
21
17
  knex,
22
- tableManager
18
+ tableManager,
19
+ scopeTenant
23
20
  }),
24
21
  keyValueStorageOperations: external_keyValueStore_index_js_createStorageOperations({
25
22
  knex,
26
23
  tableManager
27
24
  })
28
- };
25
+ });
26
+ const createApiCoreSql = ({ knex, tableNamePrefix, schemaManaged, scopeTenant })=>{
27
+ const tableManager = new TableManager(knex, tableNamePrefix, {
28
+ schemaManaged
29
+ });
30
+ return createApiCoreSqlOperations(knex, tableManager, scopeTenant);
29
31
  };
30
- export { createApiCoreSql };
32
+ export { createApiCoreSql, createApiCoreSqlOperations };
31
33
 
32
34
  //# sourceMappingURL=createApiCoreSql.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createApiCoreSql.js","sources":["../src/createApiCoreSql.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { createStorageOperations as createUsersStorageOperations } from \"./adminUsers/index.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\nimport { createStorageOperations as createSecurityStorageOperations } from \"./security/index.js\";\nimport { createStorageOperations as createKeyValueStorageOperations } from \"./keyValueStore/index.js\";\nimport { TableManager } from \"./TableManager.js\";\nimport { SqlServiceManifestLoader } from \"./serviceDiscovery/index.js\";\n\ninterface CreateApiCoreSqlParams {\n knex: Knex;\n tableNamePrefix?: string;\n}\n\nexport const createApiCoreSql = ({\n knex,\n tableNamePrefix\n}: CreateApiCoreSqlParams): ApiCoreStorageOperations => {\n const tableManager = new TableManager(knex, tableNamePrefix);\n\n ServiceDiscovery.setLoader(new SqlServiceManifestLoader(knex, tableManager));\n\n return {\n usersStorageOperations: createUsersStorageOperations({\n knex,\n tableManager\n }),\n tenancyStorageOperations: createTenancyStorageOperations({\n knex,\n tableManager\n }),\n securityStorageOperations: createSecurityStorageOperations({\n knex,\n tableManager\n }),\n keyValueStorageOperations: createKeyValueStorageOperations({\n knex,\n tableManager\n })\n };\n};\n"],"names":["createApiCoreSql","knex","tableNamePrefix","tableManager","TableManager","ServiceDiscovery","SqlServiceManifestLoader","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations"],"mappings":";;;;;;;AAeO,MAAMA,mBAAmB,CAAC,EAC7BC,IAAI,EACJC,eAAe,EACM;IACrB,MAAMC,eAAe,IAAIC,aAAaH,MAAMC;IAE5CG,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBL,MAAME;IAE9D,OAAO;QACH,wBAAwBI,wBAA6B;YACjDN;YACAE;QACJ;QACA,0BAA0BK,iCAA+B;YACrDP;YACAE;QACJ;QACA,2BAA2BM,mDAAgC;YACvDR;YACAE;QACJ;QACA,2BAA2BO,wDAAgC;YACvDT;YACAE;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"createApiCoreSql.js","sources":["../src/createApiCoreSql.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport { createStorageOperations as createUsersStorageOperations } from \"./adminUsers/index.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\nimport { createStorageOperations as createSecurityStorageOperations } from \"./security/index.js\";\nimport { createStorageOperations as createKeyValueStorageOperations } from \"./keyValueStore/index.js\";\nimport { TableManager } from \"./TableManager.js\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\ninterface CreateApiCoreSqlParams {\n knex: Knex;\n tableNamePrefix?: string;\n /** The schema was set up before the API took traffic: no table checks at runtime. */\n schemaManaged?: boolean;\n /**\n * The tenant the storage acts on: its tenant scope's. The tenant records and the key-value store\n * don't use it (the tenant registry is tenant-neutral, and the store is keyed by its own scope).\n */\n scopeTenant: ScopeTenant.Interface;\n}\n\n/**\n * The core storage operations (users, tenancy, security, key-value store) on `tableManager`, which\n * they declare their tables on.\n */\nexport const createApiCoreSqlOperations = (\n knex: Knex,\n tableManager: TableManager,\n scopeTenant: ScopeTenant.Interface\n): ApiCoreStorageOperations => {\n return {\n usersStorageOperations: createUsersStorageOperations({ knex, tableManager, scopeTenant }),\n tenancyStorageOperations: createTenancyStorageOperations({ knex, tableManager }),\n securityStorageOperations: createSecurityStorageOperations({\n knex,\n tableManager,\n scopeTenant\n }),\n keyValueStorageOperations: createKeyValueStorageOperations({ knex, tableManager })\n };\n};\n\n/**\n * The core storage operations on a connection. Cheap to build: what the table checks learn is kept\n * for the process (see `TableManager`), so they are built per request.\n */\nexport const createApiCoreSql = ({\n knex,\n tableNamePrefix,\n schemaManaged,\n scopeTenant\n}: CreateApiCoreSqlParams): ApiCoreStorageOperations => {\n const tableManager = new TableManager(knex, tableNamePrefix, { schemaManaged });\n return createApiCoreSqlOperations(knex, tableManager, scopeTenant);\n};\n"],"names":["createApiCoreSqlOperations","knex","tableManager","scopeTenant","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations","createApiCoreSql","tableNamePrefix","schemaManaged","TableManager"],"mappings":";;;;;AAyBO,MAAMA,6BAA6B,CACtCC,MACAC,cACAC,cAEO;QACH,wBAAwBC,wBAA6B;YAAEH;YAAMC;YAAcC;QAAY;QACvF,0BAA0BE,iCAA+B;YAAEJ;YAAMC;QAAa;QAC9E,2BAA2BI,mDAAgC;YACvDL;YACAC;YACAC;QACJ;QACA,2BAA2BI,wDAAgC;YAAEN;YAAMC;QAAa;IACpF;AAOG,MAAMM,mBAAmB,CAAC,EAC7BP,IAAI,EACJQ,eAAe,EACfC,aAAa,EACbP,WAAW,EACU;IACrB,MAAMD,eAAe,IAAIS,aAAaV,MAAMQ,iBAAiB;QAAEC;IAAc;IAC7E,OAAOV,2BAA2BC,MAAMC,cAAcC;AAC1D"}