@snowtop/ent 0.1.0-alpha114 → 0.1.0-alpha116
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/action/orchestrator.js +12 -0
- package/core/base.d.ts +10 -10
- package/core/context.d.ts +2 -2
- package/core/loaders/index_loader.d.ts +1 -1
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/object_loader.d.ts +9 -9
- package/core/loaders/object_loader.js +3 -2
- package/core/loaders/query_loader.d.ts +1 -1
- package/package.json +1 -1
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_tag.d.ts +1 -1
- package/testutils/fake_data/fake_user.d.ts +3 -3
package/action/orchestrator.js
CHANGED
|
@@ -290,6 +290,18 @@ class Orchestrator {
|
|
|
290
290
|
if (!val) {
|
|
291
291
|
continue;
|
|
292
292
|
}
|
|
293
|
+
if (field.valid) {
|
|
294
|
+
let valid = field.valid(val);
|
|
295
|
+
if (util_1.types.isPromise(valid)) {
|
|
296
|
+
valid = await valid;
|
|
297
|
+
}
|
|
298
|
+
// if not valid, don't format and don't pass to ent?
|
|
299
|
+
// or just early throw here
|
|
300
|
+
if (!valid) {
|
|
301
|
+
continue;
|
|
302
|
+
// throw new Error(`invalid field ${fieldName} with value ${val}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
293
305
|
// nested so it's not JSON stringified or anything like that
|
|
294
306
|
val = field.format(formatted[dbKey], true);
|
|
295
307
|
if (util_1.types.isPromise(val)) {
|
package/core/base.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as clause from "./clause";
|
|
2
|
-
export interface Loader<
|
|
2
|
+
export interface Loader<K, V> {
|
|
3
3
|
context?: Context;
|
|
4
|
-
load(key:
|
|
5
|
-
loadMany?(keys:
|
|
4
|
+
load(key: K): Promise<V>;
|
|
5
|
+
loadMany?(keys: K[]): Promise<(V | null)[]>;
|
|
6
6
|
clearAll(): any;
|
|
7
7
|
}
|
|
8
8
|
export interface LoaderWithLoadMany<T, V> extends Loader<T, V> {
|
|
@@ -19,13 +19,13 @@ export interface ConfigurableLoaderFactory<T, V> extends LoaderFactory<T, V> {
|
|
|
19
19
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<T, V>;
|
|
20
20
|
}
|
|
21
21
|
export type EdgeQueryableDataOptions = Partial<Pick<QueryableDataOptions, "limit" | "orderby" | "clause">>;
|
|
22
|
-
export interface PrimableLoader<
|
|
23
|
-
prime(d:
|
|
24
|
-
primeAll?(d:
|
|
22
|
+
export interface PrimableLoader<K, V> extends Loader<K, V> {
|
|
23
|
+
prime(d: V): void;
|
|
24
|
+
primeAll?(d: V): void;
|
|
25
25
|
}
|
|
26
26
|
interface cache {
|
|
27
|
-
getLoader<
|
|
28
|
-
getLoaderWithLoadMany<
|
|
27
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
28
|
+
getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, V>;
|
|
29
29
|
getCachedRows(options: queryOptions): Data[] | null;
|
|
30
30
|
getCachedRow(options: queryOptions): Data | null;
|
|
31
31
|
primeCache(options: queryOptions, rows: Data[]): void;
|
|
@@ -113,11 +113,11 @@ export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer =
|
|
|
113
113
|
ent: EntConstructor<TEnt, TViewer>;
|
|
114
114
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
115
115
|
}
|
|
116
|
-
export interface LoaderInfo {
|
|
116
|
+
export interface LoaderInfo<T = Data> {
|
|
117
117
|
tableName: string;
|
|
118
118
|
fields: string[];
|
|
119
119
|
nodeType: string;
|
|
120
|
-
loaderFactory: LoaderFactory<
|
|
120
|
+
loaderFactory: LoaderFactory<ID, T | null>;
|
|
121
121
|
}
|
|
122
122
|
export interface EditEntOptions<T extends Ent> extends LoadableEntOptions<T>, EditRowOptions {
|
|
123
123
|
}
|
package/core/context.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export interface RequestContext<TViewer extends Viewer = Viewer> extends Context
|
|
|
12
12
|
export declare class ContextCache {
|
|
13
13
|
loaders: Map<string, Loader<any, any>>;
|
|
14
14
|
loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
|
|
15
|
-
getLoader<
|
|
16
|
-
getLoaderWithLoadMany<
|
|
15
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
16
|
+
getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, V>;
|
|
17
17
|
private itemMap;
|
|
18
18
|
private listMap;
|
|
19
19
|
private getkey;
|
|
@@ -7,7 +7,7 @@ export declare class IndexLoaderFactory implements LoaderFactory<ID, Data[]> {
|
|
|
7
7
|
constructor(options: SelectBaseDataOptions, col: string, opts?: {
|
|
8
8
|
extraClause?: clause.Clause;
|
|
9
9
|
sortColumn?: string;
|
|
10
|
-
toPrime?: ObjectLoaderFactory<
|
|
10
|
+
toPrime?: ObjectLoaderFactory<Data>[];
|
|
11
11
|
});
|
|
12
12
|
createLoader(context?: Context): any;
|
|
13
13
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<ID, Data[]>;
|
package/core/loaders/loader.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader, LoaderFactory, Context, DataOptions } from "../base";
|
|
2
|
-
export declare function getLoader<
|
|
3
|
-
export declare function getCustomLoader<
|
|
2
|
+
export declare function getLoader<K, V>(factory: LoaderFactory<K, V>, create: () => Loader<K, V>, context?: Context): Loader<K, V>;
|
|
3
|
+
export declare function getCustomLoader<K, V>(key: string, create: () => Loader<K, V>, context?: Context): Loader<K, V>;
|
|
4
4
|
export declare class cacheMap {
|
|
5
5
|
private options;
|
|
6
6
|
private m;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { ID, Data, SelectDataOptions, Context, Loader, LoaderFactory } from "../base";
|
|
2
|
-
export declare class ObjectLoader<
|
|
2
|
+
export declare class ObjectLoader<V = Data> implements Loader<ID, V | null> {
|
|
3
3
|
private options;
|
|
4
4
|
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
5
5
|
private toPrime?;
|
|
6
6
|
private loader;
|
|
7
7
|
private primedLoaders;
|
|
8
8
|
private memoizedInitPrime;
|
|
9
|
-
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);
|
|
10
10
|
getOptions(): SelectDataOptions;
|
|
11
11
|
private initPrime;
|
|
12
|
-
load(key:
|
|
12
|
+
load(key: ID): Promise<V | null>;
|
|
13
13
|
clearAll(): void;
|
|
14
|
-
loadMany(keys:
|
|
15
|
-
prime(data:
|
|
16
|
-
primeAll(data:
|
|
14
|
+
loadMany(keys: ID[]): Promise<Array<V | null>>;
|
|
15
|
+
prime(data: V): void;
|
|
16
|
+
primeAll(data: V): void;
|
|
17
17
|
}
|
|
18
18
|
interface ObjectLoaderOptions extends SelectDataOptions {
|
|
19
19
|
instanceKey?: string;
|
|
20
20
|
}
|
|
21
|
-
export declare class ObjectLoaderFactory<
|
|
21
|
+
export declare class ObjectLoaderFactory<V = Data> implements LoaderFactory<ID, V | null> {
|
|
22
22
|
options: ObjectLoaderOptions;
|
|
23
23
|
name: string;
|
|
24
24
|
private toPrime;
|
|
25
25
|
constructor(options: ObjectLoaderOptions);
|
|
26
|
-
createLoader(context?: Context): ObjectLoader<
|
|
27
|
-
addToPrime(factory: ObjectLoaderFactory<
|
|
26
|
+
createLoader(context?: Context): ObjectLoader<V>;
|
|
27
|
+
addToPrime(factory: ObjectLoaderFactory<V>): this;
|
|
28
28
|
}
|
|
29
29
|
export {};
|
|
@@ -60,7 +60,7 @@ async function loadRowsForLoader(options, ids, context) {
|
|
|
60
60
|
// store the index....
|
|
61
61
|
m.set(ids[i], i);
|
|
62
62
|
}
|
|
63
|
-
const rows = await (0, ent_1.loadRows)(rowOptions);
|
|
63
|
+
const rows = (await (0, ent_1.loadRows)(rowOptions));
|
|
64
64
|
for (const row of rows) {
|
|
65
65
|
const id = row[col];
|
|
66
66
|
if (id === undefined) {
|
|
@@ -162,7 +162,8 @@ class ObjectLoader {
|
|
|
162
162
|
}
|
|
163
163
|
async loadMany(keys) {
|
|
164
164
|
if (this.loader) {
|
|
165
|
-
|
|
165
|
+
// @ts-expect-error TODO?
|
|
166
|
+
return this.loader.loadMany(keys);
|
|
166
167
|
}
|
|
167
168
|
return loadRowsForLoader(this.options, keys, this.context);
|
|
168
169
|
}
|
|
@@ -19,7 +19,7 @@ interface QueryOptions {
|
|
|
19
19
|
groupCol?: string;
|
|
20
20
|
clause?: clause.Clause;
|
|
21
21
|
sortColumn?: string;
|
|
22
|
-
toPrime?: ObjectLoaderFactory<
|
|
22
|
+
toPrime?: ObjectLoaderFactory<Data>[];
|
|
23
23
|
}
|
|
24
24
|
export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<K, Data[]> {
|
|
25
25
|
private options;
|
package/package.json
CHANGED
|
@@ -34,4 +34,4 @@ export interface ContactCreateInput {
|
|
|
34
34
|
}
|
|
35
35
|
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
36
36
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
37
|
-
export declare const contactLoader: ObjectLoaderFactory<
|
|
37
|
+
export declare const contactLoader: ObjectLoaderFactory<Data>;
|
|
@@ -33,4 +33,4 @@ export type TagEditInput = Partial<TagCreateInput>;
|
|
|
33
33
|
export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): import("../builder").SimpleBuilder<FakeTag, null>;
|
|
34
34
|
export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
|
|
35
35
|
export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
|
|
36
|
-
export declare const tagLoader: ObjectLoaderFactory<
|
|
36
|
+
export declare const tagLoader: ObjectLoaderFactory<Data>;
|
|
@@ -46,7 +46,7 @@ export type UserEditInput = Partial<UserCreateInput>;
|
|
|
46
46
|
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
|
|
47
47
|
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
|
|
48
48
|
export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
|
|
49
|
-
export declare const userLoader: ObjectLoaderFactory<
|
|
50
|
-
export declare const userEmailLoader: ObjectLoaderFactory<
|
|
51
|
-
export declare const userPhoneNumberLoader: ObjectLoaderFactory<
|
|
49
|
+
export declare const userLoader: ObjectLoaderFactory<Data>;
|
|
50
|
+
export declare const userEmailLoader: ObjectLoaderFactory<Data>;
|
|
51
|
+
export declare const userPhoneNumberLoader: ObjectLoaderFactory<Data>;
|
|
52
52
|
export {};
|