@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/dist/Spec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Spec.js","names":[],"sources":["../src/Spec.ts"],"sourcesContent":["import { Predicate, Record } from \"effect\";\nimport type * as GroupSpec from \"./GroupSpec\";\n\nexport const TypeId = \"@confect/core/api/Spec\";\nexport type TypeId = typeof TypeId;\n\nexport const isSpec = (u: unknown): u is AnyWithProps =>\n Predicate.hasProperty(u, TypeId);\n\nexport interface Spec<Groups_ extends GroupSpec.AnyWithProps = never> {\n readonly [TypeId]: TypeId;\n readonly groups: {\n [GroupName in GroupSpec.Name<Groups_>]: GroupSpec.WithName<\n Groups_,\n GroupName\n >;\n };\n\n add<Group extends GroupSpec.AnyWithProps>(\n group: Group,\n ): Spec<Groups_ | Group>;\n}\n\nexport interface Any {\n readonly [TypeId]: TypeId;\n}\n\nexport interface AnyWithProps extends Spec<GroupSpec.AnyWithProps> {}\n\nexport type Groups<Spec_ extends AnyWithProps> =\n Spec_[\"groups\"][keyof Spec_[\"groups\"]];\n\nconst Proto = {\n [TypeId]: TypeId,\n\n add<Group extends GroupSpec.AnyWithProps>(this: AnyWithProps, group: Group) {\n return makeProto({\n groups: Record.set(this.groups, group.name, group),\n });\n },\n};\n\nconst makeProto = <Groups_ extends GroupSpec.AnyWithProps>({\n groups,\n}: {\n groups: Record.ReadonlyRecord<string, Groups_>;\n}): Spec<Groups_> =>\n Object.assign(Object.create(Proto), {\n groups,\n });\n\nexport const make = (): Spec => makeProto({ groups: {} });\n"],"mappings":";;;;;;;;;AAGA,MAAa,SAAS;AAGtB,MAAa,UAAU,MACrB,UAAU,YAAY,GAAG,OAAO;AAyBlC,MAAM,QAAQ;EACX,SAAS;CAEV,IAA8D,OAAc;AAC1E,SAAO,UAAU,EACf,QAAQ,OAAO,IAAI,KAAK,QAAQ,MAAM,MAAM,MAAM,EACnD,CAAC;;CAEL;AAED,MAAM,aAAqD,EACzD,aAIA,OAAO,OAAO,OAAO,OAAO,MAAM,EAAE,EAClC,QACD,CAAC;AAEJ,MAAa,aAAmB,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GenericId } from "./GenericId.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { Expand, IdField, SystemFields as SystemFields$1 } from "convex/server";
|
|
4
|
+
|
|
5
|
+
//#region src/SystemFields.d.ts
|
|
6
|
+
declare namespace SystemFields_d_exports {
|
|
7
|
+
export { ExtendWithSystemFields, SystemFields, WithSystemFields, extendWithSystemFields };
|
|
8
|
+
}
|
|
9
|
+
type SystemFieldsSchema<TableName extends string> = Schema.Struct<{
|
|
10
|
+
_id: Schema.Schema<GenericId<TableName>, GenericId<TableName>, never>;
|
|
11
|
+
_creationTime: typeof Schema.Number;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Produces a schema for Convex system fields.
|
|
15
|
+
*/
|
|
16
|
+
declare const SystemFields: <TableName extends string>(tableName: TableName) => SystemFieldsSchema<TableName>;
|
|
17
|
+
/**
|
|
18
|
+
* Extend a table schema with Convex system fields.
|
|
19
|
+
*/
|
|
20
|
+
declare const extendWithSystemFields: <TableName extends string, TableSchema extends Schema.Schema.AnyNoContext>(tableName: TableName, schema: TableSchema) => ExtendWithSystemFields<TableName, TableSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* Extend a table schema with Convex system fields at the type level.
|
|
23
|
+
*/
|
|
24
|
+
type ExtendWithSystemFields<TableName extends string, TableSchema extends Schema.Schema.AnyNoContext> = Schema.extend<SystemFieldsSchema<TableName>, TableSchema>;
|
|
25
|
+
type WithSystemFields<TableName extends string, Document> = Expand<Readonly<IdField<TableName>> & Readonly<SystemFields$1> & Document>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ExtendWithSystemFields, SystemFields, SystemFields_d_exports, WithSystemFields, extendWithSystemFields };
|
|
28
|
+
//# sourceMappingURL=SystemFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemFields.d.ts","names":[],"sources":["../src/SystemFields.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAQK,+CAA+C,MAAA,CAAO;OACpD,MAAA,CAAO,OACV,UAAoB,YACpB,UAAoB;wBAGA,MAAA,CAAO;;;;;cAMlB,oDACA,cACV,mBAAmB;;AAhBmB;;AAIrC,cAqBS,sBArBT,EAAA,CAAA,kBAAA,MAAA,EAAA,oBAuBkB,MAAA,CAAO,MAAA,CAAO,YAvBhC,CAAA,CAAA,SAAA,EAyBS,SAzBT,EAAA,MAAA,EA0BM,WA1BN,EAAA,GA2BD,sBA3BC,CA2BsB,SA3BtB,EA2BiC,WA3BjC,CAAA;;;;AAIoB,KA6BZ,sBA7BmB,CAAA,kBAAA,MAAA,EAAA,oBA+BT,MAAA,CAAO,MAAA,CAAO,YA/BL,CAAA,GAgC3B,MAAA,CAAO,MAhCoB,CAgCb,kBAhCa,CAgCM,SAhCN,CAAA,EAgCkB,WAhClB,CAAA;AANqB,KAwCxC,gBAxC+C,CAAA,kBAAA,MAAA,EAAA,QAAA,CAAA,GAwCQ,MAxCR,CAyCzD,QAzCyD,CAyChD,OAzCgD,CAyCxC,SAzCwC,CAAA,CAAA,GAyC1B,QAzC0B,CAyCjB,cAzCiB,CAAA,GAyCI,QAzCJ,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { GenericId } from "./GenericId.js";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/SystemFields.ts
|
|
6
|
+
var SystemFields_exports = /* @__PURE__ */ __export({
|
|
7
|
+
SystemFields: () => SystemFields,
|
|
8
|
+
extendWithSystemFields: () => extendWithSystemFields
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Produces a schema for Convex system fields.
|
|
12
|
+
*/
|
|
13
|
+
const SystemFields = (tableName) => Schema.Struct({
|
|
14
|
+
_id: GenericId(tableName),
|
|
15
|
+
_creationTime: Schema.Number
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Extend a table schema with Convex system fields.
|
|
19
|
+
*/
|
|
20
|
+
const extendWithSystemFields = (tableName, schema) => Schema.extend(SystemFields(tableName), schema);
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { SystemFields, SystemFields_exports, extendWithSystemFields };
|
|
24
|
+
//# sourceMappingURL=SystemFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemFields.js","names":["GenericId.GenericId"],"sources":["../src/SystemFields.ts"],"sourcesContent":["import type {\n Expand,\n IdField,\n SystemFields as NonIdSystemFields,\n} from \"convex/server\";\nimport { Schema } from \"effect\";\nimport * as GenericId from \"./GenericId\";\n\ntype SystemFieldsSchema<TableName extends string> = Schema.Struct<{\n _id: Schema.Schema<\n GenericId.GenericId<TableName>,\n GenericId.GenericId<TableName>,\n never\n >;\n _creationTime: typeof Schema.Number;\n}>;\n\n/**\n * Produces a schema for Convex system fields.\n */\nexport const SystemFields = <TableName extends string>(\n tableName: TableName,\n): SystemFieldsSchema<TableName> =>\n Schema.Struct({\n _id: GenericId.GenericId(tableName),\n _creationTime: Schema.Number,\n });\n\n/**\n * Extend a table schema with Convex system fields.\n */\nexport const extendWithSystemFields = <\n TableName extends string,\n TableSchema extends Schema.Schema.AnyNoContext,\n>(\n tableName: TableName,\n schema: TableSchema,\n): ExtendWithSystemFields<TableName, TableSchema> =>\n Schema.extend(SystemFields(tableName), schema);\n\n/**\n * Extend a table schema with Convex system fields at the type level.\n */\nexport type ExtendWithSystemFields<\n TableName extends string,\n TableSchema extends Schema.Schema.AnyNoContext,\n> = Schema.extend<SystemFieldsSchema<TableName>, TableSchema>;\n\nexport type WithSystemFields<TableName extends string, Document> = Expand<\n Readonly<IdField<TableName>> & Readonly<NonIdSystemFields> & Document\n>;\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,gBACX,cAEA,OAAO,OAAO;CACZ,KAAKA,UAAoB,UAAU;CACnC,eAAe,OAAO;CACvB,CAAC;;;;AAKJ,MAAa,0BAIX,WACA,WAEA,OAAO,OAAO,aAAa,UAAU,EAAE,OAAO"}
|
package/dist/Types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Brand } from "effect";
|
|
2
|
+
import { DocumentByName, FieldTypeFromFieldPath, GenericDataModel, GenericDatabaseReader, TableNamesInDataModel } from "convex/server";
|
|
3
|
+
import { GenericId } from "convex/values";
|
|
4
|
+
|
|
5
|
+
//#region src/Types.d.ts
|
|
6
|
+
declare namespace Types_d_exports {
|
|
7
|
+
export { BaseDatabaseReader, DeepMutable, DeepReadonly, IndexFieldTypesForEq, IsAny, IsOptional, IsRecord, IsRecursive, IsUnion, IsValueLiteral, TypeDefect, TypeError, UnionToTuple };
|
|
8
|
+
}
|
|
9
|
+
type IsOptional<T, K$1 extends keyof T> = {} extends Pick<T, K$1> ? true : false;
|
|
10
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
11
|
+
type IsUnion<T, U$1 extends T = T> = T extends unknown ? [U$1] extends [T] ? false : true : never;
|
|
12
|
+
type IsValueLiteral<Vl> = [Vl] extends [never] ? never : IsUnion<Vl> extends true ? false : [Vl] extends [string | number | bigint | boolean] ? [string] extends [Vl] ? false : [number] extends [Vl] ? false : [boolean] extends [Vl] ? false : [bigint] extends [Vl] ? false : true : false;
|
|
13
|
+
/**
|
|
14
|
+
* Only checks for records with string keys.
|
|
15
|
+
*/
|
|
16
|
+
type IsRecord<T> = [T] extends [never] ? false : IsUnion<T> extends true ? false : T extends Record<string, infer V> ? string extends keyof T ? keyof T extends string ? T extends Record<string, V> ? Record<string, V> extends T ? true : false : false : false : false : false;
|
|
17
|
+
type DeepMutable<T> = IsAny<T> extends true ? any : T extends Brand.Brand<any> | GenericId<any> ? T : T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>> : T extends ReadonlySet<infer V> ? Set<DeepMutable<V>> : [keyof T] extends [never] ? T : { -readonly [K in keyof T]: DeepMutable<T[K]> };
|
|
18
|
+
type DeepReadonly<T> = IsAny<T> extends true ? any : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer V> ? ReadonlySet<DeepReadonly<V>> : [keyof T] extends [never] ? T : { readonly [K in keyof T]: DeepReadonly<T[K]> };
|
|
19
|
+
type TypeError<Message extends string, T = never> = [Message, T];
|
|
20
|
+
type TypeDefect<Message extends string, T = never> = TypeError<`Unexpected type error:\n ${Message}`, T>;
|
|
21
|
+
type IsRecursive<T> = true extends DetectCycle<T> ? true : false;
|
|
22
|
+
type DetectCycle<T, Cache extends any[] = []> = IsAny<T> extends true ? false : [T] extends [any] ? T extends Cache[number] ? true : T extends Array<infer U> ? DetectCycle<U, [...Cache, T]> : T extends Map<infer _U, infer V> ? DetectCycle<V, [...Cache, T]> : T extends Set<infer U> ? DetectCycle<U, [...Cache, T]> : T extends object ? true extends { [K in keyof T]: DetectCycle<T[K], [...Cache, T]> }[keyof T] ? true : false : false : never;
|
|
23
|
+
type UnionToTuple<t> = _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;
|
|
24
|
+
type _unionToTuple<t, result$1 extends unknown[]> = getLastBranch<t> extends infer current ? [t] extends [never] ? result$1 : _unionToTuple<Exclude<t, current>, [current, ...result$1]> : never;
|
|
25
|
+
type getLastBranch<t> = intersectUnion<t extends unknown ? (x: t) => void : never> extends ((x: infer branch) => void) ? branch : never;
|
|
26
|
+
type intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends ((_: infer intersection) => void) ? intersection : never;
|
|
27
|
+
type conform<t, base> = t extends base ? t : base;
|
|
28
|
+
type IndexFieldTypesForEq<ConvexDataModel extends GenericDataModel, Table extends TableNamesInDataModel<ConvexDataModel>, T extends string[]> = T extends readonly [...infer Rest, any] ? Rest extends readonly string[] ? { [K in keyof Rest]: FieldTypeFromFieldPath<DocumentByName<ConvexDataModel, Table>, Rest[K]> } : never : never;
|
|
29
|
+
type BaseDatabaseReader<DataModel extends GenericDataModel> = {
|
|
30
|
+
get: GenericDatabaseReader<DataModel>["get"];
|
|
31
|
+
query: GenericDatabaseReader<DataModel>["query"];
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { BaseDatabaseReader, DeepMutable, DeepReadonly, IndexFieldTypesForEq, IsAny, IsOptional, IsRecord, IsRecursive, IsUnion, IsValueLiteral, TypeDefect, TypeError, Types_d_exports, UnionToTuple };
|
|
35
|
+
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.d.ts","names":[],"sources":["../src/Types.ts"],"sourcesContent":[],"mappings":"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"}
|
package/dist/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.js","names":[],"sources":["../src/Types.ts"],"sourcesContent":["import type {\n DocumentByName,\n FieldTypeFromFieldPath,\n GenericDatabaseReader,\n GenericDataModel,\n TableNamesInDataModel,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport type { Brand } from \"effect\";\n\nexport type IsOptional<T, K extends keyof T> =\n {} extends Pick<T, K> ? true : false;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\nexport type IsUnion<T, U extends T = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\n\n// https://stackoverflow.com/a/52806744\nexport type IsValueLiteral<Vl> = [Vl] extends [never]\n ? never\n : IsUnion<Vl> extends true\n ? false\n : [Vl] extends [string | number | bigint | boolean]\n ? [string] extends [Vl]\n ? false\n : [number] extends [Vl]\n ? false\n : [boolean] extends [Vl]\n ? false\n : [bigint] extends [Vl]\n ? false\n : true\n : false;\n\n/**\n * Only checks for records with string keys.\n */\nexport type IsRecord<T> = [T] extends [never]\n ? false\n : IsUnion<T> extends true\n ? false\n : T extends Record<string, infer V>\n ? string extends keyof T\n ? keyof T extends string\n ? T extends Record<string, V>\n ? Record<string, V> extends T\n ? true\n : false\n : false\n : false\n : false\n : false;\n\nexport type DeepMutable<T> =\n IsAny<T> extends true\n ? any\n : T extends Brand.Brand<any> | GenericId<any>\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? Map<DeepMutable<K>, DeepMutable<V>>\n : T extends ReadonlySet<infer V>\n ? Set<DeepMutable<V>>\n : [keyof T] extends [never]\n ? T\n : { -readonly [K in keyof T]: DeepMutable<T[K]> };\n\nexport type DeepReadonly<T> =\n IsAny<T> extends true\n ? any\n : T extends Map<infer K, infer V>\n ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>\n : T extends Set<infer V>\n ? ReadonlySet<DeepReadonly<V>>\n : [keyof T] extends [never]\n ? T\n : { readonly [K in keyof T]: DeepReadonly<T[K]> };\n\nexport type TypeError<Message extends string, T = never> = [Message, T];\n\nexport type TypeDefect<Message extends string, T = never> = TypeError<\n `Unexpected type error:\\n ${Message}`,\n T\n>;\n\nexport type IsRecursive<T> = true extends DetectCycle<T> ? true : false;\n\ntype DetectCycle<T, Cache extends any[] = []> =\n IsAny<T> extends true\n ? false\n : [T] extends [any]\n ? T extends Cache[number]\n ? true\n : T extends Array<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends Map<infer _U, infer V>\n ? DetectCycle<V, [...Cache, T]>\n : T extends Set<infer U>\n ? DetectCycle<U, [...Cache, T]>\n : T extends object\n ? true extends {\n [K in keyof T]: DetectCycle<T[K], [...Cache, T]>;\n }[keyof T]\n ? true\n : false\n : false\n : never;\n\n//////////////////////////////////\n// START: Vendored from Arktype //\n//////////////////////////////////\n\n// https://github.com/arktypeio/arktype/blob/2e911d01a741ccee7a17e31ee144049817fabbb8/ark/util/unionToTuple.ts#L9\n\nexport type UnionToTuple<t> =\n _unionToTuple<t, []> extends infer result ? conform<result, t[]> : never;\n\ntype _unionToTuple<t, result extends unknown[]> =\n getLastBranch<t> extends infer current\n ? [t] extends [never]\n ? result\n : _unionToTuple<Exclude<t, current>, [current, ...result]>\n : never;\n\ntype getLastBranch<t> =\n intersectUnion<t extends unknown ? (x: t) => void : never> extends (\n x: infer branch,\n ) => void\n ? branch\n : never;\n\ntype intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends (\n _: infer intersection,\n) => void\n ? intersection\n : never;\n\ntype conform<t, base> = t extends base ? t : base;\n\n////////////////////////////////\n// END: Vendored from Arktype //\n////////////////////////////////\n\nexport type IndexFieldTypesForEq<\n ConvexDataModel extends GenericDataModel,\n Table extends TableNamesInDataModel<ConvexDataModel>,\n T extends string[],\n> = T extends readonly [...infer Rest, any]\n ? Rest extends readonly string[]\n ? {\n [K in keyof Rest]: FieldTypeFromFieldPath<\n DocumentByName<ConvexDataModel, Table>,\n Rest[K]\n >;\n }\n : never\n : never;\n\n// Would prefer to use `BaseDatabaseReader` from the `convex` package, but it's not exported.\nexport type BaseDatabaseReader<DataModel extends GenericDataModel> = {\n get: GenericDatabaseReader<DataModel>[\"get\"];\n query: GenericDatabaseReader<DataModel>[\"query\"];\n};\n"],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/UserIdentity.d.ts
|
|
4
|
+
declare namespace UserIdentity_d_exports {
|
|
5
|
+
export { UserIdentity };
|
|
6
|
+
}
|
|
7
|
+
declare const UserIdentity: <CustomClaimsFields extends Schema.Struct.Fields>(customClaimsFields: CustomClaimsFields) => Schema.Struct<CustomClaimsFields & {
|
|
8
|
+
tokenIdentifier: typeof Schema.String;
|
|
9
|
+
subject: typeof Schema.String;
|
|
10
|
+
issuer: typeof Schema.String;
|
|
11
|
+
name: Schema.optionalWith<typeof Schema.String, {
|
|
12
|
+
exact: true;
|
|
13
|
+
}>;
|
|
14
|
+
givenName: Schema.optionalWith<typeof Schema.String, {
|
|
15
|
+
exact: true;
|
|
16
|
+
}>;
|
|
17
|
+
familyName: Schema.optionalWith<typeof Schema.String, {
|
|
18
|
+
exact: true;
|
|
19
|
+
}>;
|
|
20
|
+
nickname: Schema.optionalWith<typeof Schema.String, {
|
|
21
|
+
exact: true;
|
|
22
|
+
}>;
|
|
23
|
+
preferredUsername: Schema.optionalWith<typeof Schema.String, {
|
|
24
|
+
exact: true;
|
|
25
|
+
}>;
|
|
26
|
+
profileUrl: Schema.optionalWith<typeof Schema.String, {
|
|
27
|
+
exact: true;
|
|
28
|
+
}>;
|
|
29
|
+
pictureUrl: Schema.optionalWith<typeof Schema.String, {
|
|
30
|
+
exact: true;
|
|
31
|
+
}>;
|
|
32
|
+
email: Schema.optionalWith<typeof Schema.String, {
|
|
33
|
+
exact: true;
|
|
34
|
+
}>;
|
|
35
|
+
emailVerified: Schema.optionalWith<typeof Schema.Boolean, {
|
|
36
|
+
exact: true;
|
|
37
|
+
}>;
|
|
38
|
+
gender: Schema.optionalWith<typeof Schema.String, {
|
|
39
|
+
exact: true;
|
|
40
|
+
}>;
|
|
41
|
+
birthday: Schema.optionalWith<typeof Schema.String, {
|
|
42
|
+
exact: true;
|
|
43
|
+
}>;
|
|
44
|
+
timezone: Schema.optionalWith<typeof Schema.String, {
|
|
45
|
+
exact: true;
|
|
46
|
+
}>;
|
|
47
|
+
language: Schema.optionalWith<typeof Schema.String, {
|
|
48
|
+
exact: true;
|
|
49
|
+
}>;
|
|
50
|
+
phoneNumber: Schema.optionalWith<typeof Schema.String, {
|
|
51
|
+
exact: true;
|
|
52
|
+
}>;
|
|
53
|
+
phoneNumberVerified: Schema.optionalWith<typeof Schema.Boolean, {
|
|
54
|
+
exact: true;
|
|
55
|
+
}>;
|
|
56
|
+
address: Schema.optionalWith<typeof Schema.String, {
|
|
57
|
+
exact: true;
|
|
58
|
+
}>;
|
|
59
|
+
updatedAt: Schema.optionalWith<typeof Schema.String, {
|
|
60
|
+
exact: true;
|
|
61
|
+
}>;
|
|
62
|
+
}>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { UserIdentity, UserIdentity_d_exports };
|
|
65
|
+
//# sourceMappingURL=UserIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserIdentity.d.ts","names":[],"sources":["../src/UserIdentity.ts"],"sourcesContent":[],"mappings":";;;;;;cAEa,0CAA2C,MAAA,CAAO,MAAA,CAAO,4BAChD,uBAAkB,MAAA,CAAA,OAAA;;;;EAD3B,IAAA,qBAyBT,CAAA,oBAAA,EAAA;IAzB2D,KAAA,EAAO,IAAA;EAChD,CAAA,CAAA;EAAkB,SAAA,qBAAA,CAAA,oBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,CAAA,CAAA;EAAA,mBAAA,qBAAA,CAAA,qBAAA,EAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
//#region src/UserIdentity.ts
|
|
5
|
+
var UserIdentity_exports = /* @__PURE__ */ __export({ UserIdentity: () => UserIdentity });
|
|
6
|
+
const UserIdentity = (customClaimsFields) => 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
|
+
});
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { UserIdentity, UserIdentity_exports };
|
|
32
|
+
//# sourceMappingURL=UserIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserIdentity.js","names":[],"sources":["../src/UserIdentity.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const UserIdentity = <CustomClaimsFields extends Schema.Struct.Fields>(\n customClaimsFields: CustomClaimsFields,\n) =>\n Schema.Struct({\n ...customClaimsFields,\n tokenIdentifier: Schema.String,\n subject: Schema.String,\n issuer: Schema.String,\n name: Schema.optionalWith(Schema.String, { exact: true }),\n givenName: Schema.optionalWith(Schema.String, { exact: true }),\n familyName: Schema.optionalWith(Schema.String, { exact: true }),\n nickname: Schema.optionalWith(Schema.String, { exact: true }),\n preferredUsername: Schema.optionalWith(Schema.String, { exact: true }),\n profileUrl: Schema.optionalWith(Schema.String, { exact: true }),\n pictureUrl: Schema.optionalWith(Schema.String, { exact: true }),\n email: Schema.optionalWith(Schema.String, { exact: true }),\n emailVerified: Schema.optionalWith(Schema.Boolean, { exact: true }),\n gender: Schema.optionalWith(Schema.String, { exact: true }),\n birthday: Schema.optionalWith(Schema.String, { exact: true }),\n timezone: Schema.optionalWith(Schema.String, { exact: true }),\n language: Schema.optionalWith(Schema.String, { exact: true }),\n phoneNumber: Schema.optionalWith(Schema.String, { exact: true }),\n phoneNumberVerified: Schema.optionalWith(Schema.Boolean, { exact: true }),\n address: Schema.optionalWith(Schema.String, { exact: true }),\n updatedAt: Schema.optionalWith(Schema.String, { exact: true }),\n });\n"],"mappings":";;;;;AAEA,MAAa,gBACX,uBAEA,OAAO,OAAO;CACZ,GAAG;CACH,iBAAiB,OAAO;CACxB,SAAS,OAAO;CAChB,QAAQ,OAAO;CACf,MAAM,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACzD,WAAW,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC9D,YAAY,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC/D,UAAU,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC7D,mBAAmB,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CACtE,YAAY,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC/D,YAAY,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC/D,OAAO,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC1D,eAAe,OAAO,aAAa,OAAO,SAAS,EAAE,OAAO,MAAM,CAAC;CACnE,QAAQ,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC3D,UAAU,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC7D,UAAU,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC7D,UAAU,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC7D,aAAa,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAChE,qBAAqB,OAAO,aAAa,OAAO,SAAS,EAAE,OAAO,MAAM,CAAC;CACzE,SAAS,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC5D,WAAW,OAAO,aAAa,OAAO,QAAQ,EAAE,OAAO,MAAM,CAAC;CAC/D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __export };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FunctionSpec_d_exports } from "./FunctionSpec.js";
|
|
2
|
+
import { GenericId_d_exports } from "./GenericId.js";
|
|
3
|
+
import { GroupSpec_d_exports } from "./GroupSpec.js";
|
|
4
|
+
import { GroupPath_d_exports } from "./GroupPath.js";
|
|
5
|
+
import { PaginationResult_d_exports } from "./PaginationResult.js";
|
|
6
|
+
import { Ref_d_exports } from "./Ref.js";
|
|
7
|
+
import { Spec_d_exports } from "./Spec.js";
|
|
8
|
+
import { Refs_d_exports } from "./Refs.js";
|
|
9
|
+
import { SystemFields_d_exports } from "./SystemFields.js";
|
|
10
|
+
import { Types_d_exports } from "./Types.js";
|
|
11
|
+
import { UserIdentity_d_exports } from "./UserIdentity.js";
|
|
12
|
+
export { FunctionSpec_d_exports as FunctionSpec, GenericId_d_exports as GenericId, GroupPath_d_exports as GroupPath, GroupSpec_d_exports as GroupSpec, PaginationResult_d_exports as PaginationResult, Ref_d_exports as Ref, Refs_d_exports as Refs, Spec_d_exports as Spec, SystemFields_d_exports as SystemFields, Types_d_exports as Types, UserIdentity_d_exports as UserIdentity };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionSpec_exports } from "./FunctionSpec.js";
|
|
2
|
+
import { GenericId_exports } from "./GenericId.js";
|
|
3
|
+
import { GroupPath_exports } from "./GroupPath.js";
|
|
4
|
+
import { GroupSpec_exports } from "./GroupSpec.js";
|
|
5
|
+
import { PaginationResult_exports } from "./PaginationResult.js";
|
|
6
|
+
import { Ref_exports } from "./Ref.js";
|
|
7
|
+
import { Refs_exports } from "./Refs.js";
|
|
8
|
+
import { Spec_exports } from "./Spec.js";
|
|
9
|
+
import { SystemFields_exports } from "./SystemFields.js";
|
|
10
|
+
import { Types_exports } from "./Types.js";
|
|
11
|
+
import { UserIdentity_exports } from "./UserIdentity.js";
|
|
12
|
+
|
|
13
|
+
export { FunctionSpec_exports as FunctionSpec, GenericId_exports as GenericId, GroupPath_exports as GroupPath, GroupSpec_exports as GroupSpec, PaginationResult_exports as PaginationResult, Ref_exports as Ref, Refs_exports as Refs, Spec_exports as Spec, SystemFields_exports as SystemFields, Types_exports as Types, UserIdentity_exports as UserIdentity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":[],"mappings":";cAmEa"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/internal/utils.ts
|
|
2
|
+
const RESERVED_JS_IDENTIFIERS = new Set([
|
|
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
|
+
"await",
|
|
37
|
+
"enum",
|
|
38
|
+
"implements",
|
|
39
|
+
"interface",
|
|
40
|
+
"let",
|
|
41
|
+
"package",
|
|
42
|
+
"private",
|
|
43
|
+
"protected",
|
|
44
|
+
"public",
|
|
45
|
+
"static",
|
|
46
|
+
"null",
|
|
47
|
+
"true",
|
|
48
|
+
"false",
|
|
49
|
+
"undefined"
|
|
50
|
+
]);
|
|
51
|
+
const RESERVED_CONVEX_FILE_NAMES = new Set([
|
|
52
|
+
"schema",
|
|
53
|
+
"http",
|
|
54
|
+
"crons"
|
|
55
|
+
]);
|
|
56
|
+
const jsIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
57
|
+
const isReservedJsIdentifier = (identifier) => RESERVED_JS_IDENTIFIERS.has(identifier);
|
|
58
|
+
const isReservedConvexFileName = (fileName) => RESERVED_CONVEX_FILE_NAMES.has(fileName);
|
|
59
|
+
const matchesJsIdentifierPattern = (identifier) => jsIdentifierRegex.test(identifier);
|
|
60
|
+
const validateConfectFunctionIdentifier = (identifier) => {
|
|
61
|
+
if (!matchesJsIdentifierPattern(identifier)) throw new Error(`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.`);
|
|
62
|
+
if (isReservedJsIdentifier(identifier)) throw new Error(`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved JavaScript identifier.`);
|
|
63
|
+
if (isReservedConvexFileName(identifier)) throw new Error(`Expected a valid Confect function identifier, but received: "${identifier}". "${identifier}" is a reserved Convex file name.`);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { validateConfectFunctionIdentifier };
|
|
68
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["const RESERVED_JS_IDENTIFIERS = new Set([\n // Reserved keywords\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n // Future reserved keywords\n \"await\",\n \"enum\",\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n // Literal values that cannot be reassigned\n \"null\",\n \"true\",\n \"false\",\n // Global objects that shouldn't be shadowed\n \"undefined\",\n]);\n\nconst RESERVED_CONVEX_FILE_NAMES = new Set([\"schema\", \"http\", \"crons\"]);\n\nconst jsIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nconst isReservedJsIdentifier = (identifier: string) =>\n RESERVED_JS_IDENTIFIERS.has(identifier);\n\nconst isReservedConvexFileName = (fileName: string) =>\n RESERVED_CONVEX_FILE_NAMES.has(fileName);\n\nconst matchesJsIdentifierPattern = (identifier: string) =>\n jsIdentifierRegex.test(identifier);\n\nexport const validateConfectFunctionIdentifier = (identifier: string) => {\n if (!matchesJsIdentifierPattern(identifier)) {\n throw new Error(\n `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.`,\n );\n }\n\n if (isReservedJsIdentifier(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved JavaScript identifier.`,\n );\n }\n\n if (isReservedConvexFileName(identifier)) {\n throw new Error(\n `Expected a valid Confect function identifier, but received: \"${identifier}\". \"${identifier}\" is a reserved Convex file name.`,\n );\n }\n};\n"],"mappings":";AAAA,MAAM,0BAA0B,IAAI,IAAI;CAEtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACD,CAAC;AAEF,MAAM,6BAA6B,IAAI,IAAI;CAAC;CAAU;CAAQ;CAAQ,CAAC;AAEvE,MAAM,oBAAoB;AAE1B,MAAM,0BAA0B,eAC9B,wBAAwB,IAAI,WAAW;AAEzC,MAAM,4BAA4B,aAChC,2BAA2B,IAAI,SAAS;AAE1C,MAAM,8BAA8B,eAClC,kBAAkB,KAAK,WAAW;AAEpC,MAAa,qCAAqC,eAAuB;AACvE,KAAI,CAAC,2BAA2B,WAAW,CACzC,OAAM,IAAI,MACR,gEAAgE,WAAW,iJAC5E;AAGH,KAAI,uBAAuB,WAAW,CACpC,OAAM,IAAI,MACR,gEAAgE,WAAW,MAAM,WAAW,wCAC7F;AAGH,KAAI,yBAAyB,WAAW,CACtC,OAAM,IAAI,MACR,gEAAgE,WAAW,MAAM,WAAW,mCAC7F"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@confect/core",
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "Confect core",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rjdellecese/confect.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/rjdellecese/confect/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://confect.rjdellecese.com",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist",
|
|
20
|
+
"package.json",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*": {
|
|
29
|
+
"types": "./dist/*.d.ts",
|
|
30
|
+
"default": "./dist/*.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json",
|
|
33
|
+
"./internal/*": null
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"effect",
|
|
37
|
+
"convex"
|
|
38
|
+
],
|
|
39
|
+
"author": "RJ Dellecese",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@ark/attest": "^0.56.0",
|
|
43
|
+
"@effect/language-service": "0.56.0",
|
|
44
|
+
"@eslint/js": "9.39.1",
|
|
45
|
+
"@tsconfig/strictest": "2.0.8",
|
|
46
|
+
"@types/node": "24.10.1",
|
|
47
|
+
"eslint": "9.39.1",
|
|
48
|
+
"prettier": "3.6.2",
|
|
49
|
+
"tsdown": "0.16.4",
|
|
50
|
+
"typescript": "5.9.3",
|
|
51
|
+
"typescript-eslint": "8.46.4"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"convex": "^1.30.0",
|
|
55
|
+
"effect": "^3.19.3"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=22",
|
|
59
|
+
"pnpm": ">=10"
|
|
60
|
+
},
|
|
61
|
+
"main": "./dist/index.js",
|
|
62
|
+
"module": "./dist/index.js",
|
|
63
|
+
"types": "./dist/index.d.ts",
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsdown --config-loader unrun",
|
|
66
|
+
"dev": "tsdown --watch",
|
|
67
|
+
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
68
|
+
"fix": "prettier --write . && eslint --fix . --max-warnings=0",
|
|
69
|
+
"lint": "prettier --check . && eslint . --max-warnings=0",
|
|
70
|
+
"bench": "tsx test/Refs.bench.ts",
|
|
71
|
+
"clean": "rm -rf dist coverage node_modules"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FunctionType,
|
|
3
|
+
FunctionVisibility,
|
|
4
|
+
RegisteredAction,
|
|
5
|
+
RegisteredMutation,
|
|
6
|
+
RegisteredQuery,
|
|
7
|
+
} from "convex/server";
|
|
8
|
+
import type { Schema } from "effect";
|
|
9
|
+
import { Predicate } from "effect";
|
|
10
|
+
import { validateConfectFunctionIdentifier } from "./internal/utils";
|
|
11
|
+
|
|
12
|
+
export const TypeId = "@confect/core/api/FunctionSpec";
|
|
13
|
+
export type TypeId = typeof TypeId;
|
|
14
|
+
|
|
15
|
+
export const isFunctionSpec = (u: unknown): u is AnyWithProps =>
|
|
16
|
+
Predicate.hasProperty(u, TypeId);
|
|
17
|
+
|
|
18
|
+
export interface FunctionSpec<
|
|
19
|
+
FunctionType_ extends FunctionType,
|
|
20
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
21
|
+
Name_ extends string,
|
|
22
|
+
Args_ extends Schema.Schema.AnyNoContext,
|
|
23
|
+
Returns_ extends Schema.Schema.AnyNoContext,
|
|
24
|
+
> {
|
|
25
|
+
readonly [TypeId]: TypeId;
|
|
26
|
+
readonly functionType: FunctionType_;
|
|
27
|
+
readonly functionVisibility: FunctionVisibility_;
|
|
28
|
+
readonly name: Name_;
|
|
29
|
+
readonly args: Args_;
|
|
30
|
+
readonly returns: Returns_;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Any {
|
|
34
|
+
readonly [TypeId]: TypeId;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AnyWithProps
|
|
38
|
+
extends FunctionSpec<
|
|
39
|
+
FunctionType,
|
|
40
|
+
FunctionVisibility,
|
|
41
|
+
string,
|
|
42
|
+
Schema.Schema.AnyNoContext,
|
|
43
|
+
Schema.Schema.AnyNoContext
|
|
44
|
+
> {}
|
|
45
|
+
|
|
46
|
+
export interface AnyWithPropsWithFunctionType<
|
|
47
|
+
FunctionType_ extends FunctionType,
|
|
48
|
+
> extends FunctionSpec<
|
|
49
|
+
FunctionType_,
|
|
50
|
+
FunctionVisibility,
|
|
51
|
+
string,
|
|
52
|
+
Schema.Schema.AnyNoContext,
|
|
53
|
+
Schema.Schema.AnyNoContext
|
|
54
|
+
> {}
|
|
55
|
+
|
|
56
|
+
export type GetFunctionType<Function extends AnyWithProps> =
|
|
57
|
+
Function["functionType"];
|
|
58
|
+
|
|
59
|
+
export type GetFunctionVisibility<Function extends AnyWithProps> =
|
|
60
|
+
Function["functionVisibility"];
|
|
61
|
+
|
|
62
|
+
export type Name<Function extends AnyWithProps> = Function["name"];
|
|
63
|
+
|
|
64
|
+
export type Args<Function extends AnyWithProps> = Function["args"];
|
|
65
|
+
|
|
66
|
+
export type Returns<Function extends AnyWithProps> = Function["returns"];
|
|
67
|
+
|
|
68
|
+
export type WithName<
|
|
69
|
+
Function extends AnyWithProps,
|
|
70
|
+
Name_ extends string,
|
|
71
|
+
> = Extract<Function, { readonly name: Name_ }>;
|
|
72
|
+
|
|
73
|
+
export type WithFunctionType<
|
|
74
|
+
Function extends AnyWithProps,
|
|
75
|
+
FunctionType_ extends FunctionType,
|
|
76
|
+
> = Extract<Function, { readonly functionType: FunctionType_ }>;
|
|
77
|
+
|
|
78
|
+
export type ExcludeName<
|
|
79
|
+
Function extends AnyWithProps,
|
|
80
|
+
Name_ extends Name<Function>,
|
|
81
|
+
> = Exclude<Function, { readonly name: Name_ }>;
|
|
82
|
+
|
|
83
|
+
export type RegisteredFunction<Function extends AnyWithProps> =
|
|
84
|
+
Function["functionType"] extends "query"
|
|
85
|
+
? RegisteredQuery<
|
|
86
|
+
GetFunctionVisibility<Function>,
|
|
87
|
+
Args<Function>["Encoded"],
|
|
88
|
+
Promise<Returns<Function>["Encoded"]>
|
|
89
|
+
>
|
|
90
|
+
: Function["functionType"] extends "mutation"
|
|
91
|
+
? RegisteredMutation<
|
|
92
|
+
GetFunctionVisibility<Function>,
|
|
93
|
+
Args<Function>["Encoded"],
|
|
94
|
+
Promise<Returns<Function>["Encoded"]>
|
|
95
|
+
>
|
|
96
|
+
: Function["functionType"] extends "action"
|
|
97
|
+
? RegisteredAction<
|
|
98
|
+
GetFunctionVisibility<Function>,
|
|
99
|
+
Args<Function>["Encoded"],
|
|
100
|
+
Promise<Returns<Function>["Encoded"]>
|
|
101
|
+
>
|
|
102
|
+
: never;
|
|
103
|
+
|
|
104
|
+
const Proto = {
|
|
105
|
+
[TypeId]: TypeId,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const make =
|
|
109
|
+
<
|
|
110
|
+
FunctionType_ extends FunctionType,
|
|
111
|
+
FunctionVisibility_ extends FunctionVisibility,
|
|
112
|
+
>(
|
|
113
|
+
functionType: FunctionType_,
|
|
114
|
+
functionVisibility: FunctionVisibility_,
|
|
115
|
+
) =>
|
|
116
|
+
<
|
|
117
|
+
const Name_ extends string,
|
|
118
|
+
Args_ extends Schema.Schema.AnyNoContext,
|
|
119
|
+
Returns_ extends Schema.Schema.AnyNoContext,
|
|
120
|
+
>({
|
|
121
|
+
name,
|
|
122
|
+
args,
|
|
123
|
+
returns,
|
|
124
|
+
}: {
|
|
125
|
+
name: Name_;
|
|
126
|
+
args: Args_;
|
|
127
|
+
returns: Returns_;
|
|
128
|
+
}): FunctionSpec<
|
|
129
|
+
FunctionType_,
|
|
130
|
+
FunctionVisibility_,
|
|
131
|
+
Name_,
|
|
132
|
+
Args_,
|
|
133
|
+
Returns_
|
|
134
|
+
> => {
|
|
135
|
+
validateConfectFunctionIdentifier(name);
|
|
136
|
+
|
|
137
|
+
return Object.assign(Object.create(Proto), {
|
|
138
|
+
functionType,
|
|
139
|
+
functionVisibility,
|
|
140
|
+
name,
|
|
141
|
+
args,
|
|
142
|
+
returns,
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const internalQuery = make("query", "internal");
|
|
147
|
+
export const query = make("query", "public");
|
|
148
|
+
|
|
149
|
+
export const internalMutation = make("mutation", "internal");
|
|
150
|
+
export const mutation = make("mutation", "public");
|
|
151
|
+
|
|
152
|
+
export const internalAction = make("action", "internal");
|
|
153
|
+
export const action = make("action", "public");
|
package/src/GenericId.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GenericId as ConvexGenericId } from "convex/values";
|
|
2
|
+
import { type Option, Schema, SchemaAST } from "effect";
|
|
3
|
+
|
|
4
|
+
const ConvexId = Symbol.for("ConvexId");
|
|
5
|
+
|
|
6
|
+
export const GenericId = <TableName extends string>(
|
|
7
|
+
tableName: TableName,
|
|
8
|
+
): Schema.Schema<ConvexGenericId<TableName>> =>
|
|
9
|
+
Schema.String.pipe(
|
|
10
|
+
Schema.annotations({ [ConvexId]: tableName }),
|
|
11
|
+
) as unknown as Schema.Schema<ConvexGenericId<TableName>>;
|
|
12
|
+
|
|
13
|
+
export type GenericId<TableName extends string> = ConvexGenericId<TableName>;
|
|
14
|
+
|
|
15
|
+
export const tableName = <TableName extends string>(
|
|
16
|
+
ast: SchemaAST.AST,
|
|
17
|
+
): Option.Option<TableName> =>
|
|
18
|
+
SchemaAST.getAnnotation<TableName>(ConvexId)(ast);
|