firebase-functions 7.0.5 → 7.1.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/esm/v2/compat.mjs +77 -0
- package/lib/esm/v2/index.mjs +2 -2
- package/lib/esm/v2/providers/dataconnect/graphql.mjs +11 -2
- package/lib/esm/v2/providers/firestore.mjs +1 -1
- package/lib/esm/v2/providers/pubsub.mjs +3 -67
- package/lib/v2/compat.d.ts +15 -0
- package/lib/v2/compat.js +77 -0
- package/lib/v2/index.d.ts +1 -0
- package/lib/v2/index.js +2 -2
- package/lib/v2/providers/dataconnect/graphql.d.ts +0 -4
- package/lib/v2/providers/dataconnect/graphql.js +11 -2
- package/lib/v2/providers/firestore.js +1 -1
- package/lib/v2/providers/pubsub.d.ts +4 -21
- package/lib/v2/providers/pubsub.js +3 -67
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Message } from "./providers/pubsub.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/v2/compat.ts
|
|
4
|
+
const V1_COMPAT_PATCHED = Symbol.for("firebase.functions.v2.compat");
|
|
5
|
+
/**
|
|
6
|
+
* Patches a CloudEvent with V1 compatibility properties (context and message) if it's a supported type (e.g., Pub/Sub).
|
|
7
|
+
* This function ensures idempotency by using a Symbol to mark already patched events.
|
|
8
|
+
* @param event The CloudEvent to potentially patch.
|
|
9
|
+
* @returns The patched CloudEvent with V1 compatibility properties, or the original event if not a supported event type or already patched.
|
|
10
|
+
*/
|
|
11
|
+
function patchV1Compat(event) {
|
|
12
|
+
if (event[V1_COMPAT_PATCHED]) {
|
|
13
|
+
return event;
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(event, V1_COMPAT_PATCHED, {
|
|
16
|
+
value: true,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
writable: false,
|
|
19
|
+
configurable: false
|
|
20
|
+
});
|
|
21
|
+
switch (event.type) {
|
|
22
|
+
case "google.cloud.pubsub.topic.v1.messagePublished": {
|
|
23
|
+
const pubsubEvent = event;
|
|
24
|
+
const pubsubData = pubsubEvent.data;
|
|
25
|
+
if (!pubsubData || !pubsubData.message) {
|
|
26
|
+
throw new Error("Malformed Pub/Sub event: missing 'message' property.");
|
|
27
|
+
}
|
|
28
|
+
if (!(pubsubData.message instanceof Message)) {
|
|
29
|
+
pubsubData.message = new Message(pubsubData.message);
|
|
30
|
+
}
|
|
31
|
+
const v2Message = pubsubData.message;
|
|
32
|
+
Object.defineProperty(pubsubEvent, "context", {
|
|
33
|
+
get: () => {
|
|
34
|
+
const service = "pubsub.googleapis.com";
|
|
35
|
+
const sourcePrefix = `//${service}/`;
|
|
36
|
+
return {
|
|
37
|
+
eventId: v2Message.messageId,
|
|
38
|
+
timestamp: v2Message.publishTime,
|
|
39
|
+
eventType: "google.pubsub.topic.publish",
|
|
40
|
+
resource: {
|
|
41
|
+
service,
|
|
42
|
+
name: event.source?.startsWith(sourcePrefix) ? event.source.substring(sourcePrefix.length) : event.source || ""
|
|
43
|
+
},
|
|
44
|
+
params: {}
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
configurable: true,
|
|
48
|
+
enumerable: true
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(pubsubEvent, "message", {
|
|
51
|
+
get: () => {
|
|
52
|
+
const baseV1Message = {
|
|
53
|
+
data: v2Message.data,
|
|
54
|
+
messageId: v2Message.messageId,
|
|
55
|
+
publishTime: v2Message.publishTime,
|
|
56
|
+
attributes: v2Message.attributes,
|
|
57
|
+
...v2Message.orderingKey && { orderingKey: v2Message.orderingKey }
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...baseV1Message,
|
|
61
|
+
get json() {
|
|
62
|
+
return v2Message.json;
|
|
63
|
+
},
|
|
64
|
+
toJSON: () => baseV1Message
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
configurable: true,
|
|
68
|
+
enumerable: true
|
|
69
|
+
});
|
|
70
|
+
return pubsubEvent;
|
|
71
|
+
}
|
|
72
|
+
default: return event;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { patchV1Compat };
|
package/lib/esm/v2/index.mjs
CHANGED
|
@@ -5,14 +5,14 @@ import { setApp } from "../common/app.mjs";
|
|
|
5
5
|
import { Change } from "../common/change.mjs";
|
|
6
6
|
import { onInit } from "../common/onInit.mjs";
|
|
7
7
|
import { config } from "../v1/config.mjs";
|
|
8
|
-
import "./core.mjs";
|
|
9
8
|
import { setGlobalOptions } from "./options.mjs";
|
|
9
|
+
import { pubsub_exports } from "./providers/pubsub.mjs";
|
|
10
|
+
import "./core.mjs";
|
|
10
11
|
import { alerts_exports } from "./providers/alerts/index.mjs";
|
|
11
12
|
import { database_exports } from "./providers/database.mjs";
|
|
12
13
|
import { eventarc_exports } from "./providers/eventarc.mjs";
|
|
13
14
|
import { https_exports } from "./providers/https.mjs";
|
|
14
15
|
import { identity_exports } from "./providers/identity.mjs";
|
|
15
|
-
import { pubsub_exports } from "./providers/pubsub.mjs";
|
|
16
16
|
import { scheduler_exports } from "./providers/scheduler.mjs";
|
|
17
17
|
import { storage_exports } from "./providers/storage.mjs";
|
|
18
18
|
import { tasks_exports } from "./providers/tasks.mjs";
|
|
@@ -11,6 +11,15 @@ import { expressMiddleware } from "@as-integrations/express4";
|
|
|
11
11
|
|
|
12
12
|
//#region src/v2/providers/dataconnect/graphql.ts
|
|
13
13
|
const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
|
|
14
|
+
const PRELUDE_GQL = [
|
|
15
|
+
"scalar UUID",
|
|
16
|
+
"scalar Int64",
|
|
17
|
+
"scalar Any",
|
|
18
|
+
"scalar Void",
|
|
19
|
+
"scalar True",
|
|
20
|
+
"scalar Date",
|
|
21
|
+
"scalar Timestamp"
|
|
22
|
+
].join("\n");
|
|
14
23
|
/** @hidden */
|
|
15
24
|
async function initGraphqlServer(opts) {
|
|
16
25
|
if (!opts.schema && !opts.schemaFilePath || opts.schema && opts.schemaFilePath) {
|
|
@@ -19,6 +28,7 @@ async function initGraphqlServer(opts) {
|
|
|
19
28
|
if (opts.schemaFilePath) {
|
|
20
29
|
opts.schema = fs.readFileSync(opts.schemaFilePath, "utf-8");
|
|
21
30
|
}
|
|
31
|
+
const schemaWithPrelude = PRELUDE_GQL + "\n" + opts.schema;
|
|
22
32
|
if (!opts.resolvers.query && !opts.resolvers.mutation) {
|
|
23
33
|
throw new Error("At least one query or mutation resolver must be provided.");
|
|
24
34
|
}
|
|
@@ -33,7 +43,7 @@ async function initGraphqlServer(opts) {
|
|
|
33
43
|
const serverPromise = (async () => {
|
|
34
44
|
const app = express();
|
|
35
45
|
const server = new ApolloServer({
|
|
36
|
-
typeDefs:
|
|
46
|
+
typeDefs: schemaWithPrelude,
|
|
37
47
|
resolvers: apolloResolvers
|
|
38
48
|
});
|
|
39
49
|
await server.start();
|
|
@@ -50,7 +60,6 @@ async function initGraphqlServer(opts) {
|
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
/**
|
|
53
|
-
* @hidden
|
|
54
63
|
* Handles HTTPS GraphQL requests.
|
|
55
64
|
* @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
|
|
56
65
|
* @returns {HttpsFunction} A function you can export and deploy.
|
|
@@ -6,8 +6,8 @@ import { withInit } from "../../common/onInit.mjs";
|
|
|
6
6
|
import { normalizePath } from "../../common/utilities/path.mjs";
|
|
7
7
|
import { createBeforeSnapshotFromJson, createBeforeSnapshotFromProtobuf, createSnapshotFromJson, createSnapshotFromProtobuf } from "../../common/providers/firestore.mjs";
|
|
8
8
|
import { wrapTraceContext } from "../trace.mjs";
|
|
9
|
-
import "../core.mjs";
|
|
10
9
|
import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
|
|
10
|
+
import "../core.mjs";
|
|
11
11
|
import { PathPattern } from "../../common/utilities/path-pattern.mjs";
|
|
12
12
|
|
|
13
13
|
//#region src/v2/providers/firestore.ts
|
|
@@ -4,14 +4,13 @@ import { copyIfPresent } from "../../common/encoding.mjs";
|
|
|
4
4
|
import { withInit } from "../../common/onInit.mjs";
|
|
5
5
|
import { wrapTraceContext } from "../trace.mjs";
|
|
6
6
|
import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
|
|
7
|
+
import { patchV1Compat } from "../compat.mjs";
|
|
7
8
|
|
|
8
9
|
//#region src/v2/providers/pubsub.ts
|
|
9
10
|
var pubsub_exports = /* @__PURE__ */ __export({
|
|
10
11
|
Message: () => Message,
|
|
11
12
|
onMessagePublished: () => onMessagePublished
|
|
12
13
|
});
|
|
13
|
-
const V1_CONTEXT = Symbol("v1Context");
|
|
14
|
-
const V1_MESSAGE = Symbol("v1Message");
|
|
15
14
|
/**
|
|
16
15
|
* Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
|
|
17
16
|
* You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
|
|
@@ -34,7 +33,6 @@ const V1_MESSAGE = Symbol("v1Message");
|
|
|
34
33
|
*/
|
|
35
34
|
/**
|
|
36
35
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
37
|
-
*
|
|
38
36
|
* @param data - Payload of a Pub/Sub message.
|
|
39
37
|
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
40
38
|
*/
|
|
@@ -66,7 +64,6 @@ var Message = class {
|
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* Returns a JSON-serializable representation of this object.
|
|
69
|
-
*
|
|
70
67
|
* @returns A JSON-serializable representation of this object.
|
|
71
68
|
*/
|
|
72
69
|
toJSON() {
|
|
@@ -102,69 +99,8 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
102
99
|
delete opts.topic;
|
|
103
100
|
}
|
|
104
101
|
const func = (raw) => {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
messagePublishedData.message = new Message(messagePublishedData.message);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the v1-compatible EventContext object.
|
|
111
|
-
* This is a compatibility layer to ease migration from v1 to v2.
|
|
112
|
-
* @returns A v1 EventContext-like object.
|
|
113
|
-
*/
|
|
114
|
-
Object.defineProperty(raw, "context", { get: function() {
|
|
115
|
-
if (this[V1_CONTEXT]) {
|
|
116
|
-
return this[V1_CONTEXT];
|
|
117
|
-
}
|
|
118
|
-
const data = this.data;
|
|
119
|
-
if (!data?.message) {
|
|
120
|
-
throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
|
|
121
|
-
}
|
|
122
|
-
const v1Context = {
|
|
123
|
-
eventId: data.message.messageId,
|
|
124
|
-
timestamp: data.message.publishTime,
|
|
125
|
-
eventType: "google.pubsub.topic.publish",
|
|
126
|
-
resource: {
|
|
127
|
-
service: "pubsub.googleapis.com",
|
|
128
|
-
name: this.source.replace("//pubsub.googleapis.com/", "")
|
|
129
|
-
},
|
|
130
|
-
params: {}
|
|
131
|
-
};
|
|
132
|
-
this[V1_CONTEXT] = v1Context;
|
|
133
|
-
return this[V1_CONTEXT];
|
|
134
|
-
} });
|
|
135
|
-
/**
|
|
136
|
-
* Get the v1-compatible Message object.
|
|
137
|
-
* This is a compatibility layer to ease migration from v1 to v2.
|
|
138
|
-
* @returns A plain object mimicking the v1 Message structure.
|
|
139
|
-
*/
|
|
140
|
-
Object.defineProperty(raw, "message", { get: function() {
|
|
141
|
-
if (this[V1_MESSAGE]) {
|
|
142
|
-
return this[V1_MESSAGE];
|
|
143
|
-
}
|
|
144
|
-
const data = this.data;
|
|
145
|
-
if (!data || !data.message) {
|
|
146
|
-
throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
|
|
147
|
-
}
|
|
148
|
-
const v2Message = data.message;
|
|
149
|
-
const baseMessage = {
|
|
150
|
-
data: v2Message.data,
|
|
151
|
-
messageId: v2Message.messageId,
|
|
152
|
-
publishTime: v2Message.publishTime,
|
|
153
|
-
attributes: v2Message.attributes || {}
|
|
154
|
-
};
|
|
155
|
-
if (v2Message.orderingKey) {
|
|
156
|
-
baseMessage.orderingKey = v2Message.orderingKey;
|
|
157
|
-
}
|
|
158
|
-
this[V1_MESSAGE] = {
|
|
159
|
-
...baseMessage,
|
|
160
|
-
get json() {
|
|
161
|
-
return v2Message.json;
|
|
162
|
-
},
|
|
163
|
-
toJSON: () => baseMessage
|
|
164
|
-
};
|
|
165
|
-
return this[V1_MESSAGE];
|
|
166
|
-
} });
|
|
167
|
-
return wrapTraceContext(withInit(handler))(raw);
|
|
102
|
+
const event = patchV1Compat(raw);
|
|
103
|
+
return wrapTraceContext(withInit(handler))(event);
|
|
168
104
|
};
|
|
169
105
|
func.run = handler;
|
|
170
106
|
Object.defineProperty(func, "__trigger", { get: () => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CloudEvent } from "./core";
|
|
2
|
+
import { MessagePublishedData, V1PubSubMessage } from "./providers/pubsub";
|
|
3
|
+
import { EventContext as V1EventContext } from "../v1";
|
|
4
|
+
export interface V1Context extends Omit<V1EventContext, "resource"> {
|
|
5
|
+
resource: {
|
|
6
|
+
service: string;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export type PubSubCloudEvent<T> = CloudEvent<MessagePublishedData<T>> & {
|
|
11
|
+
context: V1Context;
|
|
12
|
+
message: V1PubSubMessage<T>;
|
|
13
|
+
};
|
|
14
|
+
export declare function patchV1Compat<T>(event: CloudEvent<MessagePublishedData<T>>): PubSubCloudEvent<T>;
|
|
15
|
+
export declare function patchV1Compat<T>(event: CloudEvent<T>): CloudEvent<T>;
|
package/lib/v2/compat.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
2
|
+
|
|
3
|
+
//#region src/v2/compat.ts
|
|
4
|
+
const V1_COMPAT_PATCHED = Symbol.for("firebase.functions.v2.compat");
|
|
5
|
+
/**
|
|
6
|
+
* Patches a CloudEvent with V1 compatibility properties (context and message) if it's a supported type (e.g., Pub/Sub).
|
|
7
|
+
* This function ensures idempotency by using a Symbol to mark already patched events.
|
|
8
|
+
* @param event The CloudEvent to potentially patch.
|
|
9
|
+
* @returns The patched CloudEvent with V1 compatibility properties, or the original event if not a supported event type or already patched.
|
|
10
|
+
*/
|
|
11
|
+
function patchV1Compat(event) {
|
|
12
|
+
if (event[V1_COMPAT_PATCHED]) {
|
|
13
|
+
return event;
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(event, V1_COMPAT_PATCHED, {
|
|
16
|
+
value: true,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
writable: false,
|
|
19
|
+
configurable: false
|
|
20
|
+
});
|
|
21
|
+
switch (event.type) {
|
|
22
|
+
case "google.cloud.pubsub.topic.v1.messagePublished": {
|
|
23
|
+
const pubsubEvent = event;
|
|
24
|
+
const pubsubData = pubsubEvent.data;
|
|
25
|
+
if (!pubsubData || !pubsubData.message) {
|
|
26
|
+
throw new Error("Malformed Pub/Sub event: missing 'message' property.");
|
|
27
|
+
}
|
|
28
|
+
if (!(pubsubData.message instanceof require_v2_providers_pubsub.Message)) {
|
|
29
|
+
pubsubData.message = new require_v2_providers_pubsub.Message(pubsubData.message);
|
|
30
|
+
}
|
|
31
|
+
const v2Message = pubsubData.message;
|
|
32
|
+
Object.defineProperty(pubsubEvent, "context", {
|
|
33
|
+
get: () => {
|
|
34
|
+
const service = "pubsub.googleapis.com";
|
|
35
|
+
const sourcePrefix = `//${service}/`;
|
|
36
|
+
return {
|
|
37
|
+
eventId: v2Message.messageId,
|
|
38
|
+
timestamp: v2Message.publishTime,
|
|
39
|
+
eventType: "google.pubsub.topic.publish",
|
|
40
|
+
resource: {
|
|
41
|
+
service,
|
|
42
|
+
name: event.source?.startsWith(sourcePrefix) ? event.source.substring(sourcePrefix.length) : event.source || ""
|
|
43
|
+
},
|
|
44
|
+
params: {}
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
configurable: true,
|
|
48
|
+
enumerable: true
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(pubsubEvent, "message", {
|
|
51
|
+
get: () => {
|
|
52
|
+
const baseV1Message = {
|
|
53
|
+
data: v2Message.data,
|
|
54
|
+
messageId: v2Message.messageId,
|
|
55
|
+
publishTime: v2Message.publishTime,
|
|
56
|
+
attributes: v2Message.attributes,
|
|
57
|
+
...v2Message.orderingKey && { orderingKey: v2Message.orderingKey }
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...baseV1Message,
|
|
61
|
+
get json() {
|
|
62
|
+
return v2Message.json;
|
|
63
|
+
},
|
|
64
|
+
toJSON: () => baseV1Message
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
configurable: true,
|
|
68
|
+
enumerable: true
|
|
69
|
+
});
|
|
70
|
+
return pubsubEvent;
|
|
71
|
+
}
|
|
72
|
+
default: return event;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.patchV1Compat = patchV1Compat;
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { onInit } from "./core";
|
|
|
26
26
|
export type { CloudFunction, CloudEvent, ParamsOf } from "./core";
|
|
27
27
|
export { Change } from "../common/change";
|
|
28
28
|
export { traceContext } from "../common/trace";
|
|
29
|
+
export type { PubSubCloudEvent } from "./compat";
|
|
29
30
|
import * as params from "../params";
|
|
30
31
|
export { params };
|
|
31
32
|
export { config } from "../v1/config";
|
package/lib/v2/index.js
CHANGED
|
@@ -5,14 +5,14 @@ const require_common_app = require('../common/app.js');
|
|
|
5
5
|
const require_common_change = require('../common/change.js');
|
|
6
6
|
const require_common_onInit = require('../common/onInit.js');
|
|
7
7
|
const require_v1_config = require('../v1/config.js');
|
|
8
|
-
require('./core.js');
|
|
9
8
|
const require_v2_options = require('./options.js');
|
|
9
|
+
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
10
|
+
require('./core.js');
|
|
10
11
|
const require_v2_providers_alerts_index = require('./providers/alerts/index.js');
|
|
11
12
|
const require_v2_providers_database = require('./providers/database.js');
|
|
12
13
|
const require_v2_providers_eventarc = require('./providers/eventarc.js');
|
|
13
14
|
const require_v2_providers_https = require('./providers/https.js');
|
|
14
15
|
const require_v2_providers_identity = require('./providers/identity.js');
|
|
15
|
-
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
16
16
|
const require_v2_providers_scheduler = require('./providers/scheduler.js');
|
|
17
17
|
const require_v2_providers_storage = require('./providers/storage.js');
|
|
18
18
|
const require_v2_providers_tasks = require('./providers/tasks.js');
|
|
@@ -4,14 +4,12 @@ import { HttpsFunction, HttpsOptions } from "../https";
|
|
|
4
4
|
/** @hidden */
|
|
5
5
|
export declare function initGraphqlServer(opts: GraphqlServerOptions): Promise<express.Express>;
|
|
6
6
|
/**
|
|
7
|
-
* @hidden
|
|
8
7
|
* Handles HTTPS GraphQL requests.
|
|
9
8
|
* @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
|
|
10
9
|
* @returns {HttpsFunction} A function you can export and deploy.
|
|
11
10
|
*/
|
|
12
11
|
export declare function onGraphRequest(opts: GraphqlServerOptions): HttpsFunction;
|
|
13
12
|
/**
|
|
14
|
-
* @hidden
|
|
15
13
|
* Options for configuring the GraphQL server.
|
|
16
14
|
*/
|
|
17
15
|
export interface GraphqlServerOptions extends Omit<HttpsOptions, "cors"> {
|
|
@@ -35,7 +33,6 @@ export interface GraphqlServerOptions extends Omit<HttpsOptions, "cors"> {
|
|
|
35
33
|
resolvers: GraphqlResolvers;
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
|
-
* @hidden
|
|
39
36
|
* Per-request context state shared by all resolvers in a particular query.
|
|
40
37
|
*/
|
|
41
38
|
export interface FirebaseContext {
|
|
@@ -45,7 +42,6 @@ export interface FirebaseContext {
|
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
|
-
* @hidden
|
|
49
45
|
* Resolver functions that populate data for individual GraphQL schema fields.
|
|
50
46
|
*/
|
|
51
47
|
export interface GraphqlResolvers {
|
|
@@ -16,6 +16,15 @@ __as_integrations_express4 = require_rolldown_runtime.__toESM(__as_integrations_
|
|
|
16
16
|
|
|
17
17
|
//#region src/v2/providers/dataconnect/graphql.ts
|
|
18
18
|
const FIREBASE_AUTH_HEADER = "X-Firebase-Auth-Token";
|
|
19
|
+
const PRELUDE_GQL = [
|
|
20
|
+
"scalar UUID",
|
|
21
|
+
"scalar Int64",
|
|
22
|
+
"scalar Any",
|
|
23
|
+
"scalar Void",
|
|
24
|
+
"scalar True",
|
|
25
|
+
"scalar Date",
|
|
26
|
+
"scalar Timestamp"
|
|
27
|
+
].join("\n");
|
|
19
28
|
/** @hidden */
|
|
20
29
|
async function initGraphqlServer(opts) {
|
|
21
30
|
if (!opts.schema && !opts.schemaFilePath || opts.schema && opts.schemaFilePath) {
|
|
@@ -24,6 +33,7 @@ async function initGraphqlServer(opts) {
|
|
|
24
33
|
if (opts.schemaFilePath) {
|
|
25
34
|
opts.schema = fs.default.readFileSync(opts.schemaFilePath, "utf-8");
|
|
26
35
|
}
|
|
36
|
+
const schemaWithPrelude = PRELUDE_GQL + "\n" + opts.schema;
|
|
27
37
|
if (!opts.resolvers.query && !opts.resolvers.mutation) {
|
|
28
38
|
throw new Error("At least one query or mutation resolver must be provided.");
|
|
29
39
|
}
|
|
@@ -38,7 +48,7 @@ async function initGraphqlServer(opts) {
|
|
|
38
48
|
const serverPromise = (async () => {
|
|
39
49
|
const app = (0, express.default)();
|
|
40
50
|
const server = new __apollo_server.ApolloServer({
|
|
41
|
-
typeDefs:
|
|
51
|
+
typeDefs: schemaWithPrelude,
|
|
42
52
|
resolvers: apolloResolvers
|
|
43
53
|
});
|
|
44
54
|
await server.start();
|
|
@@ -55,7 +65,6 @@ async function initGraphqlServer(opts) {
|
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
|
-
* @hidden
|
|
59
68
|
* Handles HTTPS GraphQL requests.
|
|
60
69
|
* @param {GraphqlServerOptions} opts - Options for configuring the GraphQL server.
|
|
61
70
|
* @returns {HttpsFunction} A function you can export and deploy.
|
|
@@ -6,8 +6,8 @@ const require_common_onInit = require('../../common/onInit.js');
|
|
|
6
6
|
const require_common_utilities_path = require('../../common/utilities/path.js');
|
|
7
7
|
const require_common_providers_firestore = require('../../common/providers/firestore.js');
|
|
8
8
|
const require_v2_trace = require('../trace.js');
|
|
9
|
-
require('../core.js');
|
|
10
9
|
const require_v2_options = require('../options.js');
|
|
10
|
+
require('../core.js');
|
|
11
11
|
const require_common_utilities_path_pattern = require('../../common/utilities/path-pattern.js');
|
|
12
12
|
|
|
13
13
|
//#region src/v2/providers/firestore.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ResetValue } from "../../common/options";
|
|
2
|
-
import {
|
|
3
|
-
import type { EventContext } from "../../v1/index";
|
|
2
|
+
import { CloudFunction } from "../core";
|
|
4
3
|
import { Expression } from "../../params";
|
|
5
4
|
import * as options from "../options";
|
|
6
5
|
import { SupportedSecretParam } from "../../params/types";
|
|
6
|
+
import { PubSubCloudEvent } from "../compat";
|
|
7
7
|
/**
|
|
8
8
|
* Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
|
|
9
9
|
* You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
|
|
@@ -26,7 +26,6 @@ import { SupportedSecretParam } from "../../params/types";
|
|
|
26
26
|
*/
|
|
27
27
|
/**
|
|
28
28
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
29
|
-
*
|
|
30
29
|
* @param data - Payload of a Pub/Sub message.
|
|
31
30
|
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
32
31
|
*/
|
|
@@ -66,7 +65,6 @@ export declare class Message<T> {
|
|
|
66
65
|
get json(): T;
|
|
67
66
|
/**
|
|
68
67
|
* Returns a JSON-serializable representation of this object.
|
|
69
|
-
*
|
|
70
68
|
* @returns A JSON-serializable representation of this object.
|
|
71
69
|
*/
|
|
72
70
|
toJSON(): any;
|
|
@@ -97,17 +95,6 @@ export interface V1PubSubMessage<T = any> {
|
|
|
97
95
|
readonly json: T;
|
|
98
96
|
toJSON(): any;
|
|
99
97
|
}
|
|
100
|
-
export interface MessagePublishedEvent<T = any> extends CloudEvent<MessagePublishedData<T>> {
|
|
101
|
-
/**
|
|
102
|
-
* v1-compatible EventContext.
|
|
103
|
-
*/
|
|
104
|
-
readonly context: EventContext;
|
|
105
|
-
/**
|
|
106
|
-
* v1-compatible Pub/Sub Message.
|
|
107
|
-
* Note: This is a plain object mimicking the v1 Message structure, not an instance of the v1 Message class.
|
|
108
|
-
*/
|
|
109
|
-
readonly message: V1PubSubMessage<T>;
|
|
110
|
-
}
|
|
111
98
|
/** PubSubOptions extend EventHandlerOptions but must include a topic. */
|
|
112
99
|
export interface PubSubOptions extends options.EventHandlerOptions {
|
|
113
100
|
/** The Pub/Sub topic to watch for message events */
|
|
@@ -127,7 +114,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
127
114
|
/**
|
|
128
115
|
* Timeout for the function in seconds, possible values are 0 to 540.
|
|
129
116
|
* HTTPS functions can specify a higher timeout.
|
|
130
|
-
*
|
|
131
117
|
* @remarks
|
|
132
118
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
133
119
|
* function depends on the type of function: Event handling functions have a
|
|
@@ -138,7 +124,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
138
124
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
139
125
|
/**
|
|
140
126
|
* Min number of actual instances to be running at a given time.
|
|
141
|
-
*
|
|
142
127
|
* @remarks
|
|
143
128
|
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
144
129
|
* while idle.
|
|
@@ -150,7 +135,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
150
135
|
maxInstances?: number | Expression<number> | ResetValue;
|
|
151
136
|
/**
|
|
152
137
|
* Number of requests a function can serve at once.
|
|
153
|
-
*
|
|
154
138
|
* @remarks
|
|
155
139
|
* Can only be applied to functions running on Cloud Functions v2.
|
|
156
140
|
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
@@ -160,7 +144,6 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
160
144
|
concurrency?: number | Expression<number> | ResetValue;
|
|
161
145
|
/**
|
|
162
146
|
* Fractional number of CPUs to allocate to a function.
|
|
163
|
-
*
|
|
164
147
|
* @remarks
|
|
165
148
|
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
166
149
|
* This is different from the defaults when using the gcloud utility and is different from
|
|
@@ -199,11 +182,11 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
199
182
|
* @param handler - runs every time a Cloud Pub/Sub message is published
|
|
200
183
|
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
201
184
|
*/
|
|
202
|
-
export declare function onMessagePublished<T = any>(topic: string, handler: (event:
|
|
185
|
+
export declare function onMessagePublished<T = any>(topic: string, handler: (event: PubSubCloudEvent<T>) => any | Promise<any>): CloudFunction<PubSubCloudEvent<T>>;
|
|
203
186
|
/**
|
|
204
187
|
* Handle a message being published to a Pub/Sub topic.
|
|
205
188
|
* @param options - Option containing information (topic) for event
|
|
206
189
|
* @param handler - runs every time a Cloud Pub/Sub message is published
|
|
207
190
|
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
208
191
|
*/
|
|
209
|
-
export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event:
|
|
192
|
+
export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: PubSubCloudEvent<T>) => any | Promise<any>): CloudFunction<PubSubCloudEvent<T>>;
|
|
@@ -4,14 +4,13 @@ const require_common_encoding = require('../../common/encoding.js');
|
|
|
4
4
|
const require_common_onInit = require('../../common/onInit.js');
|
|
5
5
|
const require_v2_trace = require('../trace.js');
|
|
6
6
|
const require_v2_options = require('../options.js');
|
|
7
|
+
const require_v2_compat = require('../compat.js');
|
|
7
8
|
|
|
8
9
|
//#region src/v2/providers/pubsub.ts
|
|
9
10
|
var pubsub_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
10
11
|
Message: () => Message,
|
|
11
12
|
onMessagePublished: () => onMessagePublished
|
|
12
13
|
});
|
|
13
|
-
const V1_CONTEXT = Symbol("v1Context");
|
|
14
|
-
const V1_MESSAGE = Symbol("v1Message");
|
|
15
14
|
/**
|
|
16
15
|
* Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
|
|
17
16
|
* You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
|
|
@@ -34,7 +33,6 @@ const V1_MESSAGE = Symbol("v1Message");
|
|
|
34
33
|
*/
|
|
35
34
|
/**
|
|
36
35
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
37
|
-
*
|
|
38
36
|
* @param data - Payload of a Pub/Sub message.
|
|
39
37
|
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
40
38
|
*/
|
|
@@ -66,7 +64,6 @@ var Message = class {
|
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* Returns a JSON-serializable representation of this object.
|
|
69
|
-
*
|
|
70
67
|
* @returns A JSON-serializable representation of this object.
|
|
71
68
|
*/
|
|
72
69
|
toJSON() {
|
|
@@ -102,69 +99,8 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
102
99
|
delete opts.topic;
|
|
103
100
|
}
|
|
104
101
|
const func = (raw) => {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
messagePublishedData.message = new Message(messagePublishedData.message);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the v1-compatible EventContext object.
|
|
111
|
-
* This is a compatibility layer to ease migration from v1 to v2.
|
|
112
|
-
* @returns A v1 EventContext-like object.
|
|
113
|
-
*/
|
|
114
|
-
Object.defineProperty(raw, "context", { get: function() {
|
|
115
|
-
if (this[V1_CONTEXT]) {
|
|
116
|
-
return this[V1_CONTEXT];
|
|
117
|
-
}
|
|
118
|
-
const data = this.data;
|
|
119
|
-
if (!data?.message) {
|
|
120
|
-
throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
|
|
121
|
-
}
|
|
122
|
-
const v1Context = {
|
|
123
|
-
eventId: data.message.messageId,
|
|
124
|
-
timestamp: data.message.publishTime,
|
|
125
|
-
eventType: "google.pubsub.topic.publish",
|
|
126
|
-
resource: {
|
|
127
|
-
service: "pubsub.googleapis.com",
|
|
128
|
-
name: this.source.replace("//pubsub.googleapis.com/", "")
|
|
129
|
-
},
|
|
130
|
-
params: {}
|
|
131
|
-
};
|
|
132
|
-
this[V1_CONTEXT] = v1Context;
|
|
133
|
-
return this[V1_CONTEXT];
|
|
134
|
-
} });
|
|
135
|
-
/**
|
|
136
|
-
* Get the v1-compatible Message object.
|
|
137
|
-
* This is a compatibility layer to ease migration from v1 to v2.
|
|
138
|
-
* @returns A plain object mimicking the v1 Message structure.
|
|
139
|
-
*/
|
|
140
|
-
Object.defineProperty(raw, "message", { get: function() {
|
|
141
|
-
if (this[V1_MESSAGE]) {
|
|
142
|
-
return this[V1_MESSAGE];
|
|
143
|
-
}
|
|
144
|
-
const data = this.data;
|
|
145
|
-
if (!data || !data.message) {
|
|
146
|
-
throw new Error("Malformed Pub/Sub event: 'data.message' is missing.");
|
|
147
|
-
}
|
|
148
|
-
const v2Message = data.message;
|
|
149
|
-
const baseMessage = {
|
|
150
|
-
data: v2Message.data,
|
|
151
|
-
messageId: v2Message.messageId,
|
|
152
|
-
publishTime: v2Message.publishTime,
|
|
153
|
-
attributes: v2Message.attributes || {}
|
|
154
|
-
};
|
|
155
|
-
if (v2Message.orderingKey) {
|
|
156
|
-
baseMessage.orderingKey = v2Message.orderingKey;
|
|
157
|
-
}
|
|
158
|
-
this[V1_MESSAGE] = {
|
|
159
|
-
...baseMessage,
|
|
160
|
-
get json() {
|
|
161
|
-
return v2Message.json;
|
|
162
|
-
},
|
|
163
|
-
toJSON: () => baseMessage
|
|
164
|
-
};
|
|
165
|
-
return this[V1_MESSAGE];
|
|
166
|
-
} });
|
|
167
|
-
return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(raw);
|
|
102
|
+
const event = require_v2_compat.patchV1Compat(raw);
|
|
103
|
+
return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(event);
|
|
168
104
|
};
|
|
169
105
|
func.run = handler;
|
|
170
106
|
Object.defineProperty(func, "__trigger", { get: () => {
|