@forge/kvs 0.0.2-next.0 → 0.0.2-next.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.
Files changed (49) hide show
  1. package/out/__test__/index.test.d.ts +2 -0
  2. package/out/__test__/index.test.d.ts.map +1 -0
  3. package/out/__test__/index.test.js +509 -0
  4. package/out/conditions.d.ts +38 -0
  5. package/out/conditions.d.ts.map +1 -0
  6. package/out/conditions.js +98 -0
  7. package/out/entity-query.d.ts +13 -0
  8. package/out/entity-query.d.ts.map +1 -0
  9. package/out/entity-query.js +100 -0
  10. package/out/entity.d.ts +13 -0
  11. package/out/entity.d.ts.map +1 -0
  12. package/out/entity.js +35 -0
  13. package/out/errors.d.ts +21 -0
  14. package/out/errors.d.ts.map +1 -0
  15. package/out/errors.js +26 -0
  16. package/out/index.d.ts +9 -0
  17. package/out/index.d.ts.map +1 -0
  18. package/out/index.js +43 -0
  19. package/out/interfaces/entity-query.d.ts +41 -0
  20. package/out/interfaces/entity-query.d.ts.map +1 -0
  21. package/out/interfaces/entity-query.js +2 -0
  22. package/out/interfaces/kvs-api.d.ts +72 -0
  23. package/out/interfaces/kvs-api.d.ts.map +1 -0
  24. package/out/interfaces/kvs-api.js +2 -0
  25. package/out/interfaces/kvs.d.ts +19 -0
  26. package/out/interfaces/kvs.d.ts.map +1 -0
  27. package/out/interfaces/kvs.js +2 -0
  28. package/out/interfaces/query.d.ts +17 -0
  29. package/out/interfaces/query.d.ts.map +1 -0
  30. package/out/interfaces/query.js +2 -0
  31. package/out/interfaces/types.d.ts +64 -0
  32. package/out/interfaces/types.d.ts.map +1 -0
  33. package/out/interfaces/types.js +8 -0
  34. package/out/kvs.d.ts +16 -0
  35. package/out/kvs.d.ts.map +1 -0
  36. package/out/kvs.js +36 -0
  37. package/out/query.d.ts +14 -0
  38. package/out/query.d.ts.map +1 -0
  39. package/out/query.js +38 -0
  40. package/out/storage-api.d.ts +20 -0
  41. package/out/storage-api.d.ts.map +1 -0
  42. package/out/storage-api.js +77 -0
  43. package/out/utils/__test__/error-handling.test.d.ts +2 -0
  44. package/out/utils/__test__/error-handling.test.d.ts.map +1 -0
  45. package/out/utils/__test__/error-handling.test.js +121 -0
  46. package/out/utils/error-handling.d.ts +7 -0
  47. package/out/utils/error-handling.d.ts.map +1 -0
  48. package/out/utils/error-handling.js +42 -0
  49. package/package.json +3 -4
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterBuilder = exports.KvsIndexQueryBuilder = void 0;
4
+ class KvsIndexQueryBuilder {
5
+ entityName;
6
+ storageApi;
7
+ constructor(entityName, storageApi) {
8
+ this.entityName = entityName;
9
+ this.storageApi = storageApi;
10
+ }
11
+ index(name, indexOptions) {
12
+ return new KvsEntityQueryBuilder(this.storageApi, {
13
+ entityName: this.entityName,
14
+ indexName: name,
15
+ partition: indexOptions?.partition,
16
+ filters: []
17
+ });
18
+ }
19
+ }
20
+ exports.KvsIndexQueryBuilder = KvsIndexQueryBuilder;
21
+ class KvsEntityQueryBuilder {
22
+ storageApi;
23
+ queryOptions;
24
+ constructor(storageApi, queryOptions) {
25
+ this.storageApi = storageApi;
26
+ this.queryOptions = queryOptions;
27
+ }
28
+ where(condition) {
29
+ this.queryOptions.range = condition;
30
+ return this;
31
+ }
32
+ filters(filter) {
33
+ this.queryOptions.filters = filter.items;
34
+ if (filter instanceof AndFilterBuilder) {
35
+ this.queryOptions.filterOperator = 'and';
36
+ }
37
+ else {
38
+ this.queryOptions.filterOperator = 'or';
39
+ }
40
+ return this;
41
+ }
42
+ sort(sort) {
43
+ this.queryOptions.sort = sort;
44
+ return this;
45
+ }
46
+ cursor(cursor) {
47
+ this.queryOptions.cursor = cursor;
48
+ return this;
49
+ }
50
+ limit(limit) {
51
+ this.queryOptions.limit = limit;
52
+ return this;
53
+ }
54
+ async getOne() {
55
+ const { results } = await this.limit(1).getMany();
56
+ if (results && results.length > 0) {
57
+ return results[0];
58
+ }
59
+ return undefined;
60
+ }
61
+ async getMany() {
62
+ const { filters, filterOperator, ...rest } = this.queryOptions;
63
+ if (filters && filterOperator && filters.length > 0) {
64
+ return this.storageApi.queryEntity({
65
+ ...rest,
66
+ filters: {
67
+ [filterOperator]: filters
68
+ }
69
+ });
70
+ }
71
+ return this.storageApi.queryEntity(rest);
72
+ }
73
+ }
74
+ class BaseFilter {
75
+ items;
76
+ constructor(items = []) {
77
+ this.items = items;
78
+ }
79
+ }
80
+ class FilterBuilder {
81
+ and(field, condition) {
82
+ return new AndFilterBuilder().and(field, condition);
83
+ }
84
+ or(field, condition) {
85
+ return new OrFilterBuilder().or(field, condition);
86
+ }
87
+ }
88
+ exports.FilterBuilder = FilterBuilder;
89
+ class AndFilterBuilder extends BaseFilter {
90
+ and(field, condition) {
91
+ this.items.push({ property: field, ...condition });
92
+ return this;
93
+ }
94
+ }
95
+ class OrFilterBuilder extends BaseFilter {
96
+ or(field, condition) {
97
+ this.items.push({ property: field, ...condition });
98
+ return this;
99
+ }
100
+ }
@@ -0,0 +1,13 @@
1
+ import { IndexQueryBuilder } from './interfaces/entity-query';
2
+ import { KvsEntity } from './interfaces/kvs';
3
+ import { StorageApi } from './storage-api';
4
+ export declare class EntityImpl<T> implements KvsEntity<T> {
5
+ private readonly entityName;
6
+ private readonly storageApi;
7
+ constructor(entityName: string, storageApi: StorageApi);
8
+ get(key: string): Promise<T>;
9
+ set(key: string, value: T): Promise<void>;
10
+ delete(key: string): Promise<void>;
11
+ query(): IndexQueryBuilder<T>;
12
+ }
13
+ //# sourceMappingURL=entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU;IAGzC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAO5B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlC,KAAK,IAAI,iBAAiB,CAAC,CAAC,CAAC;CAG9B"}
package/out/entity.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityImpl = void 0;
4
+ const entity_query_1 = require("./entity-query");
5
+ class EntityImpl {
6
+ entityName;
7
+ storageApi;
8
+ constructor(entityName, storageApi) {
9
+ this.entityName = entityName;
10
+ this.storageApi = storageApi;
11
+ }
12
+ get(key) {
13
+ return this.storageApi.getEntity({
14
+ entityName: this.entityName,
15
+ key
16
+ });
17
+ }
18
+ set(key, value) {
19
+ return this.storageApi.setEntity({
20
+ entityName: this.entityName,
21
+ key,
22
+ value
23
+ });
24
+ }
25
+ delete(key) {
26
+ return this.storageApi.deleteEntity({
27
+ entityName: this.entityName,
28
+ key
29
+ });
30
+ }
31
+ query() {
32
+ return new entity_query_1.KvsIndexQueryBuilder(this.entityName, this.storageApi);
33
+ }
34
+ }
35
+ exports.EntityImpl = EntityImpl;
@@ -0,0 +1,21 @@
1
+ export interface ForgeError {
2
+ code: string;
3
+ message: string;
4
+ context?: Record<string, unknown>;
5
+ }
6
+ export interface APIErrorResponseDetails {
7
+ status: number;
8
+ statusText: string;
9
+ traceId?: string | null;
10
+ }
11
+ export declare class ForgeKvsError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ export declare class ForgeKvsAPIError extends ForgeKvsError {
15
+ responseDetails: APIErrorResponseDetails;
16
+ code: string;
17
+ message: string;
18
+ context: Record<string, unknown>;
19
+ constructor(responseDetails: APIErrorResponseDetails, forgeError: ForgeError);
20
+ }
21
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,eAAe,EAAE,uBAAuB,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErB,eAAe,EAAE,uBAAuB,EAAE,UAAU,EAAE,UAAU;CAU7E"}
package/out/errors.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForgeKvsAPIError = exports.ForgeKvsError = void 0;
4
+ class ForgeKvsError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'ForgeKvsError';
8
+ }
9
+ }
10
+ exports.ForgeKvsError = ForgeKvsError;
11
+ class ForgeKvsAPIError extends ForgeKvsError {
12
+ responseDetails;
13
+ code;
14
+ message;
15
+ context;
16
+ constructor(responseDetails, forgeError) {
17
+ super(forgeError.message);
18
+ const { status, statusText, traceId } = responseDetails;
19
+ this.responseDetails = { status, statusText, traceId };
20
+ const { code, message, context, ...bodyData } = forgeError;
21
+ this.code = code;
22
+ this.message = message;
23
+ this.context = { ...context, ...bodyData };
24
+ }
25
+ }
26
+ exports.ForgeKvsAPIError = ForgeKvsAPIError;
package/out/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { KvsImpl } from './kvs';
2
+ declare const kvs: KvsImpl;
3
+ export * from './interfaces/types';
4
+ export * from './errors';
5
+ export { WhereConditions, FilterConditions } from './conditions';
6
+ export { FilterBuilder as Filter } from './entity-query';
7
+ export { kvs };
8
+ export default kvs;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAqChC,QAAA,MAAM,GAAG,SAA0B,CAAC;AAEpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,CAAC;AACf,eAAe,GAAG,CAAC"}
package/out/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kvs = exports.Filter = exports.FilterConditions = exports.WhereConditions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_1 = require("@forge/api");
6
+ const kvs_1 = require("./kvs");
7
+ const storage_api_1 = require("./storage-api");
8
+ function getFetchClient() {
9
+ const { kvs } = (0, api_1.__getRuntime)();
10
+ if (kvs?.url && kvs?.host) {
11
+ const { proxy, kvs, tracing } = (0, api_1.__getRuntime)();
12
+ return async function (path, options) {
13
+ return await global.__forge_fetch__({ type: 'kvs' }, path, {
14
+ ...options,
15
+ headers: {
16
+ ...options?.headers,
17
+ Authorization: `Bearer ${proxy.token}`,
18
+ Host: kvs?.host,
19
+ 'x-b3-traceid': tracing.traceId,
20
+ 'x-b3-spanid': tracing.spanId
21
+ }
22
+ });
23
+ };
24
+ }
25
+ return async function (path, options) {
26
+ return await global.__forge_fetch__({
27
+ type: 'kvs',
28
+ provider: 'app',
29
+ remote: 'kvs'
30
+ }, path, options);
31
+ };
32
+ }
33
+ const storageApi = new storage_api_1.StorageApi(getFetchClient());
34
+ const kvs = new kvs_1.KvsImpl(storageApi);
35
+ exports.kvs = kvs;
36
+ tslib_1.__exportStar(require("./interfaces/types"), exports);
37
+ tslib_1.__exportStar(require("./errors"), exports);
38
+ var conditions_1 = require("./conditions");
39
+ Object.defineProperty(exports, "WhereConditions", { enumerable: true, get: function () { return conditions_1.WhereConditions; } });
40
+ Object.defineProperty(exports, "FilterConditions", { enumerable: true, get: function () { return conditions_1.FilterConditions; } });
41
+ var entity_query_1 = require("./entity-query");
42
+ Object.defineProperty(exports, "Filter", { enumerable: true, get: function () { return entity_query_1.FilterBuilder; } });
43
+ exports.default = kvs;
@@ -0,0 +1,41 @@
1
+ import { BeginsWithClause, BetweenClause, ContainsClause, EqualToClause, ExistsClause, FilterOperator, GreaterThanClause, GreaterThanEqualToClause, LessThanClause, LessThanEqualToClause, ListResult, NotContainsClause, NotEqualToClause, NotExistsClause, Result, Sort, StringOrNumber } from './types';
2
+ export declare type IndexOptions<T> = Pick<EntityQueryOptions<T>, 'partition'>;
3
+ export interface IndexQueryBuilder<T> {
4
+ index(name: string, indexOptions?: IndexOptions<T>): EntityQueryBuilder<T>;
5
+ }
6
+ export interface EntityQueryBuilder<T> {
7
+ where(condition: EntityWhereClauses): this;
8
+ filters(filters: AndFilter<T> | OrFilter<T>): this;
9
+ sort(sort: Sort): this;
10
+ cursor(cursor: string): this;
11
+ limit(limit: number): this;
12
+ getOne(): Promise<Result<T> | undefined>;
13
+ getMany(): Promise<ListResult<T>>;
14
+ }
15
+ export declare type FilterItem<T> = EntityFilterClauses & {
16
+ property: keyof T;
17
+ };
18
+ export interface Filter<T> {
19
+ and(field: keyof T, condition: EntityFilterClauses): AndFilter<T>;
20
+ or(field: keyof T, condition: EntityFilterClauses): OrFilter<T>;
21
+ }
22
+ export interface AndFilter<T> {
23
+ and(field: keyof T, condition: EntityFilterClauses): this;
24
+ }
25
+ export interface OrFilter<T> {
26
+ or(field: keyof T, condition: EntityFilterClauses): this;
27
+ }
28
+ export declare type EntityFilterClauses = BetweenClause<StringOrNumber> | BeginsWithClause | ExistsClause | NotExistsClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause | ContainsClause | NotContainsClause | EqualToClause | NotEqualToClause;
29
+ export declare type EntityWhereClauses = BetweenClause<StringOrNumber> | BeginsWithClause | EqualToClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause;
30
+ export interface EntityQueryOptions<T> {
31
+ sort?: Sort;
32
+ entityName: string;
33
+ indexName: string;
34
+ partition?: Array<unknown>;
35
+ range?: EntityWhereClauses;
36
+ filters?: Array<FilterItem<T>>;
37
+ filterOperator?: FilterOperator;
38
+ cursor?: string;
39
+ limit?: number;
40
+ }
41
+ //# sourceMappingURL=entity-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-query.d.ts","sourceRoot":"","sources":["../../src/interfaces/entity-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,IAAI,EACJ,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,oBAAY,YAAY,CAAC,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC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,CAAC;IACzB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAC1D;AAED,oBAAY,mBAAmB,GAC3B,aAAa,CAAC,cAAc,CAAC,GAC7B,gBAAgB,GAChB,YAAY,GACZ,eAAe,GACf,iBAAiB,GACjB,wBAAwB,GACxB,cAAc,GACd,qBAAqB,GACrB,cAAc,GACd,iBAAiB,GACjB,aAAa,GACb,gBAAgB,CAAC;AAErB,oBAAY,kBAAkB,GAC1B,aAAa,CAAC,cAAc,CAAC,GAC7B,gBAAgB,GAChB,aAAa,GACb,iBAAiB,GACjB,wBAAwB,GACxB,cAAc,GACd,qBAAqB,CAAC;AAE1B,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ declare type KeySchema = {
2
+ key: string;
3
+ };
4
+ declare type KeyValueSchema<T> = KeySchema & {
5
+ value: T;
6
+ };
7
+ export declare type GetRequest = KeySchema;
8
+ export declare type GetResponse<T> = KeyValueSchema<T>;
9
+ export declare type SetRequest<T> = KeyValueSchema<T>;
10
+ export declare type SetResponse = void;
11
+ export declare type DeleteRequest = KeySchema;
12
+ export declare type DeleteResponse = void;
13
+ declare type QueryWhere = {
14
+ condition: 'BEGINS_WITH';
15
+ property: 'key';
16
+ values: Array<unknown>;
17
+ };
18
+ export declare type QueryRequest = {
19
+ limit?: number;
20
+ after?: string;
21
+ where?: Array<QueryWhere>;
22
+ };
23
+ export declare type QueryResponse<T> = {
24
+ data: Array<KeyValueSchema<T>>;
25
+ cursor?: string;
26
+ };
27
+ export declare type SecretGetRequest = KeySchema;
28
+ export declare type SecretGetResponse<T> = KeyValueSchema<T>;
29
+ export declare type SecretSetRequest<T> = KeyValueSchema<T>;
30
+ export declare type SecretSetResponse = void;
31
+ export declare type SecretDeleteRequest = KeySchema;
32
+ export declare type SecretDeleteResponse = void;
33
+ declare type EntityKeySchema = {
34
+ entityName: string;
35
+ key: string;
36
+ };
37
+ declare type EntityKeyValueSchema<T> = EntityKeySchema & {
38
+ value: T;
39
+ };
40
+ export declare type EntityGetRequest = EntityKeySchema;
41
+ export declare type EntityGetResponse<T> = EntityKeyValueSchema<T>;
42
+ export declare type EntitySetRequest<T> = EntityKeyValueSchema<T>;
43
+ export declare type EntitySetResponse = void;
44
+ export declare type EntityDeleteRequest = EntityKeySchema;
45
+ export declare type EntityDeleteResponse = void;
46
+ declare type EntityQueryFilter = {
47
+ condition: 'BEGINS_WITH' | 'BETWEEN' | 'CONTAINS' | 'EQUAL_TO' | 'EXISTS' | 'GREATER_THAN' | 'GREATER_THAN_EQUAL_TO' | 'LESS_THAN' | 'LESS_THAN_EQUAL_TO' | 'NOT_CONTAINS' | 'NOT_EQUAL_TO' | 'NOT_EXISTS';
48
+ property: string;
49
+ values: Array<unknown>;
50
+ };
51
+ export declare type EntityQueryRequest = {
52
+ limit?: number;
53
+ cursor?: string;
54
+ range?: {
55
+ condition: 'BEGINS_WITH' | 'BETWEEN' | 'EQUAL_TO' | 'GREATER_THAN' | 'GREATER_THAN_EQUAL_TO' | 'LESS_THAN' | 'LESS_THAN_EQUAL_TO';
56
+ values: Array<unknown>;
57
+ };
58
+ filters?: {
59
+ or?: Array<EntityQueryFilter>;
60
+ and?: Array<EntityQueryFilter>;
61
+ };
62
+ sort?: 'ASC' | 'DESC';
63
+ partition?: Array<unknown>;
64
+ entityName: string;
65
+ indexName: string;
66
+ };
67
+ export declare type EntityQueryResponse<T> = {
68
+ data: Array<KeyValueSchema<T>>;
69
+ cursor?: string;
70
+ };
71
+ export {};
72
+ //# sourceMappingURL=kvs-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs-api.d.ts","sourceRoot":"","sources":["../../src/interfaces/kvs-api.ts"],"names":[],"mappings":"AAAA,aAAK,SAAS,GAAG;IACf,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,aAAK,cAAc,CAAC,CAAC,IAAI,SAAS,GAAG;IACnC,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,oBAAY,UAAU,GAAG,SAAS,CAAC;AACnC,oBAAY,WAAW,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAE/C,oBAAY,UAAU,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAC9C,oBAAY,WAAW,GAAG,IAAI,CAAC;AAE/B,oBAAY,aAAa,GAAG,SAAS,CAAC;AACtC,oBAAY,cAAc,GAAG,IAAI,CAAC;AAElC,aAAK,UAAU,GAAG;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CACxB,CAAC;AACF,oBAAY,YAAY,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC3B,CAAC;AACF,oBAAY,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAGF,oBA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AAc,GACd,uBAAuB,GACvB,WAAW,GACX,oBAAoB,CAAC;QACzB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;KACxB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,EAAE,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC9B,GAAG,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;KAChC,CAAC;IACF,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,oBAAY,mBAAmB,CAAC,CAAC,IAAI;IACnC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { IndexQueryBuilder } from './entity-query';
2
+ import { QueryBuilder } from './query';
3
+ export interface Kvs {
4
+ get<T>(key: string): Promise<T>;
5
+ set<T>(key: string, value: T): Promise<void>;
6
+ delete(key: string): Promise<void>;
7
+ query(): QueryBuilder;
8
+ getSecret<T>(key: string): Promise<T>;
9
+ setSecret<T>(key: string, value: T): Promise<void>;
10
+ deleteSecret(key: string): Promise<void>;
11
+ entity<T>(entityName: string): KvsEntity<T>;
12
+ }
13
+ export interface KvsEntity<T> {
14
+ get(key: string): Promise<T>;
15
+ set(key: string, value: T): Promise<void>;
16
+ delete(key: string): Promise<void>;
17
+ query(): IndexQueryBuilder<T>;
18
+ }
19
+ //# sourceMappingURL=kvs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs.d.ts","sourceRoot":"","sources":["../../src/interfaces/kvs.ts"],"names":[],"mappings":"AAAA,OAAO,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declare type WhereClause = BeginsWithClause;
3
+ export interface QueryBuilder {
4
+ where(property: 'key', condition: WhereClause): QueryBuilder;
5
+ cursor(cursor: string): QueryBuilder;
6
+ limit(limit: number): QueryBuilder;
7
+ getMany<T>(): Promise<ListResult<T>>;
8
+ getOne<T>(): Promise<Result<T> | undefined>;
9
+ }
10
+ export interface QueryOptions {
11
+ where?: Array<{
12
+ property: 'key';
13
+ } & WhereClause>;
14
+ cursor?: string;
15
+ limit?: number;
16
+ }
17
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/interfaces/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE/D,oBAAY,WAAW,GAAG,gBAAgB,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,YAAY,CAAC;IAC7D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IACrC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAA;KAAE,GAAG,WAAW,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,64 @@
1
+ export interface Result<T> {
2
+ key: string;
3
+ value: T;
4
+ }
5
+ export interface ListResult<T> {
6
+ results: Result<T>[];
7
+ nextCursor?: string;
8
+ }
9
+ export declare enum Sort {
10
+ ASC = "ASC",
11
+ DESC = "DESC"
12
+ }
13
+ export declare type StringOrNumberOrBoolean = string | number | boolean;
14
+ export declare type StringOrNumber = string | number;
15
+ export interface BetweenClause<T extends StringOrNumber> {
16
+ condition: 'BETWEEN';
17
+ values: [T, T];
18
+ }
19
+ export interface BeginsWithClause {
20
+ condition: 'BEGINS_WITH';
21
+ values: [StringOrNumber];
22
+ }
23
+ export interface ExistsClause {
24
+ condition: 'EXISTS';
25
+ values: [true];
26
+ }
27
+ export interface NotExistsClause {
28
+ condition: 'NOT_EXISTS';
29
+ values: [true];
30
+ }
31
+ export interface GreaterThanClause {
32
+ condition: 'GREATER_THAN';
33
+ values: [StringOrNumber];
34
+ }
35
+ export interface GreaterThanEqualToClause {
36
+ condition: 'GREATER_THAN_EQUAL_TO';
37
+ values: [StringOrNumber];
38
+ }
39
+ export interface LessThanClause {
40
+ condition: 'LESS_THAN';
41
+ values: [StringOrNumber];
42
+ }
43
+ export interface LessThanEqualToClause {
44
+ condition: 'LESS_THAN_EQUAL_TO';
45
+ values: [StringOrNumber];
46
+ }
47
+ export interface ContainsClause {
48
+ condition: 'CONTAINS';
49
+ values: [string];
50
+ }
51
+ export interface NotContainsClause {
52
+ condition: 'NOT_CONTAINS';
53
+ values: [string];
54
+ }
55
+ export interface EqualToClause {
56
+ condition: 'EQUAL_TO';
57
+ values: [StringOrNumberOrBoolean];
58
+ }
59
+ export interface NotEqualToClause {
60
+ condition: 'NOT_EQUAL_TO';
61
+ values: [StringOrNumberOrBoolean];
62
+ }
63
+ export declare type FilterOperator = 'or' | 'and';
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/interfaces/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM,CAAC,CA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CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,CAAC,uBAAuB,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,CAAC,uBAAuB,CAAC,CAAC;CACnC;AAED,oBAAY,cAAc,GAAG,IAAI,GAAG,KAAK,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sort = void 0;
4
+ var Sort;
5
+ (function (Sort) {
6
+ Sort["ASC"] = "ASC";
7
+ Sort["DESC"] = "DESC";
8
+ })(Sort = exports.Sort || (exports.Sort = {}));
package/out/kvs.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { KvsEntity, Kvs } from './interfaces/kvs';
2
+ import { QueryBuilder } from './interfaces/query';
3
+ import { StorageApi } from './storage-api';
4
+ export declare class KvsImpl implements Kvs {
5
+ private readonly storageApi;
6
+ constructor(storageApi: StorageApi);
7
+ get<T>(key: string): Promise<T>;
8
+ set<T>(key: string, value: T): Promise<void>;
9
+ delete(key: string): Promise<void>;
10
+ query(): QueryBuilder;
11
+ getSecret<T>(key: string): Promise<T>;
12
+ setSecret<T>(key: string, value: T): Promise<void>;
13
+ deleteSecret(key: string): Promise<void>;
14
+ entity<T>(entityName: string): KvsEntity<T>;
15
+ }
16
+ //# sourceMappingURL=kvs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs.d.ts","sourceRoot":"","sources":["../src/kvs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,OAAQ,YAAW,GAAG;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAEnD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,YAAY;IAIrB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAG5C"}
package/out/kvs.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KvsImpl = void 0;
4
+ const entity_1 = require("./entity");
5
+ const query_1 = require("./query");
6
+ class KvsImpl {
7
+ storageApi;
8
+ constructor(storageApi) {
9
+ this.storageApi = storageApi;
10
+ }
11
+ get(key) {
12
+ return this.storageApi.get({ key });
13
+ }
14
+ set(key, value) {
15
+ return this.storageApi.set({ key, value });
16
+ }
17
+ delete(key) {
18
+ return this.storageApi.delete({ key });
19
+ }
20
+ query() {
21
+ return new query_1.KvsQueryBuilder(this.storageApi);
22
+ }
23
+ getSecret(key) {
24
+ return this.storageApi.getSecret({ key });
25
+ }
26
+ setSecret(key, value) {
27
+ return this.storageApi.setSecret({ key, value });
28
+ }
29
+ deleteSecret(key) {
30
+ return this.storageApi.deleteSecret({ key });
31
+ }
32
+ entity(entityName) {
33
+ return new entity_1.EntityImpl(entityName, this.storageApi);
34
+ }
35
+ }
36
+ exports.KvsImpl = KvsImpl;
package/out/query.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { QueryBuilder, QueryOptions, WhereClause } from './interfaces/query';
2
+ import { ListResult, Result } from './interfaces/types';
3
+ import { StorageApi } from './storage-api';
4
+ export declare class KvsQueryBuilder implements QueryBuilder {
5
+ private storageApi;
6
+ private options;
7
+ constructor(storageApi: StorageApi, options?: QueryOptions);
8
+ where(property: 'key', condition: WhereClause): this;
9
+ cursor(cursor: string): this;
10
+ limit(limit: number): this;
11
+ getOne<T>(): Promise<Result<T> | undefined>;
12
+ getMany<T>(): Promise<ListResult<T>>;
13
+ }
14
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,eAAgB,YAAW,YAAY;IAEhD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,OAAO;gBADP,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,YAAiB;IAGpC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI;IAKpD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKpB,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAQjD,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CAOrC"}
package/out/query.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KvsQueryBuilder = void 0;
4
+ class KvsQueryBuilder {
5
+ storageApi;
6
+ options;
7
+ constructor(storageApi, options = {}) {
8
+ this.storageApi = storageApi;
9
+ this.options = options;
10
+ }
11
+ where(property, condition) {
12
+ this.options.where = [{ property, ...condition }];
13
+ return this;
14
+ }
15
+ cursor(cursor) {
16
+ this.options.cursor = cursor;
17
+ return this;
18
+ }
19
+ limit(limit) {
20
+ this.options.limit = limit;
21
+ return this;
22
+ }
23
+ async getOne() {
24
+ const { results } = await this.limit(1).getMany();
25
+ if (results && results.length > 0) {
26
+ return results[0];
27
+ }
28
+ return undefined;
29
+ }
30
+ getMany() {
31
+ return this.storageApi.query({
32
+ limit: this.options.limit,
33
+ after: this.options.cursor,
34
+ where: this.options.where
35
+ });
36
+ }
37
+ }
38
+ exports.KvsQueryBuilder = KvsQueryBuilder;