harperdb 4.3.18 → 4.3.20

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  export declare class IterableEventQueue extends EventEmitter {
4
3
  resolveNext: Function;
@@ -1,4 +1,4 @@
1
- import { ResourceInterface, Request, SubscriptionRequest, Id, Context, Query } from './ResourceInterface';
1
+ import { ResourceInterface, SubscriptionRequest, Id, Context, Query } from './ResourceInterface';
2
2
  import { Transaction } from './DatabaseTransaction';
3
3
  export declare const CONTEXT: unique symbol;
4
4
  export declare const ID_PROPERTY: unique symbol;
@@ -20,12 +20,12 @@ export declare class Resource implements ResourceInterface {
20
20
  static transactions: Transaction[] & {
21
21
  timestamp: number;
22
22
  };
23
+ [CONTEXT]: Context;
23
24
  constructor(identifier: Id, source: any);
24
25
  /**
25
26
  * The get methods are for directly getting a resource, and called for HTTP GET requests.
26
27
  */
27
- static get(identifier: Id, context?: Context): Promise<object>;
28
- static get(request: Request, context?: Context): Promise<object>;
28
+ static get(identifier: Id, context?: Context): Promise<Resource>;
29
29
  static get(query: Query, context?: Context): Promise<AsyncIterable<object>>;
30
30
  static get: typeof Resource.get;
31
31
  get?(query?: any): Promise<any>;
@@ -33,15 +33,15 @@ export declare class Resource implements ResourceInterface {
33
33
  * Store the provided record by the provided id. If no id is provided, it is auto-generated.
34
34
  */
35
35
  static put: {
36
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
36
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
37
37
  reliesOnPrototype: boolean;
38
38
  };
39
39
  static patch: {
40
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
40
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
41
41
  reliesOnPrototype: boolean;
42
42
  };
43
43
  static delete(identifier: Id, context?: Context): Promise<boolean>;
44
- static delete(request: Request, context?: Context): Promise<object>;
44
+ static delete(request: Context, context?: Context): Promise<object>;
45
45
  static delete: typeof Resource.delete;
46
46
  /**
47
47
  * Generate a new primary key for a resource; by default we use UUIDs (for now).
@@ -50,15 +50,15 @@ export declare class Resource implements ResourceInterface {
50
50
  static create(id_prefix: Id, record: any, context: Context): Promise<Id>;
51
51
  static create(record: any, context: Context): Promise<Id>;
52
52
  static invalidate: {
53
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
53
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
54
54
  reliesOnPrototype: boolean;
55
55
  };
56
56
  static post: {
57
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
57
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
58
58
  reliesOnPrototype: boolean;
59
59
  };
60
60
  static connect: {
61
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
61
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
62
62
  reliesOnPrototype: boolean;
63
63
  };
64
64
  static subscribe(request: SubscriptionRequest): Promise<AsyncIterable<{
@@ -68,23 +68,23 @@ export declare class Resource implements ResourceInterface {
68
68
  }>>;
69
69
  static subscribe: typeof Resource.subscribe;
70
70
  static publish: {
71
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
71
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
72
72
  reliesOnPrototype: boolean;
73
73
  };
74
74
  static search: {
75
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
75
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
76
76
  reliesOnPrototype: boolean;
77
77
  };
78
78
  static query: {
79
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
79
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
80
80
  reliesOnPrototype: boolean;
81
81
  };
82
82
  static copy: {
83
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
83
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
84
84
  reliesOnPrototype: boolean;
85
85
  };
86
86
  static move: {
87
- (id_or_query: Id, data_or_context?: any, context?: Context): any;
87
+ (id_or_query: string | Id, data_or_context?: any, context?: Context): any;
88
88
  reliesOnPrototype: boolean;
89
89
  };
90
90
  post(new_record: any): any;
@@ -99,7 +99,7 @@ export declare class Resource implements ResourceInterface {
99
99
  * @param options
100
100
  * @returns
101
101
  */
102
- static getResource(id: Id, request: Request, options?: any): Resource | Promise<Resource>;
102
+ static getResource(id: Id, request: Context, options?: any): Resource | Promise<Resource>;
103
103
  /**
104
104
  * This is called by protocols that wish to make a subscription for real-time notification/updates.
105
105
  * This default implementation simply provides a streaming iterator that does not deliver any notifications
@@ -126,7 +126,7 @@ export declare class Resource implements ResourceInterface {
126
126
  * Get the context for this resource
127
127
  * @returns context object with information about the current transaction, user, and more
128
128
  */
129
- getContext(): any;
129
+ getContext(): Context;
130
130
  }
131
131
  export declare function snake_case(camelCase: string): string;
132
132
  export declare function transformForSelect(select: any, resource: any): (object: any) => any;
@@ -14,28 +14,71 @@ export interface ResourceInterface<Key = any, Record = any> {
14
14
  allowDelete(user: any, query: Query, context: Context): boolean | Promise<boolean>;
15
15
  }
16
16
  export interface Context {
17
+ /** The user making the request */
17
18
  user?: any;
19
+ /** The database transaction object */
18
20
  transaction: DatabaseTransaction;
19
- responseData: {
20
- lastModified: number;
21
- };
21
+ /** If the operation that will be performed with this context should check user authorization */
22
+ authorize?: number;
23
+ /** The last modification time of any data that has been accessed with this context */
24
+ lastModified?: number;
25
+ /** The time at which a saved record should expire */
26
+ expiresAt?: number;
27
+ /** Indicates that caching should not be applied */
28
+ noCache?: boolean;
29
+ /** Indicates that values from the source data should be stored as a cached value */
30
+ noCacheStore?: boolean;
31
+ /** Only return values from the table, and don't use data from the source */
32
+ onlyIfCached?: boolean;
33
+ /** Allows data from a caching table to be used if there is an error retrieving data from the source */
34
+ staleIfError?: boolean;
35
+ /** Indicates any cached data must be revalidated */
36
+ mustRevalidate?: boolean;
22
37
  }
23
- export interface Request {
24
- id?: Id;
25
- path?: string;
26
- user?: any;
27
- data?: any;
28
- select?: string[];
29
- context?: Context;
38
+ interface DirectCondition {
39
+ attribute: string;
40
+ comparator?: string;
41
+ value: any;
42
+ }
43
+ interface ConditionGroup {
44
+ conditions: Condition[];
45
+ operator?: string;
46
+ }
47
+ type Condition = DirectCondition | ConditionGroup;
48
+ interface Sort {
49
+ attribute: string;
50
+ descending?: boolean;
51
+ next?: Sort;
52
+ }
53
+ interface SubSelect {
54
+ name: string;
55
+ select: (string | SubSelect)[];
30
56
  }
31
- export interface Query extends Request {
32
- conditions?: any[];
57
+ export interface Query {
58
+ /** The conditions to use in the query, that the returned records must satisfy */
59
+ conditions?: Condition[];
60
+ /** The number of records to return */
33
61
  limit?: number;
62
+ /** The number of records to skip */
34
63
  offset?: number;
64
+ /** The number of operator to use*/
65
+ operator?: 'AND' | 'OR';
66
+ /** The sort attribute and direction to use */
67
+ sort?: Sort;
68
+ /** The selected attributes to return */
69
+ select?: (string | SubSelect)[];
70
+ /** Return an explanation of the query order */
71
+ explain?: boolean;
72
+ /** Force the query to be executed in the order of conditions */
73
+ enforceExecutionOrder?: boolean;
35
74
  }
36
- export interface SubscriptionRequest extends Request {
75
+ export interface SubscriptionRequest {
76
+ /** The starting time of events to return (defaults to now) */
37
77
  startTime?: number;
78
+ /** The count of previously recorded events to return */
38
79
  previousCount?: number;
80
+ /** If the current record state should be omitted as the first event */
81
+ omitCurrent?: boolean;
39
82
  }
40
83
  export type Id = number | string | (number | string | null)[] | null;
41
84
  type UpdatableRecord<T> = T;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export declare const transactionKeyEncoder: {
3
2
  writeKey(key: any, buffer: any, position: any): any;
4
3
  readKey(buffer: any, start: any, end: any): any;
@@ -0,0 +1,7 @@
1
+ import { Request } from './ResourceInterface';
2
+ export declare function transaction<T>(context: Request, callback: (transaction: TransactionSet) => T, options?: any): T;
3
+ export declare function transaction<T>(callback: (transaction: TransactionSet) => T): T;
4
+ export declare namespace transaction {
5
+ var commit: (context_source: any) => any;
6
+ var abort: (context_source: any) => any;
7
+ }
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Socket } from 'net';
4
2
  /**
5
3
  * This is the central interface by which we define entry points for different server protocol plugins to listen for