@confect/core 1.0.0-next.0
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/CHANGELOG.md +7 -0
- package/LICENSE +7 -0
- package/dist/FunctionSpec.d.ts +95 -0
- package/dist/FunctionSpec.d.ts.map +1 -0
- package/dist/FunctionSpec.js +38 -0
- package/dist/FunctionSpec.js.map +1 -0
- package/dist/GenericId.d.ts +13 -0
- package/dist/GenericId.d.ts.map +1 -0
- package/dist/GenericId.js +15 -0
- package/dist/GenericId.js.map +1 -0
- package/dist/GroupPath.d.ts +33 -0
- package/dist/GroupPath.d.ts.map +1 -0
- package/dist/GroupPath.js +6 -0
- package/dist/GroupPath.js.map +1 -0
- package/dist/GroupSpec.d.ts +32 -0
- package/dist/GroupSpec.d.ts.map +1 -0
- package/dist/GroupSpec.js +49 -0
- package/dist/GroupSpec.js.map +1 -0
- package/dist/PaginationResult.d.ts +20 -0
- package/dist/PaginationResult.d.ts.map +1 -0
- package/dist/PaginationResult.js +16 -0
- package/dist/PaginationResult.js.map +1 -0
- package/dist/Ref.d.ts +40 -0
- package/dist/Ref.d.ts.map +1 -0
- package/dist/Ref.js +20 -0
- package/dist/Ref.js.map +1 -0
- package/dist/Refs.d.ts +22 -0
- package/dist/Refs.d.ts.map +1 -0
- package/dist/Refs.js +24 -0
- package/dist/Refs.js.map +1 -0
- package/dist/Spec.d.ts +23 -0
- package/dist/Spec.d.ts.map +1 -0
- package/dist/Spec.js +23 -0
- package/dist/Spec.js.map +1 -0
- package/dist/SystemFields.d.ts +28 -0
- package/dist/SystemFields.d.ts.map +1 -0
- package/dist/SystemFields.js +24 -0
- package/dist/SystemFields.js.map +1 -0
- package/dist/Types.d.ts +35 -0
- package/dist/Types.d.ts.map +1 -0
- package/dist/Types.js +6 -0
- package/dist/Types.js.map +1 -0
- package/dist/UserIdentity.d.ts +65 -0
- package/dist/UserIdentity.d.ts.map +1 -0
- package/dist/UserIdentity.js +32 -0
- package/dist/UserIdentity.js.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +13 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/internal/utils.d.ts +5 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +68 -0
- package/dist/internal/utils.js.map +1 -0
- package/package.json +73 -0
- package/src/FunctionSpec.ts +153 -0
- package/src/GenericId.ts +18 -0
- package/src/GroupPath.ts +61 -0
- package/src/GroupSpec.ts +120 -0
- package/src/PaginationResult.ts +21 -0
- package/src/Ref.ts +175 -0
- package/src/Refs.ts +99 -0
- package/src/Spec.ts +52 -0
- package/src/SystemFields.ts +51 -0
- package/src/Types.ts +166 -0
- package/src/UserIdentity.ts +28 -0
- package/src/index.ts +11 -0
- package/src/internal/utils.ts +86 -0
package/src/Types.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DocumentByName,
|
|
3
|
+
FieldTypeFromFieldPath,
|
|
4
|
+
GenericDatabaseReader,
|
|
5
|
+
GenericDataModel,
|
|
6
|
+
TableNamesInDataModel,
|
|
7
|
+
} from "convex/server";
|
|
8
|
+
import type { GenericId } from "convex/values";
|
|
9
|
+
import type { Brand } from "effect";
|
|
10
|
+
|
|
11
|
+
export type IsOptional<T, K extends keyof T> =
|
|
12
|
+
{} extends Pick<T, K> ? true : false;
|
|
13
|
+
|
|
14
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
15
|
+
|
|
16
|
+
export type IsUnion<T, U extends T = T> = T extends unknown
|
|
17
|
+
? [U] extends [T]
|
|
18
|
+
? false
|
|
19
|
+
: true
|
|
20
|
+
: never;
|
|
21
|
+
|
|
22
|
+
// https://stackoverflow.com/a/52806744
|
|
23
|
+
export type IsValueLiteral<Vl> = [Vl] extends [never]
|
|
24
|
+
? never
|
|
25
|
+
: IsUnion<Vl> extends true
|
|
26
|
+
? false
|
|
27
|
+
: [Vl] extends [string | number | bigint | boolean]
|
|
28
|
+
? [string] extends [Vl]
|
|
29
|
+
? false
|
|
30
|
+
: [number] extends [Vl]
|
|
31
|
+
? false
|
|
32
|
+
: [boolean] extends [Vl]
|
|
33
|
+
? false
|
|
34
|
+
: [bigint] extends [Vl]
|
|
35
|
+
? false
|
|
36
|
+
: true
|
|
37
|
+
: false;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Only checks for records with string keys.
|
|
41
|
+
*/
|
|
42
|
+
export type IsRecord<T> = [T] extends [never]
|
|
43
|
+
? false
|
|
44
|
+
: IsUnion<T> extends true
|
|
45
|
+
? false
|
|
46
|
+
: T extends Record<string, infer V>
|
|
47
|
+
? string extends keyof T
|
|
48
|
+
? keyof T extends string
|
|
49
|
+
? T extends Record<string, V>
|
|
50
|
+
? Record<string, V> extends T
|
|
51
|
+
? true
|
|
52
|
+
: false
|
|
53
|
+
: false
|
|
54
|
+
: false
|
|
55
|
+
: false
|
|
56
|
+
: false;
|
|
57
|
+
|
|
58
|
+
export type DeepMutable<T> =
|
|
59
|
+
IsAny<T> extends true
|
|
60
|
+
? any
|
|
61
|
+
: T extends Brand.Brand<any> | GenericId<any>
|
|
62
|
+
? T
|
|
63
|
+
: T extends ReadonlyMap<infer K, infer V>
|
|
64
|
+
? Map<DeepMutable<K>, DeepMutable<V>>
|
|
65
|
+
: T extends ReadonlySet<infer V>
|
|
66
|
+
? Set<DeepMutable<V>>
|
|
67
|
+
: [keyof T] extends [never]
|
|
68
|
+
? T
|
|
69
|
+
: { -readonly [K in keyof T]: DeepMutable<T[K]> };
|
|
70
|
+
|
|
71
|
+
export type DeepReadonly<T> =
|
|
72
|
+
IsAny<T> extends true
|
|
73
|
+
? any
|
|
74
|
+
: T extends Map<infer K, infer V>
|
|
75
|
+
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
|
76
|
+
: T extends Set<infer V>
|
|
77
|
+
? ReadonlySet<DeepReadonly<V>>
|
|
78
|
+
: [keyof T] extends [never]
|
|
79
|
+
? T
|
|
80
|
+
: { readonly [K in keyof T]: DeepReadonly<T[K]> };
|
|
81
|
+
|
|
82
|
+
export type TypeError<Message extends string, T = never> = [Message, T];
|
|
83
|
+
|
|
84
|
+
export type TypeDefect<Message extends string, T = never> = TypeError<
|
|
85
|
+
`Unexpected type error:\n ${Message}`,
|
|
86
|
+
T
|
|
87
|
+
>;
|
|
88
|
+
|
|
89
|
+
export type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
|
|
90
|
+
|
|
91
|
+
type DetectCycle<T, Cache extends any[] = []> =
|
|
92
|
+
IsAny<T> extends true
|
|
93
|
+
? false
|
|
94
|
+
: [T] extends [any]
|
|
95
|
+
? T extends Cache[number]
|
|
96
|
+
? true
|
|
97
|
+
: T extends Array<infer U>
|
|
98
|
+
? DetectCycle<U, [...Cache, T]>
|
|
99
|
+
: T extends Map<infer _U, infer V>
|
|
100
|
+
? DetectCycle<V, [...Cache, T]>
|
|
101
|
+
: T extends Set<infer U>
|
|
102
|
+
? DetectCycle<U, [...Cache, T]>
|
|
103
|
+
: T extends object
|
|
104
|
+
? true extends {
|
|
105
|
+
[K in keyof T]: DetectCycle<T[K], [...Cache, T]>;
|
|
106
|
+
}[keyof T]
|
|
107
|
+
? true
|
|
108
|
+
: false
|
|
109
|
+
: false
|
|
110
|
+
: never;
|
|
111
|
+
|
|
112
|
+
//////////////////////////////////
|
|
113
|
+
// START: Vendored from Arktype //
|
|
114
|
+
//////////////////////////////////
|
|
115
|
+
|
|
116
|
+
// https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9
|
|
117
|
+
|
|
118
|
+
export type UnionToTuple<t> =
|
|
119
|
+
_unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;
|
|
120
|
+
|
|
121
|
+
type _unionToTuple<t, result extends unknown[]> =
|
|
122
|
+
getLastBranch<t> extends infer current
|
|
123
|
+
? [t] extends [never]
|
|
124
|
+
? result
|
|
125
|
+
: _unionToTuple<Exclude<t, current>, [current, ...result]>
|
|
126
|
+
: never;
|
|
127
|
+
|
|
128
|
+
type getLastBranch<t> =
|
|
129
|
+
intersectUnion<t extends unknown ? (x: t) => void : never> extends (
|
|
130
|
+
x: infer branch,
|
|
131
|
+
) => void
|
|
132
|
+
? branch
|
|
133
|
+
: never;
|
|
134
|
+
|
|
135
|
+
type intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends (
|
|
136
|
+
_: infer intersection,
|
|
137
|
+
) => void
|
|
138
|
+
? intersection
|
|
139
|
+
: never;
|
|
140
|
+
|
|
141
|
+
type conform<t, base> = t extends base ? t : base;
|
|
142
|
+
|
|
143
|
+
////////////////////////////////
|
|
144
|
+
// END: Vendored from Arktype //
|
|
145
|
+
////////////////////////////////
|
|
146
|
+
|
|
147
|
+
export type IndexFieldTypesForEq<
|
|
148
|
+
ConvexDataModel extends GenericDataModel,
|
|
149
|
+
Table extends TableNamesInDataModel<ConvexDataModel>,
|
|
150
|
+
T extends string[],
|
|
151
|
+
> = T extends readonly [...infer Rest, any]
|
|
152
|
+
? Rest extends readonly string[]
|
|
153
|
+
? {
|
|
154
|
+
[K in keyof Rest]: FieldTypeFromFieldPath<
|
|
155
|
+
DocumentByName<ConvexDataModel, Table>,
|
|
156
|
+
Rest[K]
|
|
157
|
+
>;
|
|
158
|
+
}
|
|
159
|
+
: never
|
|
160
|
+
: never;
|
|
161
|
+
|
|
162
|
+
// Would prefer to use `BaseDatabaseReader` from the `convex` package, but it's not exported.
|
|
163
|
+
export type BaseDatabaseReader<DataModel extends GenericDataModel> = {
|
|
164
|
+
get: GenericDatabaseReader<DataModel>["get"];
|
|
165
|
+
query: GenericDatabaseReader<DataModel>["query"];
|
|
166
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export const UserIdentity = <CustomClaimsFields extends Schema.Struct.Fields>(
|
|
4
|
+
customClaimsFields: CustomClaimsFields,
|
|
5
|
+
) =>
|
|
6
|
+
Schema.Struct({
|
|
7
|
+
...customClaimsFields,
|
|
8
|
+
tokenIdentifier: Schema.String,
|
|
9
|
+
subject: Schema.String,
|
|
10
|
+
issuer: Schema.String,
|
|
11
|
+
name: Schema.optionalWith(Schema.String, { exact: true }),
|
|
12
|
+
givenName: Schema.optionalWith(Schema.String, { exact: true }),
|
|
13
|
+
familyName: Schema.optionalWith(Schema.String, { exact: true }),
|
|
14
|
+
nickname: Schema.optionalWith(Schema.String, { exact: true }),
|
|
15
|
+
preferredUsername: Schema.optionalWith(Schema.String, { exact: true }),
|
|
16
|
+
profileUrl: Schema.optionalWith(Schema.String, { exact: true }),
|
|
17
|
+
pictureUrl: Schema.optionalWith(Schema.String, { exact: true }),
|
|
18
|
+
email: Schema.optionalWith(Schema.String, { exact: true }),
|
|
19
|
+
emailVerified: Schema.optionalWith(Schema.Boolean, { exact: true }),
|
|
20
|
+
gender: Schema.optionalWith(Schema.String, { exact: true }),
|
|
21
|
+
birthday: Schema.optionalWith(Schema.String, { exact: true }),
|
|
22
|
+
timezone: Schema.optionalWith(Schema.String, { exact: true }),
|
|
23
|
+
language: Schema.optionalWith(Schema.String, { exact: true }),
|
|
24
|
+
phoneNumber: Schema.optionalWith(Schema.String, { exact: true }),
|
|
25
|
+
phoneNumberVerified: Schema.optionalWith(Schema.Boolean, { exact: true }),
|
|
26
|
+
address: Schema.optionalWith(Schema.String, { exact: true }),
|
|
27
|
+
updatedAt: Schema.optionalWith(Schema.String, { exact: true }),
|
|
28
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * as FunctionSpec from "./FunctionSpec";
|
|
2
|
+
export * as GenericId from "./GenericId";
|
|
3
|
+
export * as GroupPath from "./GroupPath";
|
|
4
|
+
export * as GroupSpec from "./GroupSpec";
|
|
5
|
+
export * as PaginationResult from "./PaginationResult";
|
|
6
|
+
export * as Ref from "./Ref";
|
|
7
|
+
export * as Refs from "./Refs";
|
|
8
|
+
export * as Spec from "./Spec";
|
|
9
|
+
export * as SystemFields from "./SystemFields";
|
|
10
|
+
export * as Types from "./Types";
|
|
11
|
+
export * as UserIdentity from "./UserIdentity";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const RESERVED_JS_IDENTIFIERS = new Set([
|
|
2
|
+
// Reserved keywords
|
|
3
|
+
"break",
|
|
4
|
+
"case",
|
|
5
|
+
"catch",
|
|
6
|
+
"class",
|
|
7
|
+
"const",
|
|
8
|
+
"continue",
|
|
9
|
+
"debugger",
|
|
10
|
+
"default",
|
|
11
|
+
"delete",
|
|
12
|
+
"do",
|
|
13
|
+
"else",
|
|
14
|
+
"export",
|
|
15
|
+
"extends",
|
|
16
|
+
"finally",
|
|
17
|
+
"for",
|
|
18
|
+
"function",
|
|
19
|
+
"if",
|
|
20
|
+
"import",
|
|
21
|
+
"in",
|
|
22
|
+
"instanceof",
|
|
23
|
+
"new",
|
|
24
|
+
"return",
|
|
25
|
+
"super",
|
|
26
|
+
"switch",
|
|
27
|
+
"this",
|
|
28
|
+
"throw",
|
|
29
|
+
"try",
|
|
30
|
+
"typeof",
|
|
31
|
+
"var",
|
|
32
|
+
"void",
|
|
33
|
+
"while",
|
|
34
|
+
"with",
|
|
35
|
+
"yield",
|
|
36
|
+
// Future reserved keywords
|
|
37
|
+
"await",
|
|
38
|
+
"enum",
|
|
39
|
+
"implements",
|
|
40
|
+
"interface",
|
|
41
|
+
"let",
|
|
42
|
+
"package",
|
|
43
|
+
"private",
|
|
44
|
+
"protected",
|
|
45
|
+
"public",
|
|
46
|
+
"static",
|
|
47
|
+
// Literal values that cannot be reassigned
|
|
48
|
+
"null",
|
|
49
|
+
"true",
|
|
50
|
+
"false",
|
|
51
|
+
// Global objects that shouldn't be shadowed
|
|
52
|
+
"undefined",
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const RESERVED_CONVEX_FILE_NAMES = new Set(["schema", "http", "crons"]);
|
|
56
|
+
|
|
57
|
+
const jsIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
58
|
+
|
|
59
|
+
const isReservedJsIdentifier = (identifier: string) =>
|
|
60
|
+
RESERVED_JS_IDENTIFIERS.has(identifier);
|
|
61
|
+
|
|
62
|
+
const isReservedConvexFileName = (fileName: string) =>
|
|
63
|
+
RESERVED_CONVEX_FILE_NAMES.has(fileName);
|
|
64
|
+
|
|
65
|
+
const matchesJsIdentifierPattern = (identifier: string) =>
|
|
66
|
+
jsIdentifierRegex.test(identifier);
|
|
67
|
+
|
|
68
|
+
export const validateConfectFunctionIdentifier = (identifier: string) => {
|
|
69
|
+
if (!matchesJsIdentifierPattern(identifier)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Expected a valid Confect function identifier, but received: "${identifier}". Valid identifiers must start with a letter, underscore, or dollar sign, and can only contain letters, numbers, underscores, or dollar signs.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isReservedJsIdentifier(identifier)) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved JavaScript identifier.`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isReservedConvexFileName(identifier)) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved Convex file name.`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|