Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yaschema-api-google-cloud-task-creator

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaschema-api-google-cloud-task-creator - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

16

lib/cjs/create-google-cloud-task/create-google-cloud-task/index.js

@@ -32,3 +32,3 @@ "use strict";

/** Uses `new CloudTasksClient().createTask` to access the specified API */
const createGoogleCloudTask = (api_1, req_1, ...args_1) => __awaiter(void 0, [api_1, req_1, ...args_1], void 0, function* (api, req, { requestValidationMode = (0, validation_mode_1.getDefaultRequestValidationMode)(), creationOptions, limitMode = DEFAULT_TASK_LIMIT_MODE, limitMSec = DEFAULT_TASK_LIMIT_MSEC, limitType = DEFAULT_TASK_LIMIT_TYPE, limitNameExtension = '' } = {}) {
const createGoogleCloudTask = (api_1, req_1, ...args_1) => __awaiter(void 0, [api_1, req_1, ...args_1], void 0, function* (api, req, { requestValidationMode = (0, validation_mode_1.getDefaultRequestValidationMode)(), creationOptions, delayMSec = 0, limitMode = DEFAULT_TASK_LIMIT_MODE, limitMSec = DEFAULT_TASK_LIMIT_MSEC, limitType = DEFAULT_TASK_LIMIT_TYPE, limitNameExtension = '' } = {}) {
var _a;

@@ -43,3 +43,11 @@ if (api.method === 'LINK' || api.method === 'UNLINK') {

});
const scheduleTimeMSec = (0, getScheduleTimeMSec_1.getScheduleTimeMSec)({ limitMode, limitMSec });
const scheduleTimeMSec = (0, getScheduleTimeMSec_1.getScheduleTimeMSec)({ delayMSec, limitMode, limitMSec });
let scheduleTime;
if (limitMSec > 0 && limitMode === 'trailing') {
scheduleTime = { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
}
else if (delayMSec > 0) {
const runTimeMSec = Date.now() + delayMSec;
scheduleTime = { seconds: Math.floor(runTimeMSec / ONE_SEC_MSEC), nanos: (runTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
}
const request = {

@@ -51,5 +59,3 @@ parent: (0, getGoogleCloudTasksClient_1.getGoogleCloudTasksClient)().queuePath((0, google_cloud_project_1.getGoogleCloudProjectForRouteType)(api.routeType), (0, google_cloud_location_1.getGoogleCloudLocationForRouteType)(api.routeType), (0, google_cloud_task_queue_1.getGoogleCloudTaskQueueForRouteType)(api.routeType)),

: null,
scheduleTime: limitMSec > 0 && limitMode === 'trailing'
? { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC }
: undefined,
scheduleTime,
httpRequest: {

@@ -56,0 +62,0 @@ httpMethod: api.method,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getScheduleTimeMSec = void 0;
const getScheduleTimeMSec = ({ limitMode, limitMSec }) => {
const getScheduleTimeMSec = ({ delayMSec, limitMode, limitMSec }) => {
const timeMSec = Date.now() + delayMSec;
switch (limitMode) {
case 'leading':
return Math.floor(Date.now() / limitMSec) * limitMSec;
return Math.floor(timeMSec / limitMSec) * limitMSec;
case 'trailing':
return Math.ceil(Date.now() / limitMSec) * limitMSec;
return Math.ceil(timeMSec / limitMSec) * limitMSec;
}

@@ -11,0 +12,0 @@ };

@@ -16,2 +16,4 @@ import type { CallOptions } from 'google-gax';

creationOptions?: CallOptions;
/** @defaultValue `0` */
delayMSec?: number;
/** @defaultValue `'trailing'` */

@@ -27,3 +29,3 @@ limitMode?: LimitMode;

/** Uses `new CloudTasksClient().createTask` to access the specified API */
export declare const createGoogleCloudTask: <ReqHeadersT extends AnyHeaders, ReqParamsT extends AnyParams, ReqQueryT extends AnyQuery, ReqBodyT extends unknown, ResStatusT extends number, ResHeadersT extends AnyHeaders, ResBodyT extends unknown, ErrResStatusT extends number, ErrResHeadersT extends AnyHeaders, ErrResBodyT extends unknown>(api: HttpApi<ReqHeadersT, ReqParamsT, ReqQueryT, ReqBodyT, ResStatusT, ResHeadersT, ResBodyT, ErrResStatusT, ErrResHeadersT, ErrResBodyT>, req: ApiRequest<ReqHeadersT, ReqParamsT, ReqQueryT, ReqBodyT>, { requestValidationMode, creationOptions, limitMode, limitMSec, limitType, limitNameExtension }?: CreateGoogleCloudTaskOptions) => Promise<CreateTaskResult>;
export declare const createGoogleCloudTask: <ReqHeadersT extends AnyHeaders, ReqParamsT extends AnyParams, ReqQueryT extends AnyQuery, ReqBodyT extends unknown, ResStatusT extends number, ResHeadersT extends AnyHeaders, ResBodyT extends unknown, ErrResStatusT extends number, ErrResHeadersT extends AnyHeaders, ErrResBodyT extends unknown>(api: HttpApi<ReqHeadersT, ReqParamsT, ReqQueryT, ReqBodyT, ResStatusT, ResHeadersT, ResBodyT, ErrResStatusT, ErrResHeadersT, ErrResBodyT>, req: ApiRequest<ReqHeadersT, ReqParamsT, ReqQueryT, ReqBodyT>, { requestValidationMode, creationOptions, delayMSec, limitMode, limitMSec, limitType, limitNameExtension }?: CreateGoogleCloudTaskOptions) => Promise<CreateTaskResult>;
//# sourceMappingURL=index.d.ts.map
import type { LimitMode } from '../types/LimitMode';
export declare const getScheduleTimeMSec: ({ limitMode, limitMSec }: {
export declare const getScheduleTimeMSec: ({ delayMSec, limitMode, limitMSec }: {
delayMSec: number;
limitMode: LimitMode;

@@ -4,0 +5,0 @@ limitMSec: number;

@@ -29,3 +29,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

/** Uses `new CloudTasksClient().createTask` to access the specified API */
export const createGoogleCloudTask = (api_1, req_1, ...args_1) => __awaiter(void 0, [api_1, req_1, ...args_1], void 0, function* (api, req, { requestValidationMode = getDefaultRequestValidationMode(), creationOptions, limitMode = DEFAULT_TASK_LIMIT_MODE, limitMSec = DEFAULT_TASK_LIMIT_MSEC, limitType = DEFAULT_TASK_LIMIT_TYPE, limitNameExtension = '' } = {}) {
export const createGoogleCloudTask = (api_1, req_1, ...args_1) => __awaiter(void 0, [api_1, req_1, ...args_1], void 0, function* (api, req, { requestValidationMode = getDefaultRequestValidationMode(), creationOptions, delayMSec = 0, limitMode = DEFAULT_TASK_LIMIT_MODE, limitMSec = DEFAULT_TASK_LIMIT_MSEC, limitType = DEFAULT_TASK_LIMIT_TYPE, limitNameExtension = '' } = {}) {
var _a;

@@ -40,3 +40,11 @@ if (api.method === 'LINK' || api.method === 'UNLINK') {

});
const scheduleTimeMSec = getScheduleTimeMSec({ limitMode, limitMSec });
const scheduleTimeMSec = getScheduleTimeMSec({ delayMSec, limitMode, limitMSec });
let scheduleTime;
if (limitMSec > 0 && limitMode === 'trailing') {
scheduleTime = { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
}
else if (delayMSec > 0) {
const runTimeMSec = Date.now() + delayMSec;
scheduleTime = { seconds: Math.floor(runTimeMSec / ONE_SEC_MSEC), nanos: (runTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
}
const request = {

@@ -48,5 +56,3 @@ parent: getGoogleCloudTasksClient().queuePath(getGoogleCloudProjectForRouteType(api.routeType), getGoogleCloudLocationForRouteType(api.routeType), getGoogleCloudTaskQueueForRouteType(api.routeType)),

: null,
scheduleTime: limitMSec > 0 && limitMode === 'trailing'
? { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC }
: undefined,
scheduleTime,
httpRequest: {

@@ -53,0 +59,0 @@ httpMethod: api.method,

@@ -1,9 +0,10 @@

export const getScheduleTimeMSec = ({ limitMode, limitMSec }) => {
export const getScheduleTimeMSec = ({ delayMSec, limitMode, limitMSec }) => {
const timeMSec = Date.now() + delayMSec;
switch (limitMode) {
case 'leading':
return Math.floor(Date.now() / limitMSec) * limitMSec;
return Math.floor(timeMSec / limitMSec) * limitMSec;
case 'trailing':
return Math.ceil(Date.now() / limitMSec) * limitMSec;
return Math.ceil(timeMSec / limitMSec) * limitMSec;
}
};
//# sourceMappingURL=getScheduleTimeMSec.js.map
{
"name": "yaschema-api-google-cloud-task-creator",
"version": "1.2.1",
"version": "1.3.0",
"description": "Google Cloud createTask support for yaschema-api",

@@ -5,0 +5,0 @@ "keywords": [

@@ -0,1 +1,2 @@

import type { google } from '@google-cloud/tasks/build/protos/protos';
import type { CallOptions } from 'google-gax';

@@ -48,2 +49,4 @@ import { v4 as uuid } from 'uuid';

creationOptions?: CallOptions;
/** @defaultValue `0` */
delayMSec?: number;
/** @defaultValue `'trailing'` */

@@ -77,2 +80,3 @@ limitMode?: LimitMode;

creationOptions,
delayMSec = 0,
limitMode = DEFAULT_TASK_LIMIT_MODE,

@@ -95,4 +99,12 @@ limitMSec = DEFAULT_TASK_LIMIT_MSEC,

const scheduleTimeMSec = getScheduleTimeMSec({ limitMode, limitMSec });
const scheduleTimeMSec = getScheduleTimeMSec({ delayMSec, limitMode, limitMSec });
let scheduleTime: google.protobuf.ITimestamp | undefined;
if (limitMSec > 0 && limitMode === 'trailing') {
scheduleTime = { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
} else if (delayMSec > 0) {
const runTimeMSec = Date.now() + delayMSec;
scheduleTime = { seconds: Math.floor(runTimeMSec / ONE_SEC_MSEC), nanos: (runTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC };
}
const request: CreateTaskRequest = {

@@ -113,6 +125,3 @@ parent: getGoogleCloudTasksClient().queuePath(

: null,
scheduleTime:
limitMSec > 0 && limitMode === 'trailing'
? { seconds: Math.floor(scheduleTimeMSec / ONE_SEC_MSEC), nanos: (scheduleTimeMSec % ONE_SEC_MSEC) * ONE_MSEC_NSEC }
: undefined,
scheduleTime,
httpRequest: {

@@ -119,0 +128,0 @@ httpMethod: api.method,

import type { LimitMode } from '../types/LimitMode';
export const getScheduleTimeMSec = ({ limitMode, limitMSec }: { limitMode: LimitMode; limitMSec: number }) => {
export const getScheduleTimeMSec = ({
delayMSec,
limitMode,
limitMSec
}: {
delayMSec: number;
limitMode: LimitMode;
limitMSec: number;
}) => {
const timeMSec = Date.now() + delayMSec;
switch (limitMode) {
case 'leading':
return Math.floor(Date.now() / limitMSec) * limitMSec;
return Math.floor(timeMSec / limitMSec) * limitMSec;
case 'trailing':
return Math.ceil(Date.now() / limitMSec) * limitMSec;
return Math.ceil(timeMSec / limitMSec) * limitMSec;
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc