This commit is contained in:
girinb
2025-05-29 15:41:51 +09:00
parent a1bd4f87a1
commit 485098cd1a
5611 changed files with 881685 additions and 0 deletions

View File

@@ -0,0 +1 @@
export {};

170
node_modules/firebase-functions/lib/runtime/loader.js generated vendored Normal file
View File

@@ -0,0 +1,170 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadStack = exports.mergeRequiredAPIs = exports.extractStack = void 0;
// The MIT License (MIT)
//
// Copyright (c) 2021 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
const path = require("path");
const url = require("url");
const params = require("../params");
/**
* Dynamically load import function to prevent TypeScript from
* transpiling into a require.
*
* See https://github.com/microsoft/TypeScript/issues/43329.
*
*/
// eslint-disable-next-line @typescript-eslint/no-implied-eval
const dynamicImport = new Function("modulePath", "return import(modulePath)");
async function loadModule(functionsDir) {
const absolutePath = path.resolve(functionsDir);
try {
return require(path.resolve(absolutePath));
}
catch (e) {
if (e.code === "ERR_REQUIRE_ESM" || e.code === "ERR_REQUIRE_ASYNC_MODULE") {
// This is an ESM package, or one containing top-level awaits!
const modulePath = require.resolve(absolutePath);
// Resolve module path to file:// URL. Required for windows support.
const moduleURL = url.pathToFileURL(modulePath).href;
return await dynamicImport(moduleURL);
}
throw e;
}
}
/* @internal */
function extractStack(module, endpoints, requiredAPIs, extensions, prefix = "") {
for (const [name, valAsUnknown] of Object.entries(module)) {
// We're introspecting untrusted code here. Any is appropraite
const val = valAsUnknown;
if (typeof val === "function" && val.__endpoint && typeof val.__endpoint === "object") {
const funcName = prefix + name;
endpoints[funcName] = {
...val.__endpoint,
entryPoint: funcName.replace(/-/g, "."),
};
if (val.__requiredAPIs && Array.isArray(val.__requiredAPIs)) {
requiredAPIs.push(...val.__requiredAPIs);
}
}
else if (isFirebaseRefExtension(val)) {
extensions[val.instanceId] = {
params: convertExtensionParams(val.params),
ref: val.FIREBASE_EXTENSION_REFERENCE,
events: val.events || [],
};
}
else if (isFirebaseLocalExtension(val)) {
extensions[val.instanceId] = {
params: convertExtensionParams(val.params),
localPath: val.FIREBASE_EXTENSION_LOCAL_PATH,
events: val.events || [],
};
}
else if (isObject(val)) {
extractStack(val, endpoints, requiredAPIs, extensions, prefix + name + "-");
}
}
}
exports.extractStack = extractStack;
function toTitleCase(txt) {
return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
}
function snakeToCamelCase(txt) {
let ret = txt.toLowerCase();
ret = ret.replace(/_/g, " ");
ret = ret.replace(/\w\S*/g, toTitleCase);
ret = ret.charAt(0).toLowerCase() + ret.substring(1);
return ret;
}
function convertExtensionParams(params) {
const systemPrefixes = {
FUNCTION: "firebaseextensions.v1beta.function",
V2FUNCTION: "firebaseextensions.v1beta.v2function",
};
const converted = {};
for (const [rawKey, paramVal] of Object.entries(params)) {
let key = rawKey;
if (rawKey.startsWith("_") && rawKey !== "_EVENT_ARC_REGION") {
const prefix = rawKey.substring(1).split("_")[0];
const suffix = rawKey.substring(2 + prefix.length); // 2 for underscores
key = `${systemPrefixes[prefix]}/${snakeToCamelCase(suffix)}`;
}
if (Array.isArray(paramVal)) {
converted[key] = paramVal.join(",");
}
else {
converted[key] = paramVal;
}
}
return converted;
}
function isObject(value) {
return typeof value === "object" && value !== null;
}
const isFirebaseLocalExtension = (val) => {
return (isObject(val) &&
typeof val.FIREBASE_EXTENSION_LOCAL_PATH === "string" &&
typeof val.instanceId === "string" &&
isObject(val.params) &&
(!val.events || Array.isArray(val.events)));
};
const isFirebaseRefExtension = (val) => {
return (isObject(val) &&
typeof val.FIREBASE_EXTENSION_REFERENCE === "string" &&
typeof val.instanceId === "string" &&
isObject(val.params) &&
(!val.events || Array.isArray(val.events)));
};
/* @internal */
function mergeRequiredAPIs(requiredAPIs) {
const apiToReasons = {};
for (const { api, reason } of requiredAPIs) {
const reasons = apiToReasons[api] || new Set();
reasons.add(reason);
apiToReasons[api] = reasons;
}
const merged = [];
for (const [api, reasons] of Object.entries(apiToReasons)) {
merged.push({ api, reason: Array.from(reasons).join(" ") });
}
return merged;
}
exports.mergeRequiredAPIs = mergeRequiredAPIs;
/* @internal */
async function loadStack(functionsDir) {
const endpoints = {};
const requiredAPIs = [];
const extensions = {};
const mod = await loadModule(functionsDir);
extractStack(mod, endpoints, requiredAPIs, extensions);
const stack = {
endpoints,
specVersion: "v1alpha1",
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
extensions,
};
if (params.declaredParams.length > 0) {
stack.params = params.declaredParams.map((p) => p.toSpec());
}
return stack;
}
exports.loadStack = loadStack;

View File

@@ -0,0 +1,116 @@
import { ResetValue } from "../common/options";
import { Expression } from "../params";
import { WireParamSpec, SecretParam } from "../params/types";
/**
* A definition of an extension as appears in the Manifest.
* Exactly one of ref or localPath must be present.
*/
export interface ManifestExtension {
params: Record<string, string | SecretParam>;
ref?: string;
localPath?: string;
events: string[];
}
/**
* A definition of a function as appears in the Manifest.
*
* @alpha
*/
export interface ManifestEndpoint {
entryPoint?: string;
region?: string[];
omit?: boolean | Expression<boolean>;
platform?: string;
availableMemoryMb?: number | Expression<number> | ResetValue;
maxInstances?: number | Expression<number> | ResetValue;
minInstances?: number | Expression<number> | ResetValue;
concurrency?: number | Expression<number> | ResetValue;
timeoutSeconds?: number | Expression<number> | ResetValue;
vpc?: {
connector: string | Expression<string>;
egressSettings?: string | Expression<string> | ResetValue;
} | ResetValue;
serviceAccountEmail?: string | Expression<string> | ResetValue;
cpu?: number | "gcf_gen1";
labels?: Record<string, string>;
ingressSettings?: string | Expression<string> | ResetValue;
environmentVariables?: Record<string, string>;
secretEnvironmentVariables?: Array<{
key: string;
secret?: string;
}>;
httpsTrigger?: {
invoker?: string[];
};
callableTrigger?: {
genkitAction?: string;
};
eventTrigger?: {
eventFilters: Record<string, string | Expression<string>>;
eventFilterPathPatterns?: Record<string, string | Expression<string>>;
channel?: string;
eventType: string;
retry: boolean | Expression<boolean> | ResetValue;
region?: string;
serviceAccountEmail?: string | ResetValue;
};
taskQueueTrigger?: {
retryConfig?: {
maxAttempts?: number | Expression<number> | ResetValue;
maxRetrySeconds?: number | Expression<number> | ResetValue;
maxBackoffSeconds?: number | Expression<number> | ResetValue;
maxDoublings?: number | Expression<number> | ResetValue;
minBackoffSeconds?: number | Expression<number> | ResetValue;
};
rateLimits?: {
maxConcurrentDispatches?: number | Expression<number> | ResetValue;
maxDispatchesPerSecond?: number | Expression<number> | ResetValue;
};
};
scheduleTrigger?: {
schedule: string | Expression<string>;
timeZone?: string | Expression<string> | ResetValue;
retryConfig?: {
retryCount?: number | Expression<number> | ResetValue;
maxRetrySeconds?: string | Expression<string> | ResetValue;
minBackoffSeconds?: string | Expression<string> | ResetValue;
maxBackoffSeconds?: string | Expression<string> | ResetValue;
maxDoublings?: number | Expression<number> | ResetValue;
maxRetryDuration?: string | Expression<string> | ResetValue;
minBackoffDuration?: string | Expression<string> | ResetValue;
maxBackoffDuration?: string | Expression<string> | ResetValue;
};
};
blockingTrigger?: {
eventType: string;
options?: Record<string, unknown>;
};
}
/**
* Description of API required for this stack.
* @alpha
*/
export interface ManifestRequiredAPI {
api: string;
reason: string;
}
/**
* A definition of a function/extension deployment as appears in the Manifest.
*
* @alpha
*/
export interface ManifestStack {
specVersion: "v1alpha1";
params?: WireParamSpec<any>[];
requiredAPIs: ManifestRequiredAPI[];
endpoints: Record<string, ManifestEndpoint>;
extensions?: Record<string, ManifestExtension>;
}
/**
* Returns the JSON representation of a ManifestStack, which has CEL
* expressions in its options as object types, with its expressions
* transformed into the actual CEL strings.
*
* @alpha
*/
export declare function stackToWire(stack: ManifestStack): Record<string, unknown>;

159
node_modules/firebase-functions/lib/runtime/manifest.js generated vendored Normal file
View File

@@ -0,0 +1,159 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2021 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.initV2ScheduleTrigger = exports.initV1ScheduleTrigger = exports.initTaskQueueTrigger = exports.initV2Endpoint = exports.initV1Endpoint = exports.stackToWire = void 0;
const options_1 = require("../common/options");
const params_1 = require("../params");
/**
* Returns the JSON representation of a ManifestStack, which has CEL
* expressions in its options as object types, with its expressions
* transformed into the actual CEL strings.
*
* @alpha
*/
function stackToWire(stack) {
const wireStack = stack;
const traverse = function traverse(obj) {
for (const [key, val] of Object.entries(obj)) {
if (val instanceof params_1.Expression) {
obj[key] = val.toCEL();
}
else if (val instanceof options_1.ResetValue) {
obj[key] = val.toJSON();
}
else if (typeof val === "object" && val !== null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
traverse(val);
}
}
};
traverse(wireStack.endpoints);
return wireStack;
}
exports.stackToWire = stackToWire;
const RESETTABLE_OPTIONS = {
availableMemoryMb: null,
timeoutSeconds: null,
minInstances: null,
maxInstances: null,
ingressSettings: null,
concurrency: null,
serviceAccountEmail: null,
vpc: null,
};
function initEndpoint(resetOptions, ...opts) {
const endpoint = {};
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
for (const key of Object.keys(resetOptions)) {
endpoint[key] = options_1.RESET_VALUE;
}
}
return endpoint;
}
/**
* @internal
*/
function initV1Endpoint(...opts) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { concurrency, ...resetOpts } = RESETTABLE_OPTIONS;
return initEndpoint({ ...resetOpts }, ...opts);
}
exports.initV1Endpoint = initV1Endpoint;
/**
* @internal
*/
function initV2Endpoint(...opts) {
return initEndpoint(RESETTABLE_OPTIONS, ...opts);
}
exports.initV2Endpoint = initV2Endpoint;
const RESETTABLE_RETRY_CONFIG_OPTIONS = {
maxAttempts: null,
maxDoublings: null,
maxBackoffSeconds: null,
maxRetrySeconds: null,
minBackoffSeconds: null,
};
const RESETTABLE_RATE_LIMITS_OPTIONS = {
maxConcurrentDispatches: null,
maxDispatchesPerSecond: null,
};
/**
* @internal
*/
function initTaskQueueTrigger(...opts) {
const taskQueueTrigger = {
retryConfig: {},
rateLimits: {},
};
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
for (const key of Object.keys(RESETTABLE_RETRY_CONFIG_OPTIONS)) {
taskQueueTrigger.retryConfig[key] = options_1.RESET_VALUE;
}
for (const key of Object.keys(RESETTABLE_RATE_LIMITS_OPTIONS)) {
taskQueueTrigger.rateLimits[key] = options_1.RESET_VALUE;
}
}
return taskQueueTrigger;
}
exports.initTaskQueueTrigger = initTaskQueueTrigger;
const RESETTABLE_V1_SCHEDULE_OPTIONS = {
retryCount: null,
maxDoublings: null,
maxRetryDuration: null,
maxBackoffDuration: null,
minBackoffDuration: null,
};
const RESETTABLE_V2_SCHEDULE_OPTIONS = {
retryCount: null,
maxDoublings: null,
maxRetrySeconds: null,
minBackoffSeconds: null,
maxBackoffSeconds: null,
};
function initScheduleTrigger(resetOptions, schedule, ...opts) {
let scheduleTrigger = {
schedule,
retryConfig: {},
};
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
for (const key of Object.keys(resetOptions)) {
scheduleTrigger.retryConfig[key] = options_1.RESET_VALUE;
}
scheduleTrigger = { ...scheduleTrigger, timeZone: options_1.RESET_VALUE };
}
return scheduleTrigger;
}
/**
* @internal
*/
function initV1ScheduleTrigger(schedule, ...opts) {
return initScheduleTrigger(RESETTABLE_V1_SCHEDULE_OPTIONS, schedule, ...opts);
}
exports.initV1ScheduleTrigger = initV1ScheduleTrigger;
/**
* @internal
*/
function initV2ScheduleTrigger(schedule, ...opts) {
return initScheduleTrigger(RESETTABLE_V2_SCHEDULE_OPTIONS, schedule, ...opts);
}
exports.initV2ScheduleTrigger = initV2ScheduleTrigger;