firebase-tools-with-isolate 13.16.0 → 13.26.0
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.
- package/lib/api.js +3 -1
- package/lib/apiv2.js +10 -3
- package/lib/appdistribution/client.js +62 -8
- package/lib/appdistribution/distribution.js +1 -1
- package/lib/apphosting/backend.js +299 -0
- package/lib/apphosting/config.js +31 -8
- package/lib/apphosting/githubConnections.js +70 -22
- package/lib/apphosting/index.js +3 -312
- package/lib/apphosting/rollout.js +138 -0
- package/lib/apphosting/secrets/index.js +70 -5
- package/lib/apphosting/utils.js +41 -0
- package/lib/apphosting/yaml.js +82 -0
- package/lib/archiveDirectory.js +1 -1
- package/lib/auth.js +31 -5
- package/lib/bin/firebase.js +2 -2
- package/lib/command.js +18 -4
- package/lib/commands/appdistribution-distribute.js +4 -4
- package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
- package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
- package/lib/commands/appdistribution-groups-list.js +55 -0
- package/lib/commands/appdistribution-testers-list.js +52 -0
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +4 -4
- package/lib/commands/apphosting-backends-delete.js +7 -15
- package/lib/commands/apphosting-backends-get.js +1 -1
- package/lib/commands/apphosting-config-export.js +51 -0
- package/lib/commands/apphosting-repos-create.js +23 -0
- package/lib/commands/apphosting-rollouts-create.js +14 -15
- package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
- package/lib/commands/database-import.js +4 -2
- package/lib/commands/database-push.js +4 -2
- package/lib/commands/database-set.js +4 -2
- package/lib/commands/database-settings-get.js +1 -1
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +4 -1
- package/lib/commands/dataconnect-services-list.js +4 -3
- package/lib/commands/dataconnect-sql-diff.js +1 -1
- package/lib/commands/dataconnect-sql-grant.js +37 -0
- package/lib/commands/dataconnect-sql-migrate.js +1 -1
- package/lib/commands/dataconnect-sql-shell.js +115 -0
- package/lib/commands/deploy.js +2 -0
- package/lib/commands/emulators-start.js +4 -1
- package/lib/commands/ext-dev-init.js +2 -2
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +2 -2
- package/lib/commands/ext-dev-upload.js +2 -2
- package/lib/commands/ext-dev-usage.js +2 -2
- package/lib/commands/ext-info.js +3 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-sdk-install.js +88 -0
- package/lib/commands/ext.js +1 -0
- package/lib/commands/firestore-databases-restore.js +39 -1
- package/lib/commands/functions-secrets-access.js +2 -4
- package/lib/commands/index.js +15 -2
- package/lib/commands/init.js +25 -15
- package/lib/commands/setup-emulators-dataconnect.js +0 -13
- package/lib/commands/use.js +1 -1
- package/lib/config.js +14 -4
- package/lib/crashlytics/buildToolsJarHelper.js +2 -2
- package/lib/dataconnect/client.js +1 -1
- package/lib/dataconnect/dataplaneClient.js +12 -9
- package/lib/dataconnect/ensureApis.js +6 -1
- package/lib/dataconnect/fileUtils.js +15 -39
- package/lib/dataconnect/freeTrial.js +45 -9
- package/lib/dataconnect/load.js +3 -1
- package/lib/dataconnect/provisionCloudSql.js +39 -26
- package/lib/dataconnect/schemaMigration.js +215 -74
- package/lib/dataconnect/types.js +4 -1
- package/lib/dataconnect/webhook.js +32 -0
- package/lib/deploy/dataconnect/deploy.js +18 -15
- package/lib/deploy/dataconnect/prepare.js +41 -0
- package/lib/deploy/dataconnect/release.js +16 -7
- package/lib/deploy/extensions/deploy.js +3 -1
- package/lib/deploy/extensions/deploymentSummary.js +7 -3
- package/lib/deploy/extensions/planner.js +44 -5
- package/lib/deploy/extensions/prepare.js +45 -73
- package/lib/deploy/extensions/release.js +11 -10
- package/lib/deploy/extensions/tasks.js +32 -21
- package/lib/deploy/firestore/prepare.js +9 -0
- package/lib/deploy/firestore/release.js +3 -6
- package/lib/deploy/functions/checkIam.js +7 -2
- package/lib/deploy/functions/ensure.js +11 -3
- package/lib/deploy/functions/prepare.js +10 -2
- package/lib/deploy/functions/release/planner.js +2 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
- package/lib/deploy/functions/runtimes/node/index.js +5 -0
- package/lib/deploy/functions/services/auth.js +34 -3
- package/lib/deploy/functions/services/index.js +2 -0
- package/lib/deploy/index.js +8 -5
- package/lib/deploy/lifecycleHooks.js +2 -1
- package/lib/emulator/apphosting/config.js +27 -0
- package/lib/emulator/apphosting/index.js +38 -0
- package/lib/emulator/apphosting/serve.js +50 -0
- package/lib/emulator/apphosting/utils.js +18 -0
- package/lib/emulator/auth/handlers.js +27 -0
- package/lib/emulator/auth/operations.js +41 -2
- package/lib/emulator/auth/state.js +2 -1
- package/lib/emulator/commandUtils.js +8 -3
- package/lib/emulator/constants.js +4 -1
- package/lib/emulator/controller.js +48 -5
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
- package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
- package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
- package/lib/emulator/dataconnect/pgliteServer.js +95 -0
- package/lib/emulator/dataconnectEmulator.js +58 -75
- package/lib/emulator/dataconnectToolkitController.js +44 -0
- package/lib/emulator/downloadableEmulators.js +27 -16
- package/lib/emulator/emulatorLogger.js +3 -0
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/extensionsEmulator.js +38 -6
- package/lib/emulator/functionsEmulator.js +85 -41
- package/lib/emulator/functionsEmulatorShared.js +2 -1
- package/lib/emulator/functionsRuntimeWorker.js +2 -1
- package/lib/emulator/hub.js +13 -9
- package/lib/emulator/hubExport.js +10 -3
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/portUtils.js +10 -11
- package/lib/emulator/registry.js +1 -0
- package/lib/emulator/storage/persistence.js +2 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/tasksEmulator.js +5 -2
- package/lib/emulator/types.js +3 -0
- package/lib/emulator/ui.js +51 -25
- package/lib/error.js +31 -1
- package/lib/experiments.js +5 -0
- package/lib/extensions/emulator/triggerHelper.js +1 -1
- package/lib/extensions/extensionsApi.js +14 -10
- package/lib/extensions/extensionsHelper.js +15 -6
- package/lib/extensions/localHelper.js +31 -0
- package/lib/extensions/runtimes/common.js +179 -39
- package/lib/extensions/runtimes/node.js +401 -0
- package/lib/extensions/types.js +25 -14
- package/lib/extensions/warnings.js +5 -2
- package/lib/firestore/api.js +2 -1
- package/lib/firestore/checkDatabaseType.js +10 -3
- package/lib/firestore/delete.js +11 -0
- package/lib/firestore/options.js +7 -0
- package/lib/frameworks/angular/index.js +15 -3
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/flutter/index.js +6 -6
- package/lib/frameworks/flutter/utils.js +34 -1
- package/lib/frameworks/next/index.js +10 -2
- package/lib/frameworks/next/utils.js +8 -5
- package/lib/frameworks/vite/index.js +2 -2
- package/lib/fsutils.js +13 -1
- package/lib/functions/constants.js +4 -0
- package/lib/functions/events/v1.js +9 -2
- package/lib/gcp/apphosting.js +1 -1
- package/lib/gcp/cloudmonitoring.js +3 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
- package/lib/gcp/cloudsql/connect.js +49 -37
- package/lib/gcp/cloudsql/interactive.js +49 -0
- package/lib/gcp/cloudsql/permissions.js +165 -0
- package/lib/gcp/devConnect.js +38 -1
- package/lib/gcp/firestore.js +5 -1
- package/lib/gcp/secretManager.js +12 -5
- package/lib/getProjectNumber.js +1 -1
- package/lib/init/features/apphosting.js +15 -0
- package/lib/init/features/dataconnect/index.js +159 -120
- package/lib/init/features/dataconnect/sdk.js +77 -84
- package/lib/init/features/emulators.js +2 -15
- package/lib/init/features/firestore/index.js +20 -1
- package/lib/init/features/firestore/indexes.js +4 -4
- package/lib/init/features/genkit/index.js +444 -0
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/init/features/index.js +1 -1
- package/lib/init/features/project.js +6 -6
- package/lib/init/features/storage.js +0 -2
- package/lib/init/index.js +1 -0
- package/lib/init/spawn.js +23 -2
- package/lib/logger.js +2 -2
- package/lib/management/projects.js +24 -4
- package/lib/projectUtils.js +1 -1
- package/lib/prompt.js +1 -1
- package/lib/rc.js +1 -8
- package/lib/requireAuth.js +19 -5
- package/lib/requireDatabaseInstance.js +1 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/responseToError.js +5 -2
- package/lib/rulesDeploy.js +1 -1
- package/lib/templates.js +2 -2
- package/lib/utils.js +16 -11
- package/lib/vsCodeUtils.js +8 -0
- package/package.json +7 -6
- package/schema/connector-yaml.json +57 -17
- package/schema/firebase-config.json +24 -0
- package/templates/extensions/javascript/package.lint.json +2 -2
- package/templates/extensions/javascript/package.nolint.json +2 -2
- package/templates/extensions/typescript/package.lint.json +2 -2
- package/templates/extensions/typescript/package.nolint.json +2 -2
- package/templates/genkit/firebase.0.9.0.template +57 -0
- package/templates/init/apphosting/apphosting.yaml +23 -0
- package/templates/init/dataconnect/connector.yaml +0 -1
- package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
- package/templates/init/dataconnect/dataconnect.yaml +1 -1
- package/templates/init/dataconnect/queries.gql +1 -2
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/ensureCloudResourceLocation.js +0 -12
- package/lib/init/features/genkit.js +0 -53
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeBase64 = exports.encodeBase64 = exports.ScramSha256AuthFlow = exports.verifyScramSha256Password = exports.createScramSha256Data = void 0;
|
|
4
|
+
const backend_error_1 = require("../../backend-error");
|
|
5
|
+
const connection_1 = require("../../connection");
|
|
6
|
+
const crypto_1 = require("../../crypto");
|
|
7
|
+
const sasl_mechanism_1 = require("./sasl-mechanism");
|
|
8
|
+
async function createScramSha256Data(password, iterations = 4096) {
|
|
9
|
+
const salt = new Uint8Array(16);
|
|
10
|
+
crypto.getRandomValues(salt);
|
|
11
|
+
const saltedPassword = await (0, crypto_1.pbkdf2)(password, salt, iterations, 32, 'SHA-256');
|
|
12
|
+
const clientKey = await (0, crypto_1.createHmacKey)(saltedPassword, 'Client Key', 'SHA-256');
|
|
13
|
+
const storedKey = await (0, crypto_1.createHashKey)(clientKey, 'SHA-256');
|
|
14
|
+
const serverKey = await (0, crypto_1.createHmacKey)(saltedPassword, 'Server Key', 'SHA-256');
|
|
15
|
+
return {
|
|
16
|
+
salt: encodeBase64(salt),
|
|
17
|
+
iterations,
|
|
18
|
+
storedKey: encodeBase64(storedKey),
|
|
19
|
+
serverKey: encodeBase64(serverKey),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.createScramSha256Data = createScramSha256Data;
|
|
23
|
+
async function verifyScramSha256Password(params) {
|
|
24
|
+
const { authMessage, clientProof, storedKey } = params;
|
|
25
|
+
const clientProofBuffer = decodeBase64(clientProof);
|
|
26
|
+
const storedKeyBuffer = decodeBase64(storedKey);
|
|
27
|
+
const clientSignature = await (0, crypto_1.createHmacKey)(storedKeyBuffer, authMessage, 'SHA-256');
|
|
28
|
+
const clientSignatureView = new Uint8Array(clientSignature);
|
|
29
|
+
const clientKey = new Uint8Array(clientProofBuffer.length);
|
|
30
|
+
for (let i = 0; i < clientProofBuffer.length; i++) {
|
|
31
|
+
clientKey[i] = clientProofBuffer[i] ^ clientSignatureView[i];
|
|
32
|
+
}
|
|
33
|
+
const computedStoredKey = await (0, crypto_1.createHashKey)(clientKey, 'SHA-256');
|
|
34
|
+
return await (0, crypto_1.timingSafeEqual)(storedKeyBuffer, computedStoredKey);
|
|
35
|
+
}
|
|
36
|
+
exports.verifyScramSha256Password = verifyScramSha256Password;
|
|
37
|
+
const ScramSha256Step = {
|
|
38
|
+
Initial: 'Initial',
|
|
39
|
+
ServerFirstMessage: 'ServerFirstMessage',
|
|
40
|
+
ServerFinalMessage: 'ServerFinalMessage',
|
|
41
|
+
Completed: 'Completed',
|
|
42
|
+
};
|
|
43
|
+
class ScramSha256AuthFlow extends sasl_mechanism_1.SaslMechanism {
|
|
44
|
+
constructor(params) {
|
|
45
|
+
super({ writer: params.writer });
|
|
46
|
+
this.step = ScramSha256Step.Initial;
|
|
47
|
+
this.username = params.username;
|
|
48
|
+
this.auth = {
|
|
49
|
+
...params.auth,
|
|
50
|
+
validateCredentials: params.auth.validateCredentials ??
|
|
51
|
+
(async ({ authMessage, clientProof, scramSha256Data }) => {
|
|
52
|
+
return verifyScramSha256Password({
|
|
53
|
+
authMessage,
|
|
54
|
+
clientProof,
|
|
55
|
+
storedKey: scramSha256Data.storedKey,
|
|
56
|
+
});
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
this.reader = params.reader;
|
|
60
|
+
this.connectionState = params.connectionState;
|
|
61
|
+
}
|
|
62
|
+
async getScramSha256Data(params) {
|
|
63
|
+
if (!this.scramSha256Data) {
|
|
64
|
+
this.scramSha256Data = await this.auth.getScramSha256Data(params, this.connectionState);
|
|
65
|
+
}
|
|
66
|
+
return this.scramSha256Data;
|
|
67
|
+
}
|
|
68
|
+
createInitialAuthMessage() {
|
|
69
|
+
return this.createAuthenticationSASL();
|
|
70
|
+
}
|
|
71
|
+
async *handleClientMessage(message) {
|
|
72
|
+
switch (this.step) {
|
|
73
|
+
case ScramSha256Step.Initial:
|
|
74
|
+
return yield* this.handleClientFirstMessage(message);
|
|
75
|
+
case ScramSha256Step.ServerFirstMessage:
|
|
76
|
+
return yield* this.handleClientFinalMessage(message);
|
|
77
|
+
default:
|
|
78
|
+
throw new Error('Unexpected SCRAM-SHA-256 authentication step');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async *handleClientFirstMessage(message) {
|
|
82
|
+
const length = this.reader.int32();
|
|
83
|
+
const saslMechanism = this.reader.cstring();
|
|
84
|
+
if (saslMechanism !== 'SCRAM-SHA-256') {
|
|
85
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
86
|
+
severity: 'FATAL',
|
|
87
|
+
code: '28000',
|
|
88
|
+
message: 'Unsupported SASL authentication mechanism',
|
|
89
|
+
});
|
|
90
|
+
yield connection_1.closeSignal;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const responseLength = this.reader.int32();
|
|
94
|
+
const clientFirstMessage = this.reader.string(responseLength);
|
|
95
|
+
const serverFirstMessage = await this.createServerFirstMessage(clientFirstMessage);
|
|
96
|
+
this.step = ScramSha256Step.ServerFirstMessage;
|
|
97
|
+
yield this.createAuthenticationSASLContinue(serverFirstMessage);
|
|
98
|
+
}
|
|
99
|
+
async createServerFirstMessage(clientFirstMessage) {
|
|
100
|
+
const clientFirstMessageParts = clientFirstMessage.split(',');
|
|
101
|
+
this.clientFirstMessageBare = clientFirstMessageParts.slice(2).join(',');
|
|
102
|
+
const clientNonce = clientFirstMessageParts.find((part) => part.startsWith('r='))?.substring(2) || '';
|
|
103
|
+
const serverNoncePart = new Uint8Array(18);
|
|
104
|
+
crypto.getRandomValues(serverNoncePart);
|
|
105
|
+
this.serverNonce = clientNonce + encodeBase64(serverNoncePart);
|
|
106
|
+
const { salt, iterations } = await this.getScramSha256Data({
|
|
107
|
+
username: this.username,
|
|
108
|
+
});
|
|
109
|
+
this.serverFirstMessage = `r=${this.serverNonce},s=${salt},i=${iterations}`;
|
|
110
|
+
return this.serverFirstMessage;
|
|
111
|
+
}
|
|
112
|
+
async *handleClientFinalMessage(message) {
|
|
113
|
+
try {
|
|
114
|
+
const serverFinalMessage = await this.createServerFinalMessage(message);
|
|
115
|
+
this.step = ScramSha256Step.Completed;
|
|
116
|
+
yield this.createAuthenticationSASLFinal(serverFinalMessage);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
120
|
+
severity: 'FATAL',
|
|
121
|
+
code: '28000',
|
|
122
|
+
message: error.message,
|
|
123
|
+
});
|
|
124
|
+
yield connection_1.closeSignal;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
get isCompleted() {
|
|
129
|
+
return this.step === ScramSha256Step.Completed;
|
|
130
|
+
}
|
|
131
|
+
async createServerFinalMessage(message) {
|
|
132
|
+
const length = this.reader.int32();
|
|
133
|
+
const stringLength = length - 4;
|
|
134
|
+
const clientFinalMessage = this.reader.string(stringLength);
|
|
135
|
+
const clientFinalMessageParts = clientFinalMessage.split(',');
|
|
136
|
+
const channelBinding = clientFinalMessageParts
|
|
137
|
+
.find((part) => part.startsWith('c='))
|
|
138
|
+
?.substring(2);
|
|
139
|
+
const fullNonce = clientFinalMessageParts.find((part) => part.startsWith('r='))?.substring(2);
|
|
140
|
+
const clientProof = clientFinalMessageParts.find((part) => part.startsWith('p='))?.substring(2);
|
|
141
|
+
if (!channelBinding || !fullNonce || !clientProof) {
|
|
142
|
+
throw new Error('Invalid client final message');
|
|
143
|
+
}
|
|
144
|
+
if (fullNonce !== this.serverNonce) {
|
|
145
|
+
throw new Error('Nonce mismatch');
|
|
146
|
+
}
|
|
147
|
+
const clientFinalMessageWithoutProof = `c=${channelBinding},r=${fullNonce}`;
|
|
148
|
+
const authMessage = `${this.clientFirstMessageBare},${this.serverFirstMessage},${clientFinalMessageWithoutProof}`;
|
|
149
|
+
const data = await this.getScramSha256Data({
|
|
150
|
+
username: this.username,
|
|
151
|
+
});
|
|
152
|
+
const isValid = await this.auth.validateCredentials({
|
|
153
|
+
authMessage,
|
|
154
|
+
clientProof,
|
|
155
|
+
username: this.username,
|
|
156
|
+
scramSha256Data: data,
|
|
157
|
+
}, this.connectionState);
|
|
158
|
+
if (!isValid) {
|
|
159
|
+
throw new Error(`password authentication failed for user "${this.username}"`);
|
|
160
|
+
}
|
|
161
|
+
const serverKeyBuffer = decodeBase64(data.serverKey);
|
|
162
|
+
const serverSignature = await (0, crypto_1.createHmacKey)(serverKeyBuffer, authMessage, 'SHA-256');
|
|
163
|
+
return `v=${encodeBase64(serverSignature)}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ScramSha256AuthFlow = ScramSha256AuthFlow;
|
|
167
|
+
function encodeBase64(data) {
|
|
168
|
+
const uint8 = data;
|
|
169
|
+
let result = "";
|
|
170
|
+
let i;
|
|
171
|
+
const l = uint8.length;
|
|
172
|
+
for (i = 2; i < l; i += 3) {
|
|
173
|
+
result += base64abc[(uint8[i - 2]) >> 2];
|
|
174
|
+
result += base64abc[(((uint8[i - 2]) & 0x03) << 4) |
|
|
175
|
+
((uint8[i - 1]) >> 4)];
|
|
176
|
+
result += base64abc[(((uint8[i - 1]) & 0x0f) << 2) |
|
|
177
|
+
((uint8[i]) >> 6)];
|
|
178
|
+
result += base64abc[(uint8[i]) & 0x3f];
|
|
179
|
+
}
|
|
180
|
+
if (i === l + 1) {
|
|
181
|
+
result += base64abc[(uint8[i - 2]) >> 2];
|
|
182
|
+
result += base64abc[((uint8[i - 2]) & 0x03) << 4];
|
|
183
|
+
result += "==";
|
|
184
|
+
}
|
|
185
|
+
if (i === l) {
|
|
186
|
+
result += base64abc[(uint8[i - 2]) >> 2];
|
|
187
|
+
result += base64abc[(((uint8[i - 2]) & 0x03) << 4) |
|
|
188
|
+
((uint8[i - 1]) >> 4)];
|
|
189
|
+
result += base64abc[((uint8[i - 1]) & 0x0f) << 2];
|
|
190
|
+
result += "=";
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
exports.encodeBase64 = encodeBase64;
|
|
195
|
+
function decodeBase64(b64) {
|
|
196
|
+
const binString = atob(b64);
|
|
197
|
+
const size = binString.length;
|
|
198
|
+
const bytes = new Uint8Array(size);
|
|
199
|
+
for (let i = 0; i < size; i++) {
|
|
200
|
+
bytes[i] = binString.charCodeAt(i);
|
|
201
|
+
}
|
|
202
|
+
return bytes;
|
|
203
|
+
}
|
|
204
|
+
exports.decodeBase64 = decodeBase64;
|
|
205
|
+
const base64abc = [
|
|
206
|
+
"A",
|
|
207
|
+
"B",
|
|
208
|
+
"C",
|
|
209
|
+
"D",
|
|
210
|
+
"E",
|
|
211
|
+
"F",
|
|
212
|
+
"G",
|
|
213
|
+
"H",
|
|
214
|
+
"I",
|
|
215
|
+
"J",
|
|
216
|
+
"K",
|
|
217
|
+
"L",
|
|
218
|
+
"M",
|
|
219
|
+
"N",
|
|
220
|
+
"O",
|
|
221
|
+
"P",
|
|
222
|
+
"Q",
|
|
223
|
+
"R",
|
|
224
|
+
"S",
|
|
225
|
+
"T",
|
|
226
|
+
"U",
|
|
227
|
+
"V",
|
|
228
|
+
"W",
|
|
229
|
+
"X",
|
|
230
|
+
"Y",
|
|
231
|
+
"Z",
|
|
232
|
+
"a",
|
|
233
|
+
"b",
|
|
234
|
+
"c",
|
|
235
|
+
"d",
|
|
236
|
+
"e",
|
|
237
|
+
"f",
|
|
238
|
+
"g",
|
|
239
|
+
"h",
|
|
240
|
+
"i",
|
|
241
|
+
"j",
|
|
242
|
+
"k",
|
|
243
|
+
"l",
|
|
244
|
+
"m",
|
|
245
|
+
"n",
|
|
246
|
+
"o",
|
|
247
|
+
"p",
|
|
248
|
+
"q",
|
|
249
|
+
"r",
|
|
250
|
+
"s",
|
|
251
|
+
"t",
|
|
252
|
+
"u",
|
|
253
|
+
"v",
|
|
254
|
+
"w",
|
|
255
|
+
"x",
|
|
256
|
+
"y",
|
|
257
|
+
"z",
|
|
258
|
+
"0",
|
|
259
|
+
"1",
|
|
260
|
+
"2",
|
|
261
|
+
"3",
|
|
262
|
+
"4",
|
|
263
|
+
"5",
|
|
264
|
+
"6",
|
|
265
|
+
"7",
|
|
266
|
+
"8",
|
|
267
|
+
"9",
|
|
268
|
+
"+",
|
|
269
|
+
"/",
|
|
270
|
+
];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBackendErrorMessage = void 0;
|
|
4
|
+
const buffer_writer_1 = require("./buffer-writer");
|
|
5
|
+
const message_codes_1 = require("./message-codes");
|
|
6
|
+
function createBackendErrorMessage(error) {
|
|
7
|
+
const writer = new buffer_writer_1.BufferWriter();
|
|
8
|
+
writer.addString('S');
|
|
9
|
+
writer.addCString(error.severity);
|
|
10
|
+
writer.addString('V');
|
|
11
|
+
writer.addCString(error.severity);
|
|
12
|
+
writer.addString('C');
|
|
13
|
+
writer.addCString(error.code);
|
|
14
|
+
writer.addString('M');
|
|
15
|
+
writer.addCString(error.message);
|
|
16
|
+
if (error.detail !== undefined) {
|
|
17
|
+
writer.addString('D');
|
|
18
|
+
writer.addCString(error.detail);
|
|
19
|
+
}
|
|
20
|
+
if (error.hint !== undefined) {
|
|
21
|
+
writer.addString('H');
|
|
22
|
+
writer.addCString(error.hint);
|
|
23
|
+
}
|
|
24
|
+
if (error.position !== undefined) {
|
|
25
|
+
writer.addString('P');
|
|
26
|
+
writer.addCString(error.position);
|
|
27
|
+
}
|
|
28
|
+
if (error.internalPosition !== undefined) {
|
|
29
|
+
writer.addString('p');
|
|
30
|
+
writer.addCString(error.internalPosition);
|
|
31
|
+
}
|
|
32
|
+
if (error.internalQuery !== undefined) {
|
|
33
|
+
writer.addString('q');
|
|
34
|
+
writer.addCString(error.internalQuery);
|
|
35
|
+
}
|
|
36
|
+
if (error.where !== undefined) {
|
|
37
|
+
writer.addString('W');
|
|
38
|
+
writer.addCString(error.where);
|
|
39
|
+
}
|
|
40
|
+
if (error.schema !== undefined) {
|
|
41
|
+
writer.addString('s');
|
|
42
|
+
writer.addCString(error.schema);
|
|
43
|
+
}
|
|
44
|
+
if (error.table !== undefined) {
|
|
45
|
+
writer.addString('t');
|
|
46
|
+
writer.addCString(error.table);
|
|
47
|
+
}
|
|
48
|
+
if (error.column !== undefined) {
|
|
49
|
+
writer.addString('c');
|
|
50
|
+
writer.addCString(error.column);
|
|
51
|
+
}
|
|
52
|
+
if (error.dataType !== undefined) {
|
|
53
|
+
writer.addString('d');
|
|
54
|
+
writer.addCString(error.dataType);
|
|
55
|
+
}
|
|
56
|
+
if (error.constraint !== undefined) {
|
|
57
|
+
writer.addString('n');
|
|
58
|
+
writer.addCString(error.constraint);
|
|
59
|
+
}
|
|
60
|
+
if (error.file !== undefined) {
|
|
61
|
+
writer.addString('F');
|
|
62
|
+
writer.addCString(error.file);
|
|
63
|
+
}
|
|
64
|
+
if (error.line !== undefined) {
|
|
65
|
+
writer.addString('L');
|
|
66
|
+
writer.addCString(error.line);
|
|
67
|
+
}
|
|
68
|
+
if (error.routine !== undefined) {
|
|
69
|
+
writer.addString('R');
|
|
70
|
+
writer.addCString(error.routine);
|
|
71
|
+
}
|
|
72
|
+
writer.addCString('');
|
|
73
|
+
return writer.flush(message_codes_1.BackendMessageCode.ErrorMessage);
|
|
74
|
+
}
|
|
75
|
+
exports.createBackendErrorMessage = createBackendErrorMessage;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferReader = void 0;
|
|
4
|
+
class BufferReader {
|
|
5
|
+
constructor(offset = 0) {
|
|
6
|
+
this.offset = offset;
|
|
7
|
+
this.buffer = new Uint8Array();
|
|
8
|
+
this.decoder = new TextDecoder();
|
|
9
|
+
}
|
|
10
|
+
setBuffer(buffer, offset = 0) {
|
|
11
|
+
this.buffer = buffer;
|
|
12
|
+
this.offset = offset;
|
|
13
|
+
}
|
|
14
|
+
int16() {
|
|
15
|
+
const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
16
|
+
const result = dataView.getInt16(this.offset);
|
|
17
|
+
this.offset += 2;
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
byte() {
|
|
21
|
+
const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
22
|
+
const result = dataView.getUint8(this.offset);
|
|
23
|
+
this.offset++;
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
int32() {
|
|
27
|
+
const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
28
|
+
const result = dataView.getInt32(this.offset);
|
|
29
|
+
this.offset += 4;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
string(length) {
|
|
33
|
+
const dataView = new DataView(this.buffer.buffer, this.offset, length);
|
|
34
|
+
this.offset += length;
|
|
35
|
+
return this.decoder.decode(dataView);
|
|
36
|
+
}
|
|
37
|
+
cstring() {
|
|
38
|
+
const start = this.offset;
|
|
39
|
+
let end = start;
|
|
40
|
+
while ((this.buffer[end++] ?? 0) !== 0) { }
|
|
41
|
+
if (this.buffer[end - 1] === undefined) {
|
|
42
|
+
throw new Error('Reached end of buffer before null character found for PG String');
|
|
43
|
+
}
|
|
44
|
+
const dataView = new DataView(this.buffer.buffer, start, end - start - 1);
|
|
45
|
+
this.offset = end;
|
|
46
|
+
return this.decoder.decode(dataView);
|
|
47
|
+
}
|
|
48
|
+
bytes(length) {
|
|
49
|
+
const result = this.buffer.slice(this.offset, this.offset + length);
|
|
50
|
+
this.offset += length;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.BufferReader = BufferReader;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferWriter = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class BufferWriter {
|
|
6
|
+
constructor(size = 256) {
|
|
7
|
+
this.size = size;
|
|
8
|
+
this.offset = 5;
|
|
9
|
+
this.headerPosition = 0;
|
|
10
|
+
this.encoder = new TextEncoder();
|
|
11
|
+
this.buffer = new Uint8Array(size);
|
|
12
|
+
}
|
|
13
|
+
ensure(size) {
|
|
14
|
+
const remaining = this.buffer.length - this.offset;
|
|
15
|
+
if (remaining < size) {
|
|
16
|
+
const oldBuffer = this.buffer;
|
|
17
|
+
const newSize = oldBuffer.length + (oldBuffer.length >> 1) + size;
|
|
18
|
+
this.buffer = new Uint8Array(newSize);
|
|
19
|
+
(0, utils_1.copy)(oldBuffer, this.buffer);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
addInt32(num) {
|
|
23
|
+
this.ensure(4);
|
|
24
|
+
this.buffer[this.offset++] = (num >>> 24) & 0xff;
|
|
25
|
+
this.buffer[this.offset++] = (num >>> 16) & 0xff;
|
|
26
|
+
this.buffer[this.offset++] = (num >>> 8) & 0xff;
|
|
27
|
+
this.buffer[this.offset++] = (num >>> 0) & 0xff;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
addInt16(num) {
|
|
31
|
+
this.ensure(2);
|
|
32
|
+
this.buffer[this.offset++] = (num >>> 8) & 0xff;
|
|
33
|
+
this.buffer[this.offset++] = (num >>> 0) & 0xff;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
addCString(string) {
|
|
37
|
+
if (!string) {
|
|
38
|
+
this.ensure(1);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const stringBuffer = this.encoder.encode(string);
|
|
42
|
+
this.ensure(stringBuffer.byteLength + 1);
|
|
43
|
+
this.buffer.set(stringBuffer, this.offset);
|
|
44
|
+
this.offset += stringBuffer.byteLength;
|
|
45
|
+
}
|
|
46
|
+
this.buffer[this.offset++] = 0;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
addString(string = '') {
|
|
50
|
+
const stringBuffer = this.encoder.encode(string);
|
|
51
|
+
this.ensure(stringBuffer.byteLength);
|
|
52
|
+
this.buffer.set(stringBuffer, this.offset);
|
|
53
|
+
this.offset += stringBuffer.byteLength;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
add(otherBuffer) {
|
|
57
|
+
this.ensure(otherBuffer.byteLength);
|
|
58
|
+
(0, utils_1.copy)(otherBuffer, this.buffer, this.offset);
|
|
59
|
+
this.offset += otherBuffer.length;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
join(code) {
|
|
63
|
+
if (code) {
|
|
64
|
+
this.buffer[this.headerPosition] = code;
|
|
65
|
+
const length = this.offset - (this.headerPosition + 1);
|
|
66
|
+
const dataView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
67
|
+
dataView.setInt32(this.headerPosition + 1, length);
|
|
68
|
+
}
|
|
69
|
+
return this.buffer.slice(code ? 0 : 5, this.offset);
|
|
70
|
+
}
|
|
71
|
+
flush(code) {
|
|
72
|
+
const result = this.join(code);
|
|
73
|
+
this.offset = 5;
|
|
74
|
+
this.headerPosition = 0;
|
|
75
|
+
this.buffer = new Uint8Array(this.size);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BufferWriter = BufferWriter;
|