@flowcore/sdk 1.20.0 → 1.21.1
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/CHANGELOG.md +26 -0
- package/esm/commands/data-core/data-core.request-delete.d.ts +5 -1
- package/esm/commands/data-core/data-core.request-delete.d.ts.map +1 -1
- package/esm/commands/data-core/data-core.request-delete.js +3 -6
- package/esm/commands/event-type/event-type.info.d.ts +2 -0
- package/esm/commands/event-type/event-type.info.d.ts.map +1 -1
- package/esm/commands/event-type/event-type.info.js +3 -0
- package/esm/commands/event-type/event-type.request-delete.d.ts +5 -1
- package/esm/commands/event-type/event-type.request-delete.d.ts.map +1 -1
- package/esm/commands/event-type/event-type.request-delete.js +3 -6
- package/esm/commands/event-type/event-type.request-truncate.d.ts +5 -1
- package/esm/commands/event-type/event-type.request-truncate.d.ts.map +1 -1
- package/esm/commands/event-type/event-type.request-truncate.js +3 -6
- package/esm/commands/events/event.list.d.ts +5 -1
- package/esm/commands/events/event.list.d.ts.map +1 -1
- package/esm/commands/events/event.list.js +3 -6
- package/esm/commands/events/events.fetch-time-buckets-by-names.d.ts +3 -1
- package/esm/commands/events/events.fetch-time-buckets-by-names.d.ts.map +1 -1
- package/esm/commands/events/events.fetch-time-buckets-by-names.js +3 -6
- package/esm/commands/events/events.fetch.d.ts +3 -1
- package/esm/commands/events/events.fetch.d.ts.map +1 -1
- package/esm/commands/events/events.fetch.js +3 -6
- package/esm/commands/events/time-bucket.list.d.ts +5 -1
- package/esm/commands/events/time-bucket.list.d.ts.map +1 -1
- package/esm/commands/events/time-bucket.list.js +3 -6
- package/esm/commands/flow-type/flow-type.delete-request.d.ts +0 -2
- package/esm/commands/flow-type/flow-type.delete-request.d.ts.map +1 -1
- package/esm/commands/flow-type/flow-type.request-delete.d.ts +5 -1
- package/esm/commands/flow-type/flow-type.request-delete.d.ts.map +1 -1
- package/esm/commands/flow-type/flow-type.request-delete.js +3 -6
- package/esm/commands/index.d.ts +1 -0
- package/esm/commands/index.d.ts.map +1 -1
- package/esm/commands/index.js +1 -0
- package/esm/commands/security/pat.exchange.d.ts.map +1 -1
- package/esm/commands/security/permissions.list.d.ts +31 -0
- package/esm/commands/security/permissions.list.d.ts.map +1 -0
- package/esm/commands/security/permissions.list.js +46 -0
- package/esm/commands/tenant/tenant.fetch.d.ts.map +1 -1
- package/esm/commands/tenant/tenant.fetch.js +19 -1
- package/esm/commands/tenant/tenant.translate-name-to-id.d.ts.map +1 -1
- package/esm/common/command-custom.d.ts +0 -2
- package/esm/common/command-custom.d.ts.map +1 -1
- package/esm/common/command.d.ts +9 -5
- package/esm/common/command.d.ts.map +1 -1
- package/esm/common/command.js +33 -11
- package/esm/common/flowcore-client.d.ts +5 -6
- package/esm/common/flowcore-client.d.ts.map +1 -1
- package/esm/common/flowcore-client.js +20 -35
- package/esm/common/tenant.cache.d.ts +17 -0
- package/esm/common/tenant.cache.d.ts.map +1 -0
- package/esm/common/tenant.cache.js +2 -0
- package/esm/contracts/index.d.ts +1 -0
- package/esm/contracts/index.d.ts.map +1 -1
- package/esm/contracts/pat.d.ts.map +1 -1
- package/esm/contracts/permission.d.ts +20 -0
- package/esm/contracts/permission.d.ts.map +1 -0
- package/esm/contracts/permission.js +15 -0
- package/esm/utils/local-cache.d.ts +11 -0
- package/esm/utils/local-cache.d.ts.map +1 -0
- package/esm/utils/local-cache.js +45 -0
- package/esm/utils/try-catch.d.ts +12 -0
- package/esm/utils/try-catch.d.ts.map +1 -0
- package/esm/utils/try-catch.js +10 -0
- package/package.json +1 -2
- package/script/commands/data-core/data-core.request-delete.d.ts +5 -1
- package/script/commands/data-core/data-core.request-delete.d.ts.map +1 -1
- package/script/commands/data-core/data-core.request-delete.js +3 -6
- package/script/commands/event-type/event-type.info.d.ts +2 -0
- package/script/commands/event-type/event-type.info.d.ts.map +1 -1
- package/script/commands/event-type/event-type.info.js +3 -0
- package/script/commands/event-type/event-type.request-delete.d.ts +5 -1
- package/script/commands/event-type/event-type.request-delete.d.ts.map +1 -1
- package/script/commands/event-type/event-type.request-delete.js +3 -6
- package/script/commands/event-type/event-type.request-truncate.d.ts +5 -1
- package/script/commands/event-type/event-type.request-truncate.d.ts.map +1 -1
- package/script/commands/event-type/event-type.request-truncate.js +3 -6
- package/script/commands/events/event.list.d.ts +5 -1
- package/script/commands/events/event.list.d.ts.map +1 -1
- package/script/commands/events/event.list.js +3 -6
- package/script/commands/events/events.fetch-time-buckets-by-names.d.ts +3 -1
- package/script/commands/events/events.fetch-time-buckets-by-names.d.ts.map +1 -1
- package/script/commands/events/events.fetch-time-buckets-by-names.js +3 -6
- package/script/commands/events/events.fetch.d.ts +3 -1
- package/script/commands/events/events.fetch.d.ts.map +1 -1
- package/script/commands/events/events.fetch.js +3 -6
- package/script/commands/events/time-bucket.list.d.ts +5 -1
- package/script/commands/events/time-bucket.list.d.ts.map +1 -1
- package/script/commands/events/time-bucket.list.js +3 -6
- package/script/commands/flow-type/flow-type.delete-request.d.ts +0 -2
- package/script/commands/flow-type/flow-type.delete-request.d.ts.map +1 -1
- package/script/commands/flow-type/flow-type.request-delete.d.ts +5 -1
- package/script/commands/flow-type/flow-type.request-delete.d.ts.map +1 -1
- package/script/commands/flow-type/flow-type.request-delete.js +3 -6
- package/script/commands/index.d.ts +1 -0
- package/script/commands/index.d.ts.map +1 -1
- package/script/commands/index.js +1 -0
- package/script/commands/security/pat.exchange.d.ts.map +1 -1
- package/script/commands/security/permissions.list.d.ts +31 -0
- package/script/commands/security/permissions.list.d.ts.map +1 -0
- package/script/commands/security/permissions.list.js +50 -0
- package/script/commands/tenant/tenant.fetch.d.ts.map +1 -1
- package/script/commands/tenant/tenant.fetch.js +19 -1
- package/script/commands/tenant/tenant.translate-name-to-id.d.ts.map +1 -1
- package/script/common/command-custom.d.ts +0 -2
- package/script/common/command-custom.d.ts.map +1 -1
- package/script/common/command.d.ts +9 -5
- package/script/common/command.d.ts.map +1 -1
- package/script/common/command.js +33 -11
- package/script/common/flowcore-client.d.ts +5 -6
- package/script/common/flowcore-client.d.ts.map +1 -1
- package/script/common/flowcore-client.js +20 -38
- package/script/common/tenant.cache.d.ts +17 -0
- package/script/common/tenant.cache.d.ts.map +1 -0
- package/script/common/tenant.cache.js +5 -0
- package/script/contracts/index.d.ts +1 -0
- package/script/contracts/index.d.ts.map +1 -1
- package/script/contracts/pat.d.ts.map +1 -1
- package/script/contracts/permission.d.ts +20 -0
- package/script/contracts/permission.d.ts.map +1 -0
- package/script/contracts/permission.js +18 -0
- package/script/utils/local-cache.d.ts +11 -0
- package/script/utils/local-cache.d.ts.map +1 -0
- package/script/utils/local-cache.js +49 -0
- package/script/utils/try-catch.d.ts +12 -0
- package/script/utils/try-catch.d.ts.map +1 -0
- package/script/utils/try-catch.js +13 -0
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.FlowcoreClient = void 0;
|
|
7
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
-
const index_js_1 = require("../commands/index.js");
|
|
9
4
|
const client_error_js_1 = require("../exceptions/client-error.js");
|
|
10
5
|
const command_error_js_1 = require("../exceptions/command-error.js");
|
|
6
|
+
const try_catch_js_1 = require("../utils/try-catch.js");
|
|
7
|
+
const tenant_cache_js_1 = require("./tenant.cache.js");
|
|
11
8
|
const RETRYABLE_ERROR_CODES = [408, 429, 500, 502, 503, 504];
|
|
12
|
-
const getDedicatedTenantCacheKey = (tenantId) => `dedicated-tenant-${tenantId}`;
|
|
13
9
|
/**
|
|
14
10
|
* A base client for executing commands
|
|
15
11
|
*/
|
|
@@ -33,12 +29,6 @@ class FlowcoreClient {
|
|
|
33
29
|
writable: true,
|
|
34
30
|
value: void 0
|
|
35
31
|
});
|
|
36
|
-
Object.defineProperty(this, "dedicatedTenantCache", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: new node_cache_1.default()
|
|
41
|
-
});
|
|
42
32
|
if (this.options.getBearerToken) {
|
|
43
33
|
this.mode = "bearer";
|
|
44
34
|
}
|
|
@@ -74,29 +64,21 @@ class FlowcoreClient {
|
|
|
74
64
|
/**
|
|
75
65
|
* Execute a command (inner method)
|
|
76
66
|
*/
|
|
77
|
-
async innerExecute(command, retryCount = 0
|
|
67
|
+
async innerExecute(command, retryCount = 0) {
|
|
78
68
|
const request = await command.getRequest(this);
|
|
79
|
-
if (request.supportsDedicatedUrl && request.dedicatedSubdomain && dedicatedTenantId) {
|
|
80
|
-
let tenantConfig = this.dedicatedTenantCache.get(getDedicatedTenantCacheKey(dedicatedTenantId));
|
|
81
|
-
if (tenantConfig === undefined) {
|
|
82
|
-
const tenant = await this.execute(new index_js_1.TenantFetchCommand({ tenantId: dedicatedTenantId }));
|
|
83
|
-
tenantConfig = tenant;
|
|
84
|
-
this.dedicatedTenantCache.set(getDedicatedTenantCacheKey(dedicatedTenantId), tenant, 60 * 5);
|
|
85
|
-
}
|
|
86
|
-
if (tenantConfig.isDedicated) {
|
|
87
|
-
if (!tenantConfig.dedicated?.configuration.domain) {
|
|
88
|
-
throw new command_error_js_1.CommandError(command.constructor.name, `Tenant ${dedicatedTenantId} does not have a dedicated domain configured`);
|
|
89
|
-
}
|
|
90
|
-
this.baseUrl = `https://${request.dedicatedSubdomain}.${tenantConfig.dedicated?.configuration.domain}`;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
69
|
if (request.customExecute) {
|
|
94
70
|
return request.customExecute(this);
|
|
95
71
|
}
|
|
96
72
|
if (!request.allowedModes.includes(this.mode)) {
|
|
97
73
|
throw new command_error_js_1.CommandError(command.constructor.name, `Not allowed in "${this.mode}" mode`);
|
|
98
74
|
}
|
|
99
|
-
const authHeader = await this.getAuthHeader();
|
|
75
|
+
const { data: authHeader, error: authHeaderError } = await (0, try_catch_js_1.tryCatch)(this.getAuthHeader());
|
|
76
|
+
if (authHeaderError) {
|
|
77
|
+
throw new client_error_js_1.ClientError("Failed to get auth header", 0, command.constructor.name, {
|
|
78
|
+
command: command.constructor.name,
|
|
79
|
+
error: authHeaderError,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
100
82
|
const headers = {
|
|
101
83
|
...request.headers,
|
|
102
84
|
...(authHeader ? { Authorization: authHeader } : {}),
|
|
@@ -152,22 +134,22 @@ class FlowcoreClient {
|
|
|
152
134
|
/**
|
|
153
135
|
* Execute a command
|
|
154
136
|
*/
|
|
155
|
-
execute(command
|
|
156
|
-
return this.innerExecute(command, 0
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Clear the dedicated tenant cache
|
|
160
|
-
*/
|
|
161
|
-
clearDedicatedTenantCache() {
|
|
162
|
-
this.dedicatedTenantCache.flushAll();
|
|
137
|
+
execute(command) {
|
|
138
|
+
return this.innerExecute(command, 0);
|
|
163
139
|
}
|
|
164
140
|
/**
|
|
165
141
|
* Close the client and clean up resources
|
|
166
142
|
* This should be called when the client is no longer needed to prevent memory leaks
|
|
167
143
|
*/
|
|
168
144
|
close() {
|
|
169
|
-
//
|
|
170
|
-
|
|
145
|
+
// Clear the tenant cache
|
|
146
|
+
tenant_cache_js_1.tenantCache.clear();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Dispose the client
|
|
150
|
+
*/
|
|
151
|
+
[Symbol.dispose]() {
|
|
152
|
+
this.close();
|
|
171
153
|
}
|
|
172
154
|
}
|
|
173
155
|
exports.FlowcoreClient = FlowcoreClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LocalCache } from "../utils/local-cache.js";
|
|
2
|
+
export declare const tenantCache: LocalCache<{
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
description: string;
|
|
7
|
+
websiteUrl: string;
|
|
8
|
+
isDedicated: boolean;
|
|
9
|
+
dedicated: {
|
|
10
|
+
status: "ready" | "degraded" | "offline";
|
|
11
|
+
configuration: {
|
|
12
|
+
domain: string;
|
|
13
|
+
configurationRepoUrl: string;
|
|
14
|
+
};
|
|
15
|
+
} | null;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=tenant.cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant.cache.d.ts","sourceRoot":"","sources":["../../src/common/tenant.cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;EAAoC,CAAA"}
|
|
@@ -3,4 +3,5 @@ export type { EventType } from "./event-type.js";
|
|
|
3
3
|
export type { FlowType } from "./flow-type.js";
|
|
4
4
|
export type { FlowcoreEvent } from "./event.js";
|
|
5
5
|
export type { Tenant } from "./tenant.js";
|
|
6
|
+
export type { Permission } from "./permission.js";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pat.d.ts","sourceRoot":"","sources":["../../src/contracts/pat.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"pat.d.ts","sourceRoot":"","sources":["../../src/contracts/pat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAA;AAEjG;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,CAAC;IAC9B,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,OAAO,CAAA;IACb,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/B,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;CACnB,CAMC,CAAA;AACF;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Static, type TArray, type TLiteral, type TObject, type TString, type TUnion } from "@sinclair/typebox";
|
|
2
|
+
/**
|
|
3
|
+
* The schema for a permission
|
|
4
|
+
*/
|
|
5
|
+
export declare const PermissionSchema: TObject<{
|
|
6
|
+
tenant: TString;
|
|
7
|
+
type: TString;
|
|
8
|
+
id: TString;
|
|
9
|
+
action: TArray<TUnion<[
|
|
10
|
+
TLiteral<"read">,
|
|
11
|
+
TLiteral<"write">,
|
|
12
|
+
TLiteral<"ingest">,
|
|
13
|
+
TLiteral<"fetch">
|
|
14
|
+
]>>;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* The type for a permission
|
|
18
|
+
*/
|
|
19
|
+
export type Permission = Static<typeof PermissionSchema>;
|
|
20
|
+
//# sourceMappingURL=permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../../src/contracts/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EAEZ,MAAM,mBAAmB,CAAA;AAE1B;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC;IACrC,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,MAAM,CACZ,MAAM,CAAC;QACL,QAAQ,CAAC,MAAM,CAAC;QAChB,QAAQ,CAAC,OAAO,CAAC;QACjB,QAAQ,CAAC,QAAQ,CAAC;QAClB,QAAQ,CAAC,OAAO,CAAC;KAClB,CAAC,CACH,CAAA;CACF,CAYC,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionSchema = void 0;
|
|
4
|
+
const typebox_1 = require("@sinclair/typebox");
|
|
5
|
+
/**
|
|
6
|
+
* The schema for a permission
|
|
7
|
+
*/
|
|
8
|
+
exports.PermissionSchema = typebox_1.Type.Object({
|
|
9
|
+
tenant: typebox_1.Type.String(),
|
|
10
|
+
type: typebox_1.Type.String(),
|
|
11
|
+
id: typebox_1.Type.String(),
|
|
12
|
+
action: typebox_1.Type.Array(typebox_1.Type.Union([
|
|
13
|
+
typebox_1.Type.Literal("read"),
|
|
14
|
+
typebox_1.Type.Literal("write"),
|
|
15
|
+
typebox_1.Type.Literal("ingest"),
|
|
16
|
+
typebox_1.Type.Literal("fetch"),
|
|
17
|
+
])),
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class LocalCache<T> {
|
|
2
|
+
private readonly defaultTtlMs?;
|
|
3
|
+
private cache;
|
|
4
|
+
private timers;
|
|
5
|
+
constructor(defaultTtlMs?: number | undefined);
|
|
6
|
+
get(key: string): T | undefined;
|
|
7
|
+
set(key: string, value: T, ttlMs?: number): void;
|
|
8
|
+
delete(key: string): void;
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=local-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-cache.d.ts","sourceRoot":"","sources":["../../src/utils/local-cache.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU,CAAC,CAAC;IAKX,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAJ1C,OAAO,CAAC,KAAK,CAA4B;IAEzC,OAAO,CAAC,MAAM,CAA8B;gBAEf,YAAY,CAAC,EAAE,MAAM,YAAA;IAElD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAI/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM;IASzC,MAAM,CAAC,GAAG,EAAE,MAAM;IAKlB,KAAK;CAON"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalCache = void 0;
|
|
4
|
+
class LocalCache {
|
|
5
|
+
constructor(defaultTtlMs) {
|
|
6
|
+
Object.defineProperty(this, "defaultTtlMs", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: defaultTtlMs
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "cache", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: new Map()
|
|
17
|
+
});
|
|
18
|
+
// deno-lint-ignore no-explicit-any
|
|
19
|
+
Object.defineProperty(this, "timers", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: new Map()
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get(key) {
|
|
27
|
+
return this.cache.get(key);
|
|
28
|
+
}
|
|
29
|
+
set(key, value, ttlMs) {
|
|
30
|
+
clearTimeout(this.timers.get(key));
|
|
31
|
+
this.cache.set(key, value);
|
|
32
|
+
if (ttlMs ?? this.defaultTtlMs) {
|
|
33
|
+
const timer = setTimeout(() => this.cache.delete(key), ttlMs ?? this.defaultTtlMs);
|
|
34
|
+
this.timers.set(key, timer);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
delete(key) {
|
|
38
|
+
clearTimeout(this.timers.get(key));
|
|
39
|
+
this.cache.delete(key);
|
|
40
|
+
}
|
|
41
|
+
clear() {
|
|
42
|
+
for (const key of this.timers.keys()) {
|
|
43
|
+
clearTimeout(this.timers.get(key));
|
|
44
|
+
}
|
|
45
|
+
this.cache.clear();
|
|
46
|
+
this.timers.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.LocalCache = LocalCache;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Success<T> = {
|
|
2
|
+
data: T;
|
|
3
|
+
error: null;
|
|
4
|
+
};
|
|
5
|
+
type Failure<E> = {
|
|
6
|
+
data: null;
|
|
7
|
+
error: E;
|
|
8
|
+
};
|
|
9
|
+
type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
10
|
+
export declare function tryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=try-catch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"try-catch.d.ts","sourceRoot":"","sources":["../../src/utils/try-catch.ts"],"names":[],"mappings":"AACA,KAAK,OAAO,CAAC,CAAC,IAAI;IAChB,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ,CAAA;AAED,KAAK,OAAO,CAAC,CAAC,IAAI;IAChB,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAGnD,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EACzC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAOvB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryCatch = tryCatch;
|
|
4
|
+
// Main wrapper function
|
|
5
|
+
async function tryCatch(promise) {
|
|
6
|
+
try {
|
|
7
|
+
const data = await promise;
|
|
8
|
+
return { data, error: null };
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return { data: null, error: error };
|
|
12
|
+
}
|
|
13
|
+
}
|