@antelopejs/interface-database 0.1.6 → 0.1.7
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/dist/antelope.test.js +1 -1
- package/dist/atomic.d.ts +3 -37
- package/dist/atomic.js +39 -121
- package/dist/atomic.js.map +1 -1
- package/dist/common.d.ts +1 -58
- package/dist/common.js +15 -41
- package/dist/common.js.map +1 -1
- package/dist/datum.d.ts +1 -55
- package/dist/datum.js +2 -66
- package/dist/datum.js.map +1 -1
- package/dist/query.d.ts +11 -12
- package/dist/query.js +24 -22
- package/dist/query.js.map +1 -1
- package/dist/schema.d.ts +3 -120
- package/dist/schema.js +7 -88
- package/dist/schema.js.map +1 -1
- package/dist/selection.d.ts +1 -104
- package/dist/selection.js +5 -123
- package/dist/selection.js.map +1 -1
- package/dist/staged-query/atomic.d.ts +34 -0
- package/dist/staged-query/atomic.js +108 -0
- package/dist/staged-query/atomic.js.map +1 -0
- package/dist/staged-query/common.d.ts +58 -0
- package/dist/staged-query/common.js +45 -0
- package/dist/staged-query/common.js.map +1 -0
- package/dist/staged-query/datum.d.ts +55 -0
- package/dist/staged-query/datum.js +70 -0
- package/dist/staged-query/datum.js.map +1 -0
- package/dist/staged-query/index.d.ts +8 -0
- package/dist/staged-query/index.js +36 -0
- package/dist/staged-query/index.js.map +1 -0
- package/dist/staged-query/query.d.ts +3 -0
- package/dist/staged-query/query.js +9 -0
- package/dist/staged-query/query.js.map +1 -0
- package/dist/staged-query/schema.d.ts +122 -0
- package/dist/staged-query/schema.js +95 -0
- package/dist/staged-query/schema.js.map +1 -0
- package/dist/staged-query/selection.d.ts +104 -0
- package/dist/staged-query/selection.js +126 -0
- package/dist/staged-query/selection.js.map +1 -0
- package/dist/staged-query/stream.d.ts +185 -0
- package/dist/staged-query/stream.js +221 -0
- package/dist/staged-query/stream.js.map +1 -0
- package/dist/staged-query/valueproxy.d.ts +415 -0
- package/dist/staged-query/valueproxy.js +562 -0
- package/dist/staged-query/valueproxy.js.map +1 -0
- package/dist/stream.d.ts +1 -185
- package/dist/stream.js +2 -217
- package/dist/stream.js.map +1 -1
- package/dist/valueproxy.d.ts +1 -415
- package/dist/valueproxy.js +15 -559
- package/dist/valueproxy.js.map +1 -1
- package/package.json +9 -1
package/dist/antelope.test.js
CHANGED
package/dist/atomic.d.ts
CHANGED
|
@@ -1,41 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { QueryStage } from "./common";
|
|
3
|
-
/** Matches an absent revision field on an existing record, not stored null. */
|
|
4
|
-
export interface MissingRevision {
|
|
5
|
-
kind: "missing";
|
|
6
|
-
}
|
|
7
|
-
export interface AtomicCondition<T> {
|
|
8
|
-
revisionField: keyof T & string;
|
|
9
|
-
expectedRevision: string | MissingRevision;
|
|
10
|
-
}
|
|
11
|
-
/** Replaces supplied top-level fields and atomically installs a fresh revision. */
|
|
12
|
-
export interface AtomicUpdate<T> extends AtomicCondition<T> {
|
|
13
|
-
type: "update";
|
|
14
|
-
nextRevision: string;
|
|
15
|
-
patch: Partial<T>;
|
|
16
|
-
}
|
|
17
|
-
export interface AtomicDelete<T> extends AtomicCondition<T> {
|
|
18
|
-
type: "delete";
|
|
19
|
-
}
|
|
20
|
-
export type AtomicEqualityValue = string | number | boolean | Date;
|
|
21
|
-
/** Deletes by one observed scalar value; does not provide revision or ABA protection. */
|
|
22
|
-
export interface AtomicDeleteIfEqual<T> {
|
|
23
|
-
type: "deleteIfEqual";
|
|
24
|
-
field: keyof T & string;
|
|
25
|
-
expectedValue: AtomicEqualityValue;
|
|
26
|
-
}
|
|
27
|
-
export type AtomicMutation<T> = AtomicUpdate<T> | AtomicDelete<T> | AtomicDeleteIfEqual<T>;
|
|
28
|
-
export type AtomicMutationOutcome = "applied" | "not-applied" | "unknown";
|
|
1
|
+
import { AtomicMutationQuery as StagedAtomicMutationQuery } from "./staged-query/atomic";
|
|
29
2
|
/** Signals an adapter that does not implement the atomic mutation contract. */
|
|
30
3
|
export declare class AtomicMutationUnsupportedError extends Error {
|
|
31
4
|
constructor();
|
|
32
5
|
}
|
|
33
|
-
|
|
34
|
-
export
|
|
35
|
-
/** Rejects selections and cross-instance operations before adapter dispatch. */
|
|
36
|
-
export declare function ValidateAtomicMutationTable(stages: QueryStage[]): void;
|
|
37
|
-
/** Executes only the explicit atomic stage; invalid adapter results fail closed. */
|
|
38
|
-
export declare class AtomicMutationQuery extends Query<AtomicMutationOutcome> {
|
|
39
|
-
run(): Promise<AtomicMutationOutcome>;
|
|
40
|
-
cursor(): AsyncGenerator<AtomicMutationOutcome, void, unknown>;
|
|
41
|
-
}
|
|
6
|
+
export * from "./staged-query/atomic";
|
|
7
|
+
export { StagedAtomicMutationQuery as AtomicMutationQuery };
|
package/dist/atomic.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.AtomicMutationQuery = exports.AtomicMutationUnsupportedError = void 0;
|
|
4
|
-
exports.ValidateAtomicMutation = ValidateAtomicMutation;
|
|
5
|
-
exports.ValidateAtomicMutationTable = ValidateAtomicMutationTable;
|
|
6
18
|
const query_1 = require("./query");
|
|
19
|
+
const atomic_1 = require("./staged-query/atomic");
|
|
20
|
+
Object.defineProperty(exports, "AtomicMutationQuery", { enumerable: true, get: function () { return atomic_1.AtomicMutationQuery; } });
|
|
7
21
|
const outcomes = ["applied", "not-applied", "unknown"];
|
|
8
|
-
const tableStages = ["schema", "instance", "table"];
|
|
9
|
-
const identityFields = ["id", "_id"];
|
|
10
22
|
/** Signals an adapter that does not implement the atomic mutation contract. */
|
|
11
23
|
class AtomicMutationUnsupportedError extends Error {
|
|
12
24
|
constructor() {
|
|
@@ -15,121 +27,27 @@ class AtomicMutationUnsupportedError extends Error {
|
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
29
|
exports.AtomicMutationUnsupportedError = AtomicMutationUnsupportedError;
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (Array.isArray(value) && Object.keys(value).length !== value.length) {
|
|
42
|
-
throw new TypeError("Atomic mutation arrays must not contain holes");
|
|
43
|
-
}
|
|
44
|
-
ancestors.add(value);
|
|
45
|
-
for (const [field, child] of Object.entries(value)) {
|
|
46
|
-
validateField(field);
|
|
47
|
-
validateConstant(child, ancestors);
|
|
48
|
-
}
|
|
49
|
-
ancestors.delete(value);
|
|
50
|
-
}
|
|
51
|
-
/** Validates literal input; adapters must additionally supply scope fields. */
|
|
52
|
-
function ValidateAtomicMutation(key, request, protectedFields = []) {
|
|
53
|
-
if (!isToken(key) || !isRecord(request)) {
|
|
54
|
-
throw new TypeError("Atomic mutation requires one literal record identity");
|
|
55
|
-
}
|
|
56
|
-
const forbidden = [...identityFields, ...protectedFields];
|
|
57
|
-
if (request.type === "deleteIfEqual") {
|
|
58
|
-
validateEquality(request, forbidden);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
validateField(request.revisionField);
|
|
62
|
-
if (forbidden.includes(request.revisionField)) {
|
|
63
|
-
throw new TypeError("Atomic mutation revision cannot be an identity field");
|
|
64
|
-
}
|
|
65
|
-
const expected = request.expectedRevision;
|
|
66
|
-
const isMissing = isRecord(expected) &&
|
|
67
|
-
expected.kind === "missing" &&
|
|
68
|
-
Object.keys(expected).length === 1;
|
|
69
|
-
if (!isToken(expected) && !isMissing) {
|
|
70
|
-
throw new TypeError("Expected revision must be a token or missing tag");
|
|
71
|
-
}
|
|
72
|
-
if (request.type === "delete")
|
|
73
|
-
return;
|
|
74
|
-
if (request.type !== "update") {
|
|
75
|
-
throw new TypeError("Unknown atomic mutation operation");
|
|
76
|
-
}
|
|
77
|
-
validateUpdate(request, forbidden);
|
|
78
|
-
}
|
|
79
|
-
function validateEquality(request, forbidden) {
|
|
80
|
-
validateField(request.field);
|
|
81
|
-
if (forbidden.includes(request.field)) {
|
|
82
|
-
throw new TypeError("Atomic equality field cannot be an identity field");
|
|
83
|
-
}
|
|
84
|
-
const value = request.expectedValue;
|
|
85
|
-
if (!["string", "number", "boolean"].includes(typeof value) &&
|
|
86
|
-
!(value instanceof Date)) {
|
|
87
|
-
throw new TypeError("Atomic equality requires a scalar or Date");
|
|
88
|
-
}
|
|
89
|
-
validateConstant(value);
|
|
90
|
-
}
|
|
91
|
-
function validateUpdate(request, forbidden) {
|
|
92
|
-
if (!isToken(request.nextRevision) ||
|
|
93
|
-
request.nextRevision === request.expectedRevision) {
|
|
94
|
-
throw new TypeError("Atomic mutation requires a changed revision token");
|
|
95
|
-
}
|
|
96
|
-
if (!isRecord(request.patch)) {
|
|
97
|
-
throw new TypeError("Atomic mutation patch must be an object");
|
|
98
|
-
}
|
|
99
|
-
forbidden.push(request.revisionField);
|
|
100
|
-
if (Object.keys(request.patch).some((field) => forbidden.includes(field))) {
|
|
101
|
-
throw new TypeError("Atomic mutation patch cannot change identity or revision");
|
|
102
|
-
}
|
|
103
|
-
validateConstant(request.patch);
|
|
104
|
-
}
|
|
105
|
-
/** Rejects selections and cross-instance operations before adapter dispatch. */
|
|
106
|
-
function ValidateAtomicMutationTable(stages) {
|
|
107
|
-
if (stages.length !== tableStages.length ||
|
|
108
|
-
stages.some((stage, index) => stage.stage !== tableStages[index]) ||
|
|
109
|
-
(stages[1].options?.id !== undefined &&
|
|
110
|
-
typeof stages[1].options.id !== "string")) {
|
|
111
|
-
throw new TypeError("Atomic mutation requires one instance-scoped table");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/** Executes only the explicit atomic stage; invalid adapter results fail closed. */
|
|
115
|
-
class AtomicMutationQuery extends query_1.Query {
|
|
116
|
-
async run() {
|
|
117
|
-
const terminal = this.stages.at(-1);
|
|
118
|
-
ValidateAtomicMutationTable(this.stages.slice(0, -1));
|
|
119
|
-
if (terminal.stage !== "atomicMutation" ||
|
|
120
|
-
terminal.options !== undefined ||
|
|
121
|
-
terminal.args.length !== 2) {
|
|
122
|
-
throw new TypeError("Atomic mutation requires its canonical terminal stage");
|
|
123
|
-
}
|
|
124
|
-
ValidateAtomicMutation(terminal.args[0], terminal.args[1]);
|
|
125
|
-
const result = await super.run();
|
|
126
|
-
if (!outcomes.includes(result))
|
|
127
|
-
throw new AtomicMutationUnsupportedError();
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
cursor() {
|
|
131
|
-
throw new TypeError("Atomic mutations cannot be executed as cursors");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.AtomicMutationQuery = AtomicMutationQuery;
|
|
30
|
+
async function run() {
|
|
31
|
+
const stages = this.build();
|
|
32
|
+
const terminal = stages.at(-1);
|
|
33
|
+
(0, atomic_1.ValidateAtomicMutationTable)(stages.slice(0, -1));
|
|
34
|
+
if (terminal.stage !== "atomicMutation" ||
|
|
35
|
+
terminal.options !== undefined ||
|
|
36
|
+
terminal.args.length !== 2) {
|
|
37
|
+
throw new TypeError("Atomic mutation requires its canonical terminal stage");
|
|
38
|
+
}
|
|
39
|
+
(0, atomic_1.ValidateAtomicMutation)(terminal.args[0], terminal.args[1]);
|
|
40
|
+
const result = await query_1.Query.prototype.run.call(this);
|
|
41
|
+
if (!outcomes.includes(result))
|
|
42
|
+
throw new AtomicMutationUnsupportedError();
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function cursor() {
|
|
46
|
+
throw new TypeError("Atomic mutations cannot be executed as cursors");
|
|
47
|
+
}
|
|
48
|
+
Object.defineProperties(atomic_1.AtomicMutationQuery.prototype, {
|
|
49
|
+
run: { configurable: true, value: run, writable: true },
|
|
50
|
+
cursor: { configurable: true, value: cursor, writable: true },
|
|
51
|
+
});
|
|
52
|
+
__exportStar(require("./staged-query/atomic"), exports);
|
|
135
53
|
//# sourceMappingURL=atomic.js.map
|
package/dist/atomic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../src/atomic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../src/atomic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAChC,kDAK+B;AA2CO,oGA/Cb,4BAAyB,OA+CO;AAzCzD,MAAM,QAAQ,GAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AAE3E,+EAA+E;AAC/E,MAAa,8BAA+B,SAAQ,KAAK;IACvD;QACE,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AALD,wEAKC;AAED,KAAK,UAAU,GAAG;IAGhB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC5B,MAA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./valueproxy";
|
|
5
|
-
/**
|
|
6
|
-
* Recursive Partial generic type
|
|
7
|
-
*/
|
|
8
|
-
export type DeepPartial<T> = {
|
|
9
|
-
[K in keyof T]?: T[K] extends Array<infer U1> ? Array<DeepPartial<U1>> : T[K] extends ReadonlyArray<infer U2> ? ReadonlyArray<DeepPartial<U2>> : DeepPartial<T[K]>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Change event
|
|
13
|
-
*/
|
|
14
|
-
export interface Changes<T> {
|
|
15
|
-
/**
|
|
16
|
-
* The type of change that occured
|
|
17
|
-
*
|
|
18
|
-
* Possible values: added, removed, modified
|
|
19
|
-
*/
|
|
20
|
-
changeType: "added" | "removed" | "modified";
|
|
21
|
-
/**
|
|
22
|
-
* Value prior to the change
|
|
23
|
-
*/
|
|
24
|
-
oldValue?: T;
|
|
25
|
-
/**
|
|
26
|
-
* New value after the change
|
|
27
|
-
*/
|
|
28
|
-
newValue?: T;
|
|
29
|
-
}
|
|
30
|
-
export interface InsertOptions {
|
|
31
|
-
conflict?: "update" | "replace";
|
|
32
|
-
}
|
|
33
|
-
export interface QueryStage {
|
|
34
|
-
stage: string;
|
|
35
|
-
options?: any;
|
|
36
|
-
args: any[];
|
|
37
|
-
}
|
|
38
|
-
export declare function QueryStage(stage: string, options?: any, ...args: any[]): {
|
|
39
|
-
stage: string;
|
|
40
|
-
options: any;
|
|
41
|
-
args: any[];
|
|
42
|
-
};
|
|
43
|
-
export declare class StagedObject {
|
|
44
|
-
protected readonly stages: QueryStage[];
|
|
45
|
-
constructor(newStage: QueryStage, previous?: StagedObject);
|
|
46
|
-
build(): QueryStage[];
|
|
47
|
-
protected stage(type: undefined, stage: string, options?: any, ...args: any[]): this;
|
|
48
|
-
protected stage<T extends StagedObject>(type: Class<T>, stage: string, options?: any, ...args: any[]): T;
|
|
49
|
-
private static nextargid;
|
|
50
|
-
protected callfunc<T extends StagedObject[]>(func: (...args: T) => any, ...args: (typeof StagedObject)[]): QueryStage;
|
|
51
|
-
}
|
|
52
|
-
export type Value<T> = Datum<T> | ValueProxyOrValue<T>;
|
|
53
|
-
type UnknownObject = Record<keyof any, unknown>;
|
|
54
|
-
type ExtractTypeObject<T extends UnknownObject> = T extends infer O ? {
|
|
55
|
-
[K in keyof O]: ExtractType<O[K]>;
|
|
56
|
-
} : never;
|
|
57
|
-
export type ExtractType<T> = T extends ValueProxy<infer A> ? A : T extends Query<infer A> ? A : T extends UnknownObject ? ExtractTypeObject<T> : T extends Array<infer A> ? Array<ExtractType<A>> : T;
|
|
58
|
-
export {};
|
|
1
|
+
export * from "./staged-query/common";
|
package/dist/common.js
CHANGED
|
@@ -1,44 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
stage,
|
|
8
|
-
options,
|
|
9
|
-
args,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
class StagedObject {
|
|
13
|
-
stages;
|
|
14
|
-
constructor(newStage, previous) {
|
|
15
|
-
this.stages = previous ? [...previous.stages, newStage] : [newStage];
|
|
16
|
-
}
|
|
17
|
-
//@internal
|
|
18
|
-
build() {
|
|
19
|
-
return this.stages;
|
|
20
|
-
}
|
|
21
|
-
stage(type, stage, options, ...args) {
|
|
22
|
-
return new (type ?? this.constructor)({
|
|
23
|
-
stage,
|
|
24
|
-
options,
|
|
25
|
-
args,
|
|
26
|
-
}, this);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
7
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
stage: "func", // TODO: using the query stage structure here doesnt make any sense
|
|
39
|
-
args: [argNumbers, func(...argValues)],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.StagedObject = StagedObject;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./staged-query/common"), exports);
|
|
44
18
|
//# sourceMappingURL=common.js.map
|
package/dist/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
|
package/dist/datum.d.ts
CHANGED
|
@@ -1,55 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ValueProxy } from "./valueproxy";
|
|
3
|
-
import type { Selection } from "./selection";
|
|
4
|
-
import type { ExtractType, Value } from "./common";
|
|
5
|
-
export declare class Datum<T> extends Query<T> {
|
|
6
|
-
/**
|
|
7
|
-
* Changes the type of this datum.
|
|
8
|
-
* This does not actually perform any conversion, it only changes the typescript type.
|
|
9
|
-
*
|
|
10
|
-
* @returns Same datum with a different type
|
|
11
|
-
*/
|
|
12
|
-
cast<U>(): Datum<U>;
|
|
13
|
-
/**
|
|
14
|
-
* Indexes the datum.
|
|
15
|
-
*
|
|
16
|
-
* TODO: Better name?
|
|
17
|
-
* TODO: typing for compound keys (a.b.c)
|
|
18
|
-
*
|
|
19
|
-
* @param key Field name
|
|
20
|
-
* @param def Default value
|
|
21
|
-
* @returns New datum with the value
|
|
22
|
-
*/
|
|
23
|
-
key<K extends keyof NonNullable<T>, U = undefined>(key: K, def?: U): Datum<U extends undefined ? NonNullable<T>[K] : U | NonNullable<NonNullable<T>[K]>>;
|
|
24
|
-
/**
|
|
25
|
-
* Defaults the datum to a given value if it is null.
|
|
26
|
-
*
|
|
27
|
-
* @param value Default value
|
|
28
|
-
* @returns Current datum or given value
|
|
29
|
-
*/
|
|
30
|
-
default<U>(val: Value<U>): Datum<U | Exclude<T, null | undefined>>;
|
|
31
|
-
/**
|
|
32
|
-
* Run a mapping function on the datum.
|
|
33
|
-
*
|
|
34
|
-
* @param mapper Mapping function
|
|
35
|
-
* @returns New datum with the result of the mapper
|
|
36
|
-
*/
|
|
37
|
-
do<U>(mapper: (val: ValueProxy<T>) => U): Datum<ExtractType<U>>;
|
|
38
|
-
/**
|
|
39
|
-
* Perform a foreign key lookup
|
|
40
|
-
*
|
|
41
|
-
* @param other Other table
|
|
42
|
-
* @param localKey Key in local object
|
|
43
|
-
* @param otherKey Key in other table
|
|
44
|
-
*/
|
|
45
|
-
lookup<U = any, TK extends keyof T = keyof T>(other: Selection<U>, localKey: TK, otherKey: keyof U): Datum<Omit<T, TK> & Record<TK, T[TK] extends any[] ? U[] : U>>;
|
|
46
|
-
/**
|
|
47
|
-
* Plucks fields from the documents.
|
|
48
|
-
*
|
|
49
|
-
* TODO: Better typing
|
|
50
|
-
*
|
|
51
|
-
* @param fields Fields to keep
|
|
52
|
-
* @returns New datum
|
|
53
|
-
*/
|
|
54
|
-
pluck(...fields: string[]): Datum<Partial<T>>;
|
|
55
|
-
}
|
|
1
|
+
export { Datum } from "./staged-query/datum";
|
package/dist/datum.js
CHANGED
|
@@ -1,70 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Datum = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Datum extends query_1.Query {
|
|
7
|
-
/**
|
|
8
|
-
* Changes the type of this datum.
|
|
9
|
-
* This does not actually perform any conversion, it only changes the typescript type.
|
|
10
|
-
*
|
|
11
|
-
* @returns Same datum with a different type
|
|
12
|
-
*/
|
|
13
|
-
cast() {
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Indexes the datum.
|
|
18
|
-
*
|
|
19
|
-
* TODO: Better name?
|
|
20
|
-
* TODO: typing for compound keys (a.b.c)
|
|
21
|
-
*
|
|
22
|
-
* @param key Field name
|
|
23
|
-
* @param def Default value
|
|
24
|
-
* @returns New datum with the value
|
|
25
|
-
*/
|
|
26
|
-
key(key, def) {
|
|
27
|
-
return this.stage((Datum), "key", undefined, key, def);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Defaults the datum to a given value if it is null.
|
|
31
|
-
*
|
|
32
|
-
* @param value Default value
|
|
33
|
-
* @returns Current datum or given value
|
|
34
|
-
*/
|
|
35
|
-
default(val) {
|
|
36
|
-
return this.stage((Datum), "default", undefined, val);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Run a mapping function on the datum.
|
|
40
|
-
*
|
|
41
|
-
* @param mapper Mapping function
|
|
42
|
-
* @returns New datum with the result of the mapper
|
|
43
|
-
*/
|
|
44
|
-
do(mapper) {
|
|
45
|
-
return this.stage((Datum), "map", undefined, this.callfunc(mapper, (valueproxy_1.ValueProxy)));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Perform a foreign key lookup
|
|
49
|
-
*
|
|
50
|
-
* @param other Other table
|
|
51
|
-
* @param localKey Key in local object
|
|
52
|
-
* @param otherKey Key in other table
|
|
53
|
-
*/
|
|
54
|
-
lookup(other, localKey, otherKey) {
|
|
55
|
-
return this.stage((Datum), "lookup", { localKey, otherKey }, other);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Plucks fields from the documents.
|
|
59
|
-
*
|
|
60
|
-
* TODO: Better typing
|
|
61
|
-
*
|
|
62
|
-
* @param fields Fields to keep
|
|
63
|
-
* @returns New datum
|
|
64
|
-
*/
|
|
65
|
-
pluck(...fields) {
|
|
66
|
-
return this.stage((Datum), "pluck", undefined, fields);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.Datum = Datum;
|
|
4
|
+
var datum_1 = require("./staged-query/datum");
|
|
5
|
+
Object.defineProperty(exports, "Datum", { enumerable: true, get: function () { return datum_1.Datum; } });
|
|
70
6
|
//# sourceMappingURL=datum.js.map
|
package/dist/datum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datum.js","sourceRoot":"","sources":["../src/datum.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"datum.js","sourceRoot":"","sources":["../src/datum.ts"],"names":[],"mappings":";;;AAAA,8CAA6C;AAApC,8FAAA,KAAK,OAAA"}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const RunQuery: (query: import("./common").QueryStage[]) => Promise<any>;
|
|
3
|
-
export declare const ReadCursor: (reqId: number, stages: import("./common").QueryStage[]) => Promise<IteratorResult<any, void>>;
|
|
1
|
+
import { Query as StagedQuery } from "./staged-query/query";
|
|
2
|
+
export declare const RunQuery: (query: import("./staged-query/common").QueryStage[]) => Promise<any>;
|
|
3
|
+
export declare const ReadCursor: (reqId: number, stages: import("./staged-query/common").QueryStage[]) => Promise<IteratorResult<any, void>>;
|
|
4
4
|
export declare const CloseCursor: (reqId: number) => Promise<void>;
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
* Execute the query
|
|
8
|
-
*
|
|
9
|
-
* @returns Query result
|
|
10
|
-
*/
|
|
5
|
+
export interface QueryExecution<T> extends PromiseLike<T> {
|
|
11
6
|
run(): Promise<T>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[Symbol.asyncIterator](): AsyncGenerator<T extends (infer T1)[] ? T1 : T, void, unknown>;
|
|
7
|
+
cursor(): AsyncGenerator<T extends Array<infer U> ? U : T, void, unknown>;
|
|
8
|
+
[Symbol.asyncIterator](): AsyncGenerator<T extends Array<infer U> ? U : T, void, unknown>;
|
|
15
9
|
}
|
|
10
|
+
declare module "./staged-query/query" {
|
|
11
|
+
interface Query<T> extends QueryExecution<T> {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { StagedQuery as Query };
|
package/dist/query.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Query = exports.CloseCursor = exports.ReadCursor = exports.RunQuery = void 0;
|
|
4
4
|
const interface_core_1 = require("@antelopejs/interface-core");
|
|
5
|
-
const
|
|
5
|
+
const query_1 = require("./staged-query/query");
|
|
6
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
|
6
7
|
//@internal
|
|
7
8
|
exports.RunQuery = (0, interface_core_1.InterfaceFunction)();
|
|
8
9
|
//@internal
|
|
@@ -54,26 +55,27 @@ class IterableCursor {
|
|
|
54
55
|
return this;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return this.run().then(onfulfilled, onrejected);
|
|
69
|
-
}
|
|
70
|
-
//TODO: core interface function for async generators
|
|
71
|
-
cursor() {
|
|
72
|
-
return new IterableCursor(this.stages);
|
|
73
|
-
}
|
|
74
|
-
[Symbol.asyncIterator]() {
|
|
75
|
-
return this.cursor();
|
|
76
|
-
}
|
|
58
|
+
function run() {
|
|
59
|
+
return (0, exports.RunQuery)(this.build());
|
|
60
|
+
}
|
|
61
|
+
function then(onfulfilled, onrejected) {
|
|
62
|
+
return this.run().then(onfulfilled, onrejected);
|
|
63
|
+
}
|
|
64
|
+
function cursor() {
|
|
65
|
+
return new IterableCursor(this.build());
|
|
66
|
+
}
|
|
67
|
+
function iterate() {
|
|
68
|
+
return this.cursor();
|
|
77
69
|
}
|
|
78
|
-
|
|
70
|
+
Object.defineProperties(query_1.Query.prototype, {
|
|
71
|
+
run: { configurable: true, value: run, writable: true },
|
|
72
|
+
// oxlint-disable-next-line unicorn/no-thenable -- Query is deliberately PromiseLike so `await query` executes it.
|
|
73
|
+
then: { configurable: true, value: then, writable: true },
|
|
74
|
+
cursor: { configurable: true, value: cursor, writable: true },
|
|
75
|
+
[Symbol.asyncIterator]: {
|
|
76
|
+
configurable: true,
|
|
77
|
+
value: iterate,
|
|
78
|
+
writable: true,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
79
81
|
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAG/D,gDAA4D;AAgHpC,sFAhHN,aAAW,OAgHA;AA9G7B,WAAW;AACE,QAAA,QAAQ,GACnB,IAAA,kCAAiB,GAA0C,CAAC;AAC9D,WAAW;AACE,QAAA,UAAU,GACrB,IAAA,kCAAiB,GAEd,CAAC;AACN,WAAW;AACE,QAAA,WAAW,GAAG,IAAA,kCAAiB,GAA2B,CAAC;AAExE,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,MAAM,cAAc;IAKS;IAJnB,KAAK,CAAS;IACd,OAAO,CAA4C;IACnD,MAAM,CAAsB;IAEpC,YAA2B,MAA8B;QAA9B,WAAM,GAAN,MAAM,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