@snowtop/ent 0.1.0-alpha124 → 0.1.0-alpha126
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/core/base.d.ts +7 -8
- package/core/clause.d.ts +1 -2
- package/core/clause.js +1 -18
- package/core/ent.d.ts +10 -10
- package/core/ent.js +54 -35
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/object_loader.d.ts +8 -28
- package/core/loaders/object_loader.js +39 -176
- package/core/loaders/query_loader.d.ts +1 -1
- package/core/query/shared_test.js +1 -2
- package/graphql/graphql.d.ts +19 -12
- package/graphql/graphql.js +66 -126
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +1 -2
- package/imports/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/package.json +4 -5
- package/parse_schema/parse.d.ts +1 -2
- package/parse_schema/parse.js +2 -10
- package/schema/field.d.ts +3 -5
- package/schema/field.js +15 -69
- package/schema/schema.d.ts +0 -2
- package/schema/struct_field.d.ts +6 -8
- package/schema/struct_field.js +8 -67
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +2 -2
- package/scripts/move_types.js +4 -1
- package/testutils/db_mock.js +1 -1
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_log.js +1 -1
- package/core/global_schema.d.ts +0 -7
- package/core/global_schema.js +0 -51
package/core/base.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as clause from "./clause";
|
|
2
|
-
import { ObjectLoaderFactory } from "./loaders";
|
|
3
2
|
export interface Loader<K, V> {
|
|
4
3
|
context?: Context;
|
|
5
4
|
load(key: K): Promise<V>;
|
|
@@ -96,21 +95,21 @@ export interface EditRowOptions extends CreateRowOptions {
|
|
|
96
95
|
whereClause: clause.Clause;
|
|
97
96
|
expressions?: Map<string, clause.Clause>;
|
|
98
97
|
}
|
|
99
|
-
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer
|
|
100
|
-
loaderFactory:
|
|
98
|
+
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
99
|
+
loaderFactory: LoaderFactoryWithOptions;
|
|
101
100
|
ent: EntConstructor<TEnt, TViewer>;
|
|
102
101
|
}
|
|
103
|
-
export interface LoaderFactoryWithOptions
|
|
102
|
+
export interface LoaderFactoryWithOptions extends LoaderFactoryWithLoaderMany<any, Data | null> {
|
|
104
103
|
options?: SelectDataOptions;
|
|
105
104
|
}
|
|
106
|
-
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer
|
|
105
|
+
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends LoadableEntOptions<TEnt, TViewer>, SelectBaseDataOptions {
|
|
107
106
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
108
107
|
}
|
|
109
|
-
export interface SelectCustomDataOptions
|
|
110
|
-
loaderFactory:
|
|
108
|
+
export interface SelectCustomDataOptions extends SelectBaseDataOptions {
|
|
109
|
+
loaderFactory: LoaderFactoryWithOptions;
|
|
111
110
|
prime?: boolean;
|
|
112
111
|
}
|
|
113
|
-
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer
|
|
112
|
+
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends SelectCustomDataOptions {
|
|
114
113
|
ent: EntConstructor<TEnt, TViewer>;
|
|
115
114
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
116
115
|
}
|
package/core/clause.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data
|
|
1
|
+
import { Data } from "./base";
|
|
2
2
|
export interface Clause<T extends Data = Data, K = keyof T> {
|
|
3
3
|
clause(idx: number): string;
|
|
4
4
|
columns(): K[];
|
|
@@ -102,5 +102,4 @@ export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any
|
|
|
102
102
|
export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
103
103
|
export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
104
104
|
export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
105
|
-
export declare function getCombinedClause<V extends Data = Data, K = keyof V>(options: Omit<SelectDataOptions, "key">, cls: Clause<V, K>): Clause<V, K>;
|
|
106
105
|
export {};
|
package/core/clause.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.inClause = void 0;
|
|
27
27
|
const db_1 = __importStar(require("./db"));
|
|
28
28
|
function isSensitive(val) {
|
|
29
29
|
return (val !== null &&
|
|
@@ -731,20 +731,3 @@ function Modulo(col, value) {
|
|
|
731
731
|
return new simpleClause(col, value, "%", new isNullClause(col));
|
|
732
732
|
}
|
|
733
733
|
exports.Modulo = Modulo;
|
|
734
|
-
function getCombinedClause(options, cls) {
|
|
735
|
-
if (options.clause) {
|
|
736
|
-
let optionClause;
|
|
737
|
-
if (typeof options.clause === "function") {
|
|
738
|
-
optionClause = options.clause();
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
optionClause = options.clause;
|
|
742
|
-
}
|
|
743
|
-
if (optionClause) {
|
|
744
|
-
// @ts-expect-error different types
|
|
745
|
-
cls = And(cls, optionClause);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return cls;
|
|
749
|
-
}
|
|
750
|
-
exports.getCombinedClause = getCombinedClause;
|
package/core/ent.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Executor } from "../action/action";
|
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Builder } from "../action";
|
|
6
6
|
import DataLoader from "dataloader";
|
|
7
|
+
import { GlobalSchema } from "../schema/";
|
|
7
8
|
export declare function getEntKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): string;
|
|
8
9
|
export declare function loadEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
9
10
|
export declare function loadEntViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
@@ -23,13 +24,13 @@ export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends
|
|
|
23
24
|
* @deperecated use loadCustomEnts
|
|
24
25
|
*/
|
|
25
26
|
export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
|
|
26
|
-
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer, TQueryData extends Data = Data, TResultData extends Data = TQueryData, TKey = keyof TQueryData>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer
|
|
27
|
+
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer, TQueryData extends Data = Data, TResultData extends Data = TQueryData, TKey = keyof TQueryData>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery<TQueryData, TKey>): Promise<TEnt[]>;
|
|
27
28
|
interface parameterizedQueryOptions {
|
|
28
29
|
query: string;
|
|
29
30
|
values?: any[];
|
|
30
31
|
logValues?: any[];
|
|
31
32
|
}
|
|
32
|
-
export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameterizedQueryOptions | clause.Clause<T, K> | QueryDataOptions
|
|
33
|
+
export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameterizedQueryOptions | clause.Clause<T, K> | QueryDataOptions;
|
|
33
34
|
/**
|
|
34
35
|
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
35
36
|
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
@@ -53,15 +54,11 @@ export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameter
|
|
|
53
54
|
* orderby: 'time',
|
|
54
55
|
* disableTransformations: false
|
|
55
56
|
* }) // doesn't change the query
|
|
56
|
-
*
|
|
57
|
-
* For queries that pass in a clause, we batch them with an underlying dataloader so that multiple queries with the same clause
|
|
58
|
-
* or parallel queries with the same clause are batched together.
|
|
59
|
-
*
|
|
60
|
-
* If a raw or parameterized query is passed in, we don't attempt to batch them together and they're executed as is.
|
|
61
|
-
* If you end up with a scenario where you may need to coalesce or batch (non-clause) queries here, you should use some kind of memoization here.
|
|
62
57
|
*/
|
|
63
|
-
export declare function loadCustomData<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData>(options: SelectCustomDataOptions
|
|
64
|
-
|
|
58
|
+
export declare function loadCustomData<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData>(options: SelectCustomDataOptions, query: CustomQuery<TQueryData, K>, context: Context | undefined): Promise<TResultData[]>;
|
|
59
|
+
interface CustomCountOptions extends DataOptions {
|
|
60
|
+
}
|
|
61
|
+
export declare function loadCustomCount<T extends Data = Data, K = keyof T>(options: CustomCountOptions, query: CustomQuery<T, K>, context: Context | undefined): Promise<number>;
|
|
65
62
|
export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
|
|
66
63
|
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
67
64
|
export declare function logQuery(query: string, logValues: any[]): void;
|
|
@@ -117,6 +114,9 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
|
117
114
|
returnedRow(): Data | null;
|
|
118
115
|
createdEnt(viewer: Viewer): T | null;
|
|
119
116
|
}
|
|
117
|
+
export declare function setGlobalSchema(val: GlobalSchema): void;
|
|
118
|
+
export declare function clearGlobalSchema(): void;
|
|
119
|
+
export declare function __hasGlobalSchema(): boolean;
|
|
120
120
|
export declare class EdgeOperation implements DataOperation {
|
|
121
121
|
private builder;
|
|
122
122
|
edgeInput: AssocEdgeInput;
|
package/core/ent.js
CHANGED
|
@@ -26,16 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = void 0;
|
|
29
|
+
exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.___setLogQueryErrorWithError = exports.loadRow = exports.loadRowX = exports.logQuery = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
|
|
30
|
+
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = void 0;
|
|
31
31
|
const db_1 = __importStar(require("./db"));
|
|
32
32
|
const privacy_1 = require("./privacy");
|
|
33
33
|
const clause = __importStar(require("./clause"));
|
|
34
34
|
const action_1 = require("../action");
|
|
35
35
|
const logger_1 = require("./logger");
|
|
36
36
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
37
|
-
const schema_1 = require("../schema/
|
|
38
|
-
const global_schema_1 = require("./global_schema");
|
|
37
|
+
const schema_1 = require("../schema/");
|
|
39
38
|
// TODO kill this and createDataLoader
|
|
40
39
|
class cacheMap {
|
|
41
40
|
constructor(options) {
|
|
@@ -397,12 +396,6 @@ function isParameterizedQuery(opts) {
|
|
|
397
396
|
* orderby: 'time',
|
|
398
397
|
* disableTransformations: false
|
|
399
398
|
* }) // doesn't change the query
|
|
400
|
-
*
|
|
401
|
-
* For queries that pass in a clause, we batch them with an underlying dataloader so that multiple queries with the same clause
|
|
402
|
-
* or parallel queries with the same clause are batched together.
|
|
403
|
-
*
|
|
404
|
-
* If a raw or parameterized query is passed in, we don't attempt to batch them together and they're executed as is.
|
|
405
|
-
* If you end up with a scenario where you may need to coalesce or batch (non-clause) queries here, you should use some kind of memoization here.
|
|
406
399
|
*/
|
|
407
400
|
async function loadCustomData(options, query, context) {
|
|
408
401
|
const rows = await loadCustomDataImpl(options, query, context);
|
|
@@ -421,10 +414,7 @@ exports.loadCustomData = loadCustomData;
|
|
|
421
414
|
// NOTE: if you use a raw query or paramterized query with this,
|
|
422
415
|
// you should use `SELECT count(*) as count...`
|
|
423
416
|
async function loadCustomCount(options, query, context) {
|
|
424
|
-
//
|
|
425
|
-
if (typeof query !== "string" && isClause(query)) {
|
|
426
|
-
return options.loaderFactory.createCountLoader(context).load(query);
|
|
427
|
-
}
|
|
417
|
+
// TODO also need to loaderify this in case we're querying for this a lot...
|
|
428
418
|
const rows = await loadCustomDataImpl({
|
|
429
419
|
...options,
|
|
430
420
|
fields: ["count(1) as count"],
|
|
@@ -439,31 +429,50 @@ function isPrimableLoader(loader) {
|
|
|
439
429
|
return loader != undefined;
|
|
440
430
|
}
|
|
441
431
|
async function loadCustomDataImpl(options, query, context) {
|
|
432
|
+
function getClause(cls) {
|
|
433
|
+
let optClause = options.loaderFactory?.options?.clause;
|
|
434
|
+
if (typeof optClause === "function") {
|
|
435
|
+
optClause = optClause();
|
|
436
|
+
}
|
|
437
|
+
if (!optClause) {
|
|
438
|
+
return cls;
|
|
439
|
+
}
|
|
440
|
+
// @ts-expect-error string|ID mismatch
|
|
441
|
+
return clause.And(cls, optClause);
|
|
442
|
+
}
|
|
442
443
|
if (typeof query === "string") {
|
|
443
444
|
// no caching, perform raw query
|
|
444
445
|
return performRawQuery(query, [], []);
|
|
446
|
+
// @ts-ignore
|
|
445
447
|
}
|
|
446
448
|
else if (isClause(query)) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
// if a Clause is passed in and we have a default clause
|
|
450
|
+
// associated with the query, pass that in
|
|
451
|
+
// if we want to disableTransformations, need to indicate that with
|
|
452
|
+
// disableTransformations option
|
|
453
|
+
// this will have rudimentary caching but nothing crazy
|
|
454
|
+
return loadRows({
|
|
455
|
+
...options,
|
|
456
|
+
// @ts-ignore
|
|
457
|
+
clause: getClause(query),
|
|
458
|
+
context: context,
|
|
459
|
+
});
|
|
451
460
|
}
|
|
452
461
|
else if (isParameterizedQuery(query)) {
|
|
453
462
|
// no caching, perform raw query
|
|
454
463
|
return performRawQuery(query.query, query.values || [], query.logValues);
|
|
455
464
|
}
|
|
456
465
|
else {
|
|
457
|
-
// this will have rudimentary caching but nothing crazy
|
|
458
466
|
let cls = query.clause;
|
|
459
467
|
if (!query.disableTransformations) {
|
|
460
|
-
|
|
468
|
+
// @ts-ignore
|
|
469
|
+
cls = getClause(cls);
|
|
461
470
|
}
|
|
471
|
+
// this will have rudimentary caching but nothing crazy
|
|
462
472
|
return loadRows({
|
|
463
473
|
...query,
|
|
464
474
|
...options,
|
|
465
475
|
context: context,
|
|
466
|
-
// @ts-expect-error
|
|
467
476
|
clause: cls,
|
|
468
477
|
});
|
|
469
478
|
}
|
|
@@ -600,7 +609,7 @@ async function performRawQuery(query, values, logValues) {
|
|
|
600
609
|
catch (e) {
|
|
601
610
|
if (_logQueryWithError) {
|
|
602
611
|
const msg = e.message;
|
|
603
|
-
throw new Error(`error \`${msg}\` running query: \`${query}
|
|
612
|
+
throw new Error(`error \`${msg}\` running query: \`${query}\``);
|
|
604
613
|
}
|
|
605
614
|
throw e;
|
|
606
615
|
}
|
|
@@ -807,6 +816,20 @@ class EditNodeOperation {
|
|
|
807
816
|
}
|
|
808
817
|
}
|
|
809
818
|
exports.EditNodeOperation = EditNodeOperation;
|
|
819
|
+
let globalSchema;
|
|
820
|
+
function setGlobalSchema(val) {
|
|
821
|
+
globalSchema = val;
|
|
822
|
+
}
|
|
823
|
+
exports.setGlobalSchema = setGlobalSchema;
|
|
824
|
+
function clearGlobalSchema() {
|
|
825
|
+
globalSchema = undefined;
|
|
826
|
+
}
|
|
827
|
+
exports.clearGlobalSchema = clearGlobalSchema;
|
|
828
|
+
// used by tests. no guarantee will always exist
|
|
829
|
+
function __hasGlobalSchema() {
|
|
830
|
+
return globalSchema !== undefined;
|
|
831
|
+
}
|
|
832
|
+
exports.__hasGlobalSchema = __hasGlobalSchema;
|
|
810
833
|
class EdgeOperation {
|
|
811
834
|
constructor(builder, edgeInput, options) {
|
|
812
835
|
this.builder = builder;
|
|
@@ -849,9 +872,8 @@ class EdgeOperation {
|
|
|
849
872
|
let op = schema_1.SQLStatementOperation.Delete;
|
|
850
873
|
let updateData = null;
|
|
851
874
|
// TODO respect disableTransformations
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
transformed = transformedEdgeWrite({
|
|
875
|
+
if (globalSchema?.transformEdgeWrite) {
|
|
876
|
+
transformed = globalSchema.transformEdgeWrite({
|
|
855
877
|
op: schema_1.SQLStatementOperation.Delete,
|
|
856
878
|
edge,
|
|
857
879
|
});
|
|
@@ -929,10 +951,9 @@ class EdgeOperation {
|
|
|
929
951
|
fields["time"] = new Date().toISOString();
|
|
930
952
|
}
|
|
931
953
|
const onConflictFields = ["data"];
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
const f = extraEdgeFields[name];
|
|
954
|
+
if (globalSchema?.extraEdgeFields) {
|
|
955
|
+
for (const name in globalSchema.extraEdgeFields) {
|
|
956
|
+
const f = globalSchema.extraEdgeFields[name];
|
|
936
957
|
if (f.defaultValueOnCreate) {
|
|
937
958
|
const storageKey = (0, schema_1.getStorageKey)(f, name);
|
|
938
959
|
fields[storageKey] = f.defaultValueOnCreate(this.builder, {});
|
|
@@ -944,9 +965,8 @@ class EdgeOperation {
|
|
|
944
965
|
}
|
|
945
966
|
// TODO respect disableTransformations
|
|
946
967
|
let transformed = null;
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
transformed = transformEdgeWrite({
|
|
968
|
+
if (globalSchema?.transformEdgeWrite) {
|
|
969
|
+
transformed = globalSchema.transformEdgeWrite({
|
|
950
970
|
op: schema_1.SQLStatementOperation.Insert,
|
|
951
971
|
edge,
|
|
952
972
|
});
|
|
@@ -1463,9 +1483,8 @@ async function loadEdges(options) {
|
|
|
1463
1483
|
exports.loadEdges = loadEdges;
|
|
1464
1484
|
function getEdgeClauseAndFields(cls, options) {
|
|
1465
1485
|
let fields = edgeFields;
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
const transformClause = transformEdgeRead();
|
|
1486
|
+
if (globalSchema?.transformEdgeRead) {
|
|
1487
|
+
const transformClause = globalSchema.transformEdgeRead();
|
|
1469
1488
|
if (!options.disableTransformations) {
|
|
1470
1489
|
cls = clause.And(cls, transformClause);
|
|
1471
1490
|
}
|
|
@@ -21,7 +21,7 @@ export declare class AssocDirectEdgeLoader<T extends AssocEdge> implements Loade
|
|
|
21
21
|
private edgeCtr;
|
|
22
22
|
private options?;
|
|
23
23
|
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
24
|
-
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T>, options?: Partial<Pick<import("../base").QueryableDataOptions, "
|
|
24
|
+
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T>, options?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
25
25
|
load(id: ID): Promise<T[]>;
|
|
26
26
|
loadEdgeForID2(id: ID, id2: ID): Promise<T | undefined>;
|
|
27
27
|
clearAll(): void;
|
|
@@ -1,49 +1,29 @@
|
|
|
1
1
|
import { ID, Data, SelectDataOptions, Context, Loader, LoaderFactory } from "../base";
|
|
2
|
-
|
|
3
|
-
export declare class ObjectLoader<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData> implements Loader<ID, TResultData | null>, Loader<clause.Clause<TQueryData, K>, TResultData[] | null> {
|
|
2
|
+
export declare class ObjectLoader<V = Data> implements Loader<ID, V | null> {
|
|
4
3
|
private options;
|
|
5
4
|
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
6
5
|
private toPrime?;
|
|
7
|
-
private
|
|
8
|
-
private clauseLoader;
|
|
6
|
+
private loader;
|
|
9
7
|
private primedLoaders;
|
|
10
8
|
private memoizedInitPrime;
|
|
11
|
-
constructor(options: SelectDataOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined, toPrime?: ObjectLoaderFactory<
|
|
9
|
+
constructor(options: SelectDataOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined, toPrime?: ObjectLoaderFactory<V>[] | undefined);
|
|
12
10
|
getOptions(): SelectDataOptions;
|
|
13
11
|
private initPrime;
|
|
14
|
-
load(key: ID): Promise<
|
|
15
|
-
load(key: clause.Clause<TQueryData, K>): Promise<TResultData[] | null>;
|
|
16
|
-
private loadID;
|
|
17
|
-
private loadClause;
|
|
18
|
-
clearAll(): void;
|
|
19
|
-
loadMany(keys: ID[]): Promise<Array<TResultData | null>>;
|
|
20
|
-
loadMany(keys: clause.Clause<TQueryData, K>[]): Promise<Array<TResultData[] | null>>;
|
|
21
|
-
private loadIDMany;
|
|
22
|
-
private loadClauseMany;
|
|
23
|
-
prime(data: TResultData): void;
|
|
24
|
-
primeAll(data: TResultData): void;
|
|
25
|
-
}
|
|
26
|
-
export declare class ObjectCountLoader<V extends Data = Data, K = keyof V> implements Loader<clause.Clause<V, K>, number> {
|
|
27
|
-
private options;
|
|
28
|
-
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
29
|
-
private loader;
|
|
30
|
-
constructor(options: SelectDataOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
31
|
-
getOptions(): SelectDataOptions;
|
|
32
|
-
load(key: clause.Clause<V, K>): Promise<number>;
|
|
12
|
+
load(key: ID): Promise<V | null>;
|
|
33
13
|
clearAll(): void;
|
|
34
|
-
loadMany(keys:
|
|
14
|
+
loadMany(keys: ID[]): Promise<Array<V | null>>;
|
|
15
|
+
prime(data: V): void;
|
|
16
|
+
primeAll(data: V): void;
|
|
35
17
|
}
|
|
36
18
|
interface ObjectLoaderOptions extends SelectDataOptions {
|
|
37
19
|
instanceKey?: string;
|
|
38
20
|
}
|
|
39
|
-
export declare class ObjectLoaderFactory<V
|
|
21
|
+
export declare class ObjectLoaderFactory<V = Data> implements LoaderFactory<ID, V | null> {
|
|
40
22
|
options: ObjectLoaderOptions;
|
|
41
23
|
name: string;
|
|
42
24
|
private toPrime;
|
|
43
25
|
constructor(options: ObjectLoaderOptions);
|
|
44
26
|
createLoader(context?: Context): ObjectLoader<V>;
|
|
45
|
-
createTypedLoader<TQueryData extends Data = Data, TResultData extends Data = Data, K = keyof TQueryData>(context?: Context): ObjectLoader<TQueryData, TResultData, K>;
|
|
46
|
-
createCountLoader<K = keyof V>(context?: Context): ObjectCountLoader<V, K>;
|
|
47
27
|
addToPrime(factory: ObjectLoaderFactory<V>): this;
|
|
48
28
|
}
|
|
49
29
|
export {};
|