@verdant-web/common 2.7.0 → 2.7.1
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/esm/batching.d.ts +3 -4
- package/dist/esm/files.d.ts +0 -1
- package/dist/esm/oidsLegacy.d.ts +1 -1
- package/dist/esm/patch.d.ts +1 -1
- package/dist/esm/schema/fieldHelpers.d.ts +45 -18
- package/dist/esm/schema/fieldHelpers.js +50 -7
- package/dist/esm/schema/fieldHelpers.js.map +1 -1
- package/dist/esm/schema/index.d.ts +36 -32
- package/dist/esm/schema/types/shapes.d.ts +0 -1
- package/package.json +1 -1
- package/src/schema/fieldHelpers.ts +69 -11
package/dist/esm/batching.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
export declare class Batcher<T, UserData = any> {
|
|
3
2
|
private flusher;
|
|
4
3
|
private batches;
|
|
@@ -34,9 +33,9 @@ export declare class Batch<T, UserData = any> {
|
|
|
34
33
|
});
|
|
35
34
|
update: ({ items, max, timeout, userData, }: {
|
|
36
35
|
items: Array<T>;
|
|
37
|
-
max?: number | null
|
|
38
|
-
timeout?: number | null
|
|
39
|
-
userData?: UserData
|
|
36
|
+
max?: number | null;
|
|
37
|
+
timeout?: number | null;
|
|
38
|
+
userData?: UserData;
|
|
40
39
|
}) => void;
|
|
41
40
|
flush: () => any;
|
|
42
41
|
discard: () => void;
|
package/dist/esm/files.d.ts
CHANGED
package/dist/esm/oidsLegacy.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ export declare const MATCH_LEGACY_OID_JSON_STRING: RegExp;
|
|
|
15
15
|
export declare function replaceLegacyOidsInJsonString(string: string): string;
|
|
16
16
|
export declare function replaceLegacyOidsInObject(obj: any): any;
|
|
17
17
|
export declare function getLegacyDotOidSubIdRange(oid: ObjectIdentifier): string[];
|
|
18
|
-
export declare function isOidKey(key: string):
|
|
18
|
+
export declare function isOidKey(key: string): key is "__@@oid_do_not_use" | "@@id";
|
package/dist/esm/patch.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class PatchCreator {
|
|
|
21
21
|
createListPush: (oid: ObjectIdentifier, value: any) => Operation[];
|
|
22
22
|
createListAdd: (oid: ObjectIdentifier, value: any) => Operation[];
|
|
23
23
|
createListInsert: (oid: ObjectIdentifier, index: number, value: any) => Operation[];
|
|
24
|
-
createListRemove: (oid: ObjectIdentifier, value: any, only?:
|
|
24
|
+
createListRemove: (oid: ObjectIdentifier, value: any, only?: "first" | "last") => Operation[];
|
|
25
25
|
createListDelete: (oid: ObjectIdentifier, index: number, count?: number) => Operation[];
|
|
26
26
|
createListMoveByRef: (oid: ObjectIdentifier, value: ObjectRef | FileRef, index: number) => Operation[];
|
|
27
27
|
createListMoveByIndex: (oid: ObjectIdentifier, fromIndex: number, toIndex: number) => Operation[];
|
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
import { ShapeFromFieldsWithDefaults, StorageAnyFieldSchema, StorageArrayFieldSchema, StorageBooleanFieldSchema, StorageFieldSchema, StorageFieldsSchema, StorageFileFieldSchema, StorageMapFieldSchema, StorageNumberFieldSchema, StorageObjectFieldSchema, StorageStringFieldSchema } from './types.js';
|
|
2
|
+
type ObjectFieldArgs<Props extends StorageFieldsSchema> = {
|
|
3
|
+
/** @deprecated - use fields. renamed for more consistency with collection root. */
|
|
4
|
+
properties?: Props;
|
|
5
|
+
fields?: Props;
|
|
6
|
+
nullable?: boolean;
|
|
7
|
+
default?: ShapeFromFieldsWithDefaults<Props> | (() => ShapeFromFieldsWithDefaults<Props>);
|
|
8
|
+
/** Add some docs to your field which will annotate the generated typing */
|
|
9
|
+
documentation?: string;
|
|
10
|
+
};
|
|
11
|
+
declare function objectField<Props extends StorageFieldsSchema>(args: ObjectFieldArgs<Props>): StorageObjectFieldSchema<Props>;
|
|
12
|
+
/**
|
|
13
|
+
* Used for recursively defined field schemas. Replaces the original properties
|
|
14
|
+
* of an object field with the provided fields. This will mutate the original field.
|
|
15
|
+
*/
|
|
16
|
+
declare function replaceObjectFields(object: StorageObjectFieldSchema<any>, fields: StorageFieldsSchema): StorageObjectFieldSchema<any>;
|
|
17
|
+
type ArrayFieldArgs<T extends StorageFieldSchema> = {
|
|
18
|
+
items: T;
|
|
19
|
+
nullable?: boolean;
|
|
20
|
+
/** Add some docs to your field which will annotate the generated typing */
|
|
21
|
+
documentation?: string;
|
|
22
|
+
};
|
|
23
|
+
declare function arrayField<T extends StorageFieldSchema>(args: ArrayFieldArgs<T>): StorageArrayFieldSchema<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Used for recursively defined field schemas. Replaces the original items
|
|
26
|
+
* of an array field with the provided items. This will mutate the original field.
|
|
27
|
+
*/
|
|
28
|
+
declare function replaceArrayItems(array: StorageArrayFieldSchema<any>, items: StorageFieldSchema): StorageArrayFieldSchema<any>;
|
|
29
|
+
type MapFieldArgs<T extends StorageFieldSchema> = {
|
|
30
|
+
values: T;
|
|
31
|
+
/** Add some docs to your field which will annotate the generated typing */
|
|
32
|
+
documentation?: string;
|
|
33
|
+
};
|
|
34
|
+
declare function mapField<T extends StorageFieldSchema>(args: MapFieldArgs<T>): StorageMapFieldSchema<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Used for recursively defined field schemas. Replaces the original values
|
|
37
|
+
* of a map field with the provided values. This will mutate the original field.
|
|
38
|
+
*/
|
|
39
|
+
declare function replaceMapValues(map: StorageMapFieldSchema<any>, values: StorageFieldSchema): StorageMapFieldSchema<any>;
|
|
2
40
|
export declare const fields: {
|
|
3
|
-
object:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** Add some docs to your field which will annotate the generated typing */
|
|
8
|
-
documentation?: string;
|
|
9
|
-
}) => StorageObjectFieldSchema<Props>;
|
|
10
|
-
array: <T extends StorageFieldSchema>(args: {
|
|
11
|
-
items: T;
|
|
12
|
-
nullable?: boolean;
|
|
13
|
-
/** Add some docs to your field which will annotate the generated typing */
|
|
14
|
-
documentation?: string;
|
|
15
|
-
}) => StorageArrayFieldSchema<T>;
|
|
41
|
+
object: typeof objectField;
|
|
42
|
+
array: typeof arrayField;
|
|
43
|
+
replaceObjectFields: typeof replaceObjectFields;
|
|
44
|
+
replaceArrayItems: typeof replaceArrayItems;
|
|
16
45
|
string: (args?: {
|
|
17
46
|
nullable?: boolean;
|
|
18
47
|
default?: string | (() => string);
|
|
@@ -37,11 +66,8 @@ export declare const fields: {
|
|
|
37
66
|
/** Add some docs to your field which will annotate the generated typing */
|
|
38
67
|
documentation?: string;
|
|
39
68
|
}) => StorageAnyFieldSchema<TShape>;
|
|
40
|
-
map:
|
|
41
|
-
|
|
42
|
-
/** Add some docs to your field which will annotate the generated typing */
|
|
43
|
-
documentation?: string | undefined;
|
|
44
|
-
}) => StorageMapFieldSchema<T_1>;
|
|
69
|
+
map: typeof mapField;
|
|
70
|
+
replaceMapValues: typeof replaceMapValues;
|
|
45
71
|
file: (args?: {
|
|
46
72
|
nullable?: boolean;
|
|
47
73
|
downloadRemote?: boolean;
|
|
@@ -50,3 +76,4 @@ export declare const fields: {
|
|
|
50
76
|
}) => StorageFileFieldSchema;
|
|
51
77
|
id: () => StorageStringFieldSchema;
|
|
52
78
|
};
|
|
79
|
+
export {};
|
|
@@ -1,10 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
4
11
|
};
|
|
5
|
-
|
|
12
|
+
import cuid from 'cuid';
|
|
13
|
+
function objectField(args) {
|
|
14
|
+
const { properties, fields } = args, resolvedArgs = __rest(args, ["properties", "fields"]);
|
|
15
|
+
const props = properties || fields;
|
|
16
|
+
if (!props) {
|
|
17
|
+
throw new Error('objectField must be passed a properties object');
|
|
18
|
+
}
|
|
19
|
+
return Object.assign(Object.assign({ type: 'object' }, resolvedArgs), { properties: props });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Used for recursively defined field schemas. Replaces the original properties
|
|
23
|
+
* of an object field with the provided fields. This will mutate the original field.
|
|
24
|
+
*/
|
|
25
|
+
function replaceObjectFields(object, fields) {
|
|
26
|
+
object.properties = fields;
|
|
27
|
+
return object;
|
|
28
|
+
}
|
|
29
|
+
function arrayField(args) {
|
|
6
30
|
return Object.assign({ type: 'array' }, args);
|
|
7
|
-
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Used for recursively defined field schemas. Replaces the original items
|
|
34
|
+
* of an array field with the provided items. This will mutate the original field.
|
|
35
|
+
*/
|
|
36
|
+
function replaceArrayItems(array, items) {
|
|
37
|
+
array.items = items;
|
|
38
|
+
return array;
|
|
39
|
+
}
|
|
8
40
|
const stringField = (args) => {
|
|
9
41
|
return Object.assign({ type: 'string' }, args);
|
|
10
42
|
};
|
|
@@ -17,9 +49,17 @@ const booleanField = (args) => {
|
|
|
17
49
|
const anyField = (args) => {
|
|
18
50
|
return Object.assign({ type: 'any' }, args);
|
|
19
51
|
};
|
|
20
|
-
|
|
52
|
+
function mapField(args) {
|
|
21
53
|
return Object.assign({ type: 'map' }, args);
|
|
22
|
-
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Used for recursively defined field schemas. Replaces the original values
|
|
57
|
+
* of a map field with the provided values. This will mutate the original field.
|
|
58
|
+
*/
|
|
59
|
+
function replaceMapValues(map, values) {
|
|
60
|
+
map.values = values;
|
|
61
|
+
return map;
|
|
62
|
+
}
|
|
23
63
|
const fileField = (args) => {
|
|
24
64
|
return Object.assign({ type: 'file' }, args);
|
|
25
65
|
};
|
|
@@ -36,11 +76,14 @@ const idField = () => {
|
|
|
36
76
|
export const fields = {
|
|
37
77
|
object: objectField,
|
|
38
78
|
array: arrayField,
|
|
79
|
+
replaceObjectFields,
|
|
80
|
+
replaceArrayItems,
|
|
39
81
|
string: stringField,
|
|
40
82
|
number: numberField,
|
|
41
83
|
boolean: booleanField,
|
|
42
84
|
any: anyField,
|
|
43
85
|
map: mapField,
|
|
86
|
+
replaceMapValues,
|
|
44
87
|
file: fileField,
|
|
45
88
|
id: idField,
|
|
46
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldHelpers.js","sourceRoot":"","sources":["../../../src/schema/fieldHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"fieldHelpers.js","sourceRoot":"","sources":["../../../src/schema/fieldHelpers.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AA2BxB,SAAS,WAAW,CACnB,IAA4B;IAE5B,MAAM,EAAE,UAAU,EAAE,MAAM,KAAsB,IAAI,EAArB,YAAY,UAAK,IAAI,EAA9C,wBAAuC,CAAO,CAAC;IACrD,MAAM,KAAK,GAAG,UAAU,IAAI,MAAM,CAAC;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACnE,CAAC;IACD,qCACC,IAAI,EAAE,QAAQ,IACX,YAAY,KACf,UAAU,EAAE,KAAK,IAChB;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC3B,MAAqC,EACrC,MAA2B;IAE3B,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;IAC3B,OAAO,MAAM,CAAC;AACf,CAAC;AASD,SAAS,UAAU,CAClB,IAAuB;IAEvB,uBACC,IAAI,EAAE,OAAO,IACV,IAAI,EACN;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,iBAAiB,CACzB,KAAmC,EACnC,KAAyB;IAEzB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,IAMpB,EAA4B,EAAE;IAC9B,uBACC,IAAI,EAAE,QAAQ,IACX,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAKpB,EAA4B,EAAE;IAC9B,uBACC,IAAI,EAAE,QAAQ,IACX,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAKrB,EAA6B,EAAE;IAC/B,uBACC,IAAI,EAAE,SAAS,IACZ,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAS,IAIzB,EAAiC,EAAE;IACnC,uBACC,IAAI,EAAE,KAAK,IACR,IAAI,EACN;AACH,CAAC,CAAC;AAOF,SAAS,QAAQ,CAChB,IAAqB;IAErB,uBACC,IAAI,EAAE,KAAK,IACR,IAAI,EACN;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACxB,GAA+B,EAC/B,MAA0B;IAE1B,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,IAKlB,EAA0B,EAAE;IAC5B,uBACC,IAAI,EAAE,MAAM,IACT,IAAI,EACN;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,GAAG,GAA6B,EAAE;IAC9C,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,IAAI;KACb,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,UAAU;IACjB,mBAAmB;IACnB,iBAAiB;IACjB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,gBAAgB;IAChB,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,OAAO;CACX,CAAC"}
|
|
@@ -7,52 +7,56 @@ export declare namespace schema {
|
|
|
7
7
|
var collection: typeof import("./index.js").collection;
|
|
8
8
|
var fields: {
|
|
9
9
|
object: <Props extends StorageFieldsSchema>(args: {
|
|
10
|
-
properties
|
|
11
|
-
|
|
10
|
+
properties?: Props | undefined;
|
|
11
|
+
fields?: Props | undefined;
|
|
12
|
+
nullable?: boolean;
|
|
12
13
|
default?: import("./types.js").ShapeFromFieldsWithDefaults<Props> | (() => import("./types.js").ShapeFromFieldsWithDefaults<Props>) | undefined;
|
|
13
|
-
documentation?: string
|
|
14
|
+
documentation?: string;
|
|
14
15
|
}) => import("./types.js").StorageObjectFieldSchema<Props>;
|
|
15
16
|
array: <T extends import("./types.js").StorageFieldSchema>(args: {
|
|
16
17
|
items: T;
|
|
17
|
-
nullable?: boolean
|
|
18
|
-
documentation?: string
|
|
18
|
+
nullable?: boolean;
|
|
19
|
+
documentation?: string;
|
|
19
20
|
}) => import("./types.js").StorageArrayFieldSchema<T>;
|
|
21
|
+
replaceObjectFields: (object: import("./types.js").StorageObjectFieldSchema<any>, fields: StorageFieldsSchema) => import("./types.js").StorageObjectFieldSchema<any>;
|
|
22
|
+
replaceArrayItems: (array: import("./types.js").StorageArrayFieldSchema<any>, items: import("./types.js").StorageFieldSchema) => import("./types.js").StorageArrayFieldSchema<any>;
|
|
20
23
|
string: (args?: {
|
|
21
|
-
nullable?: boolean
|
|
22
|
-
default?: string | (() => string)
|
|
23
|
-
options?: string[]
|
|
24
|
-
documentation?: string
|
|
25
|
-
}
|
|
24
|
+
nullable?: boolean;
|
|
25
|
+
default?: string | (() => string);
|
|
26
|
+
options?: string[];
|
|
27
|
+
documentation?: string;
|
|
28
|
+
}) => import("./types.js").StorageStringFieldSchema;
|
|
26
29
|
number: (args?: {
|
|
27
|
-
nullable?: boolean
|
|
28
|
-
default?: number | (() => number)
|
|
29
|
-
documentation?: string
|
|
30
|
-
}
|
|
30
|
+
nullable?: boolean;
|
|
31
|
+
default?: number | (() => number);
|
|
32
|
+
documentation?: string;
|
|
33
|
+
}) => import("./types.js").StorageNumberFieldSchema;
|
|
31
34
|
boolean: (args?: {
|
|
32
|
-
nullable?: boolean
|
|
33
|
-
default?: boolean | (() => boolean)
|
|
34
|
-
documentation?: string
|
|
35
|
-
}
|
|
35
|
+
nullable?: boolean;
|
|
36
|
+
default?: boolean | (() => boolean);
|
|
37
|
+
documentation?: string;
|
|
38
|
+
}) => import("./types.js").StorageBooleanFieldSchema;
|
|
36
39
|
any: <TShape>(args?: {
|
|
37
|
-
default?: TShape
|
|
38
|
-
documentation?: string
|
|
39
|
-
}
|
|
40
|
-
map: <
|
|
41
|
-
values:
|
|
42
|
-
documentation?: string
|
|
43
|
-
}) => import("./types.js").StorageMapFieldSchema<
|
|
40
|
+
default?: TShape;
|
|
41
|
+
documentation?: string;
|
|
42
|
+
}) => import("./types.js").StorageAnyFieldSchema<TShape>;
|
|
43
|
+
map: <T extends import("./types.js").StorageFieldSchema>(args: {
|
|
44
|
+
values: T;
|
|
45
|
+
documentation?: string;
|
|
46
|
+
}) => import("./types.js").StorageMapFieldSchema<T>;
|
|
47
|
+
replaceMapValues: (map: import("./types.js").StorageMapFieldSchema<any>, values: import("./types.js").StorageFieldSchema) => import("./types.js").StorageMapFieldSchema<any>;
|
|
44
48
|
file: (args?: {
|
|
45
|
-
nullable?: boolean
|
|
46
|
-
downloadRemote?: boolean
|
|
47
|
-
documentation?: string
|
|
48
|
-
}
|
|
49
|
+
nullable?: boolean;
|
|
50
|
+
downloadRemote?: boolean;
|
|
51
|
+
documentation?: string;
|
|
52
|
+
}) => import("./types.js").StorageFileFieldSchema;
|
|
49
53
|
id: () => import("./types.js").StorageStringFieldSchema;
|
|
50
54
|
};
|
|
51
55
|
var generated: {
|
|
52
56
|
id: (() => string) & {
|
|
53
|
-
slug: () => string;
|
|
54
|
-
isCuid: (cuid: string) => boolean;
|
|
55
|
-
isSlug: (slug: string) => boolean;
|
|
57
|
+
slug: (() => string);
|
|
58
|
+
isCuid: ((cuid: string) => boolean);
|
|
59
|
+
isSlug: ((slug: string) => boolean);
|
|
56
60
|
};
|
|
57
61
|
};
|
|
58
62
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { StorageCollectionSchema } from './collection.js';
|
|
3
2
|
import { StorageArrayFieldSchema, StorageFieldSchema, StorageFieldsSchema, StorageMapFieldSchema, StorageObjectFieldSchema } from './fields.js';
|
|
4
3
|
type StoragePropertyIsNullable<T extends StorageFieldSchema> = T extends {
|
package/package.json
CHANGED
|
@@ -13,32 +13,72 @@ import {
|
|
|
13
13
|
StorageStringFieldSchema,
|
|
14
14
|
} from './types.js';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
type ObjectFieldArgs<Props extends StorageFieldsSchema> = {
|
|
17
|
+
/** @deprecated - use fields. renamed for more consistency with collection root. */
|
|
18
|
+
properties?: Props;
|
|
19
|
+
fields?: Props;
|
|
18
20
|
nullable?: boolean;
|
|
19
21
|
default?:
|
|
20
22
|
| ShapeFromFieldsWithDefaults<Props>
|
|
21
23
|
| (() => ShapeFromFieldsWithDefaults<Props>);
|
|
22
24
|
/** Add some docs to your field which will annotate the generated typing */
|
|
23
25
|
documentation?: string;
|
|
24
|
-
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function objectField<Props extends StorageFieldsSchema>(
|
|
29
|
+
args: ObjectFieldArgs<Props>,
|
|
30
|
+
): StorageObjectFieldSchema<Props> {
|
|
31
|
+
const { properties, fields, ...resolvedArgs } = args;
|
|
32
|
+
const props = properties || fields;
|
|
33
|
+
if (!props) {
|
|
34
|
+
throw new Error('objectField must be passed a properties object');
|
|
35
|
+
}
|
|
25
36
|
return {
|
|
26
37
|
type: 'object',
|
|
27
|
-
...
|
|
38
|
+
...resolvedArgs,
|
|
39
|
+
properties: props,
|
|
28
40
|
};
|
|
29
|
-
}
|
|
41
|
+
}
|
|
30
42
|
|
|
31
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Used for recursively defined field schemas. Replaces the original properties
|
|
45
|
+
* of an object field with the provided fields. This will mutate the original field.
|
|
46
|
+
*/
|
|
47
|
+
function replaceObjectFields(
|
|
48
|
+
object: StorageObjectFieldSchema<any>,
|
|
49
|
+
fields: StorageFieldsSchema,
|
|
50
|
+
): StorageObjectFieldSchema<any> {
|
|
51
|
+
object.properties = fields;
|
|
52
|
+
return object;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type ArrayFieldArgs<T extends StorageFieldSchema> = {
|
|
32
56
|
items: T;
|
|
33
57
|
nullable?: boolean;
|
|
34
58
|
/** Add some docs to your field which will annotate the generated typing */
|
|
35
59
|
documentation?: string;
|
|
36
|
-
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function arrayField<T extends StorageFieldSchema>(
|
|
63
|
+
args: ArrayFieldArgs<T>,
|
|
64
|
+
): StorageArrayFieldSchema<T> {
|
|
37
65
|
return {
|
|
38
66
|
type: 'array',
|
|
39
67
|
...args,
|
|
40
68
|
};
|
|
41
|
-
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Used for recursively defined field schemas. Replaces the original items
|
|
73
|
+
* of an array field with the provided items. This will mutate the original field.
|
|
74
|
+
*/
|
|
75
|
+
function replaceArrayItems(
|
|
76
|
+
array: StorageArrayFieldSchema<any>,
|
|
77
|
+
items: StorageFieldSchema,
|
|
78
|
+
): StorageArrayFieldSchema<any> {
|
|
79
|
+
array.items = items;
|
|
80
|
+
return array;
|
|
81
|
+
}
|
|
42
82
|
|
|
43
83
|
const stringField = (args?: {
|
|
44
84
|
nullable?: boolean;
|
|
@@ -88,16 +128,31 @@ const anyField = <TShape>(args?: {
|
|
|
88
128
|
};
|
|
89
129
|
};
|
|
90
130
|
|
|
91
|
-
|
|
131
|
+
type MapFieldArgs<T extends StorageFieldSchema> = {
|
|
92
132
|
values: T;
|
|
93
133
|
/** Add some docs to your field which will annotate the generated typing */
|
|
94
134
|
documentation?: string;
|
|
95
|
-
}
|
|
135
|
+
};
|
|
136
|
+
function mapField<T extends StorageFieldSchema>(
|
|
137
|
+
args: MapFieldArgs<T>,
|
|
138
|
+
): StorageMapFieldSchema<T> {
|
|
96
139
|
return {
|
|
97
140
|
type: 'map',
|
|
98
141
|
...args,
|
|
99
142
|
};
|
|
100
|
-
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Used for recursively defined field schemas. Replaces the original values
|
|
147
|
+
* of a map field with the provided values. This will mutate the original field.
|
|
148
|
+
*/
|
|
149
|
+
function replaceMapValues(
|
|
150
|
+
map: StorageMapFieldSchema<any>,
|
|
151
|
+
values: StorageFieldSchema,
|
|
152
|
+
): StorageMapFieldSchema<any> {
|
|
153
|
+
map.values = values;
|
|
154
|
+
return map;
|
|
155
|
+
}
|
|
101
156
|
|
|
102
157
|
const fileField = (args?: {
|
|
103
158
|
nullable?: boolean;
|
|
@@ -125,11 +180,14 @@ const idField = (): StorageStringFieldSchema => {
|
|
|
125
180
|
export const fields = {
|
|
126
181
|
object: objectField,
|
|
127
182
|
array: arrayField,
|
|
183
|
+
replaceObjectFields,
|
|
184
|
+
replaceArrayItems,
|
|
128
185
|
string: stringField,
|
|
129
186
|
number: numberField,
|
|
130
187
|
boolean: booleanField,
|
|
131
188
|
any: anyField,
|
|
132
189
|
map: mapField,
|
|
190
|
+
replaceMapValues,
|
|
133
191
|
file: fileField,
|
|
134
192
|
id: idField,
|
|
135
193
|
};
|