@simpleview/sv-pubsub 1.0.14

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/dist/.gitkeep ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PubSubClient = void 0;
7
+ var PubSubClient_1 = require("./lib/PubSubClient");
8
+ Object.defineProperty(exports, "PubSubClient", { enumerable: true, get: function () { return __importDefault(PubSubClient_1).default; } });
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pubsub_1 = require("@google-cloud/pubsub");
4
+ class PubSubClient {
5
+ pubsub;
6
+ constructor(options) {
7
+ this.pubsub = new pubsub_1.PubSub(options);
8
+ }
9
+ async createTopic(topicName) {
10
+ try {
11
+ const [topic] = await this.pubsub.createTopic(topicName);
12
+ return topic;
13
+ }
14
+ catch (error) {
15
+ if (error.code === 6) { // ALREADY_EXISTS
16
+ return this.pubsub.topic(topicName);
17
+ }
18
+ throw error;
19
+ }
20
+ }
21
+ async createSubscription(topicName, subscriptionName, retentionDuration) {
22
+ try {
23
+ const [subscription] = await this.pubsub
24
+ .topic(topicName)
25
+ .createSubscription(subscriptionName, {
26
+ messageRetentionDuration: { seconds: retentionDuration || 86400 }
27
+ });
28
+ return subscription;
29
+ }
30
+ catch (error) {
31
+ if (error.code === 6) { // ALREADY_EXISTS
32
+ return this.pubsub.subscription(subscriptionName);
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+ close() {
38
+ return this.pubsub.close();
39
+ }
40
+ }
41
+ exports.default = PubSubClient;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_1 = require("child_process");
4
+ describe(__filename, function () {
5
+ this.timeout(15000);
6
+ it("Run linter", async () => {
7
+ (0, child_process_1.execSync)("yarn run style", { stdio: "inherit" });
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export { default as PubSubClient, PubSubClientOptions } from "./lib/PubSubClient";
@@ -0,0 +1,15 @@
1
+ import { PubSub, Subscription } from "@google-cloud/pubsub";
2
+ export type PubSubClientOptions = {
3
+ projectId: string;
4
+ credentials: {
5
+ private_key: string;
6
+ client_email: string;
7
+ };
8
+ };
9
+ export default class PubSubClient {
10
+ pubsub: PubSub;
11
+ constructor(options: PubSubClientOptions);
12
+ createTopic(topicName: string): Promise<import("@google-cloud/pubsub").Topic>;
13
+ createSubscription(topicName: string, subscriptionName: string, retentionDuration?: number): Promise<Subscription>;
14
+ close(): Promise<void>;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@simpleview/sv-pubsub",
3
+ "version": "1.0.14",
4
+ "description": "Client for communicating with Google Pub/Sub",
5
+ "author": "Paul Riding <paul.riding@granicus.com>",
6
+ "devDependencies": {
7
+ "@simpleview/assertlib": "1.2.0",
8
+ "@simpleview/mochalib": "2.0.2",
9
+ "@tsconfig/node20": "20.1.4",
10
+ "@types/mocha": "9.1.1",
11
+ "@types/node": "20.1.4",
12
+ "eslint": "8.36.0",
13
+ "mocha": "11.1.0",
14
+ "ts-mocha": "10.0.0",
15
+ "ts-node": "10.9.2",
16
+ "ts-node-dev": "2.0.0",
17
+ "typescript": "5.4.5"
18
+ },
19
+ "dependencies": {
20
+ "@google-cloud/pubsub": "5.2.0"
21
+ },
22
+ "resolutions": {
23
+ "ts-mocha/tsconfig-paths": "^3.15.0"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "default": "./dist/cjs/index.js"
32
+ },
33
+ "./lib/*": {
34
+ "types": "./dist/types/lib/*.d.ts",
35
+ "default": "./dist/cjs/lib/*.js"
36
+ }
37
+ },
38
+ "scripts": {
39
+ "build": "yarn run build:cjs && yarn run build:types",
40
+ "build:esm": "rm -rf ./dist/esm && tsc --project ./tsconfig.esm.json",
41
+ "build:cjs": "rm -rf ./dist/cjs && tsc --project ./tsconfig.cjs.json",
42
+ "build:types": "rm -rf ./dist/types && tsc --project ./tsconfig.types.json",
43
+ "test": "ts-mocha --paths './src/**/*.test.ts'",
44
+ "docker": "./src/scripts/run || true",
45
+ "publish": "./src/scripts/publish",
46
+ "install:host": "npm install -f --package-lock false",
47
+ "style": "eslint .",
48
+ "style:fix": "eslint --fix .",
49
+ "sync-state": "bash ./src/scripts/sync-state",
50
+ "types": "tsc -p tsconfig.json --noEmit"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "https://github.com/simpleviewinc/sv-pubsub"
55
+ },
56
+ "license": "MIT",
57
+ "packageManager": "yarn@4.2.2",
58
+ "sideEffects": false
59
+ }