mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Add "reply" middleware, tighten up some any types
This commit is contained in:
Vendored
+13
-7
@@ -125,8 +125,9 @@ declare namespace middleware {
|
||||
doc: DocContext; // Deprecated, use 'readSnapshots' instead.
|
||||
op: OpContext;
|
||||
query: QueryContext;
|
||||
receive: ReceiveContext;
|
||||
readSnapshots: ReadSnapshotsContext;
|
||||
receive: ReceiveContext;
|
||||
reply: ReplyContext;
|
||||
submit: SubmitContext;
|
||||
}
|
||||
|
||||
@@ -165,22 +166,27 @@ declare namespace middleware {
|
||||
projection: Projection | undefined;
|
||||
fields: ProjectionFields | undefined;
|
||||
channel: string;
|
||||
query: any;
|
||||
options: any;
|
||||
query: ShareDB.JSONObject;
|
||||
options: ShareDB.JSONObject;
|
||||
db: sharedb.DB | null;
|
||||
snapshotProjection: Projection | null;
|
||||
}
|
||||
|
||||
interface ReceiveContext extends BaseContext {
|
||||
data: any;
|
||||
}
|
||||
|
||||
interface ReadSnapshotsContext extends BaseContext {
|
||||
collection: string;
|
||||
snapshots: ShareDB.Snapshot[];
|
||||
snapshotType: SnapshotType;
|
||||
}
|
||||
|
||||
interface ReceiveContext extends BaseContext {
|
||||
data: ShareDB.JSONObject; // ClientRequest, but before any validation
|
||||
}
|
||||
|
||||
interface ReplyContext extends BaseContext {
|
||||
request: ShareDB.ClientRequest;
|
||||
reply: ShareDB.JSONObject;
|
||||
}
|
||||
|
||||
type SnapshotType = 'current' | 'byVersion' | 'byTimestamp';
|
||||
|
||||
interface SubmitContext extends BaseContext, SubmitRequest {
|
||||
|
||||
Vendored
+18
-2
@@ -1,18 +1,25 @@
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
export type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
|
||||
export interface JSONObject {
|
||||
[name: string]: JSONValue;
|
||||
}
|
||||
export interface JSONArray extends Array<JSONValue> {}
|
||||
|
||||
export type Path = ReadonlyArray<string|number>;
|
||||
export interface Snapshot {
|
||||
id: string;
|
||||
v: number;
|
||||
type: string | null;
|
||||
data: any; // JSON object, could be undefined
|
||||
data: JSONObject | undefined;
|
||||
m: SnapshotMeta | null;
|
||||
}
|
||||
|
||||
export interface SnapshotMeta {
|
||||
ctime: number;
|
||||
mtime: number;
|
||||
[key: string]: any;
|
||||
// Users can use server middleware to add additional metadata to snapshots.
|
||||
[key: string]: JSONValue;
|
||||
}
|
||||
|
||||
export interface AddNumOp { p: Path; na: number; }
|
||||
@@ -95,3 +102,12 @@ export class Query extends EventEmitter {
|
||||
removeListener(event: QueryEvent, listener: (...args: any[]) => any): this;
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
export type RequestAction = 'qf' | 'qs' | 'qu' | 'bf' | 'bs' | 'bu' | 'f' | 's' | 'u' | 'op' | 'nf' | 'nt';
|
||||
|
||||
export interface ClientRequest {
|
||||
/** Short name of the request's action */
|
||||
a: RequestAction;
|
||||
|
||||
[propertyName: string]: JSONValue;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,16 @@ backend.use('receive', (context, callback) => {
|
||||
);
|
||||
callback();
|
||||
});
|
||||
backend.use('reply', (context, callback) => {
|
||||
console.log(
|
||||
context.action,
|
||||
context.agent,
|
||||
context.backend,
|
||||
context.request,
|
||||
context.reply,
|
||||
);
|
||||
callback();
|
||||
});
|
||||
backend.use('readSnapshots', (context, callback) => {
|
||||
console.log(
|
||||
context.action,
|
||||
|
||||
Reference in New Issue
Block a user