express-file-cluster 0.8.0 → 0.9.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/README.md +1 -1
- package/dist/auth/index.cjs +3 -3
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +2 -2
- package/dist/{chunk-ZDM5JHVK.cjs → chunk-2J3HHQKP.cjs} +3 -3
- package/dist/{chunk-ZDM5JHVK.cjs.map → chunk-2J3HHQKP.cjs.map} +1 -1
- package/dist/{chunk-BUBXO7WU.js → chunk-HXV543HZ.js} +10 -3
- package/dist/chunk-HXV543HZ.js.map +1 -0
- package/dist/{chunk-OSES7ZQ5.js → chunk-QKQZF573.js} +27 -5
- package/dist/chunk-QKQZF573.js.map +1 -0
- package/dist/{chunk-B2I7SYQ3.js → chunk-RRQ2RK5M.js} +371 -8
- package/dist/chunk-RRQ2RK5M.js.map +1 -0
- package/dist/{chunk-TRC4DUZB.js → chunk-RSZB7VAO.js} +2 -2
- package/dist/{chunk-FQFKHPLR.cjs → chunk-RTF7PHS2.cjs} +473 -110
- package/dist/chunk-RTF7PHS2.cjs.map +1 -0
- package/dist/{chunk-MGH4VDV3.cjs → chunk-VQSWSYK6.cjs} +10 -3
- package/dist/chunk-VQSWSYK6.cjs.map +1 -0
- package/dist/{chunk-75O3WQKR.cjs → chunk-X2US4RAM.cjs} +30 -8
- package/dist/chunk-X2US4RAM.cjs.map +1 -0
- package/dist/cli/db-runner.cjs +19 -19
- package/dist/cli/db-runner.js +3 -3
- package/dist/cli/index.cjs +364 -27
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +344 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/collection.md +155 -0
- package/dist/docs/api-reference/ignite.md +19 -0
- package/dist/docs/api-reference/table.md +3 -0
- package/dist/docs/cli/add.md +36 -7
- package/dist/docs/guides/authentication.md +50 -0
- package/dist/docs/guides/coming-from-mongoose.md +60 -0
- package/dist/docs/guides/database.md +2 -0
- package/dist/docs/guides/relations.md +147 -0
- package/dist/docs/guides/which-api.md +59 -0
- package/dist/docs/index.md +5 -1
- package/dist/docs/skills/SKILL.md +3 -3
- package/dist/docs/skills/api-surface.md +9 -0
- package/dist/docs/skills/what-not-to-invent.md +3 -2
- package/dist/index.cjs +21 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +193 -3
- package/dist/index.d.ts +193 -3
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/registry/index.json +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/{types-B1tJoI4g.d.cts → types-BY-ObnZH.d.cts} +47 -7
- package/dist/{types-B1tJoI4g.d.ts → types-BY-ObnZH.d.ts} +47 -7
- package/package.json +1 -1
- package/dist/chunk-75O3WQKR.cjs.map +0 -1
- package/dist/chunk-B2I7SYQ3.js.map +0 -1
- package/dist/chunk-BUBXO7WU.js.map +0 -1
- package/dist/chunk-FQFKHPLR.cjs.map +0 -1
- package/dist/chunk-MGH4VDV3.cjs.map +0 -1
- package/dist/chunk-OSES7ZQ5.js.map +0 -1
- /package/dist/{chunk-TRC4DUZB.js.map → chunk-RSZB7VAO.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { S as Simplify, I as InferSchema, b as InferCreateInput, M as ModelSchema, c as ModelOptions, d as InferredModel, e as TableSchema, f as TableOptions, R as RouteEntry, E as EFCConfig } from './types-
|
|
3
|
-
export { A as AuthStrategy,
|
|
2
|
+
import { S as Simplify, I as InferSchema, b as InferCreateInput, M as ModelSchema, c as ModelOptions, d as InferredModel, e as TableSchema, f as TableOptions, g as SortDirection, C as CollectionSchema, R as RouteEntry, E as EFCConfig } from './types-BY-ObnZH.cjs';
|
|
3
|
+
export { A as AuthStrategy, h as CacheConfig, i as CollectionFieldDefinition, j as CorsConfig, D as DatabaseEngine, k as DatabasePoolConfig, l as DefaultOperator, F as FieldDefinition, m as Filter, n as FilterOperators, o as FindOptions, G as GeoPoint, p as IndexDefinition, q as InferCreate, r as InferRecord, L as LoggingConfig, s as MigrationContext, t as ModelCRUD, u as ModelQueryOptions, v as ModelRecord, Q as QueryLogConfig, w as RequestSchema, x as RouteMeta, y as RouteMethodMeta, z as RouteSchema, B as ScalarKeys, H as SchemaField, J as TableFieldDefinition, K as TableRelation, N as TableSchemaField, a as TaskDefinition, T as TaskOptions, U as Update, V as ValidationIssue, O as Validator } from './types-BY-ObnZH.cjs';
|
|
4
4
|
import { Logger } from 'pino';
|
|
5
5
|
import { Request, RequestHandler } from 'express';
|
|
6
6
|
export { listTasks } from './tasks/index.cjs';
|
|
@@ -722,6 +722,196 @@ declare function defineModel<T extends object = never, const S extends ModelSche
|
|
|
722
722
|
*/
|
|
723
723
|
declare function defineTable<const S extends TableSchema, const O extends TableOptions = object>(name: string, schema: S, options?: O): TableModel<S, O>;
|
|
724
724
|
|
|
725
|
+
type AnyRecord = Record<string, unknown>;
|
|
726
|
+
interface CollectionOptions extends ModelOptions {
|
|
727
|
+
/** Default collation for this collection's queries, e.g. `{ locale: 'en', strength: 2 }`. */
|
|
728
|
+
collation?: AnyRecord;
|
|
729
|
+
}
|
|
730
|
+
interface CollectionFindOptions {
|
|
731
|
+
/** Inclusion (`{ name: 1 }`) or exclusion (`{ secret: 0 }`) projection. */
|
|
732
|
+
projection?: Record<string, 0 | 1 | boolean | AnyRecord>;
|
|
733
|
+
sort?: Record<string, SortDirection | {
|
|
734
|
+
$meta: 'textScore';
|
|
735
|
+
}>;
|
|
736
|
+
skip?: number;
|
|
737
|
+
limit?: number;
|
|
738
|
+
/** Resolve `objectId` fields that have a `ref` into the referenced documents. */
|
|
739
|
+
populate?: string | string[];
|
|
740
|
+
collation?: AnyRecord;
|
|
741
|
+
}
|
|
742
|
+
interface CollectionWriteResult {
|
|
743
|
+
matchedCount: number;
|
|
744
|
+
modifiedCount: number;
|
|
745
|
+
upsertedCount: number;
|
|
746
|
+
upsertedId: string | null;
|
|
747
|
+
}
|
|
748
|
+
interface CollectionBulkResult {
|
|
749
|
+
insertedCount: number;
|
|
750
|
+
matchedCount: number;
|
|
751
|
+
modifiedCount: number;
|
|
752
|
+
deletedCount: number;
|
|
753
|
+
upsertedCount: number;
|
|
754
|
+
}
|
|
755
|
+
/** A change stream: iterate with `for await`, stop with `close()` (or `break`). */
|
|
756
|
+
interface CollectionChangeStream<R> extends AsyncIterable<CollectionChange<R>> {
|
|
757
|
+
close(): Promise<void>;
|
|
758
|
+
}
|
|
759
|
+
interface CollectionChange<R> {
|
|
760
|
+
operationType: string;
|
|
761
|
+
/** The document id. */
|
|
762
|
+
id: string | undefined;
|
|
763
|
+
/** The new document (inserts, replaces; updates with `fullDocument: 'updateLookup'`). */
|
|
764
|
+
fullDocument?: R;
|
|
765
|
+
updateDescription?: {
|
|
766
|
+
updatedFields: AnyRecord;
|
|
767
|
+
removedFields: string[];
|
|
768
|
+
};
|
|
769
|
+
raw: AnyRecord;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Defines a MongoDB-native model with mongoose's vocabulary — `find` with projections,
|
|
773
|
+
* `findOneAndUpdate` with upsert, `bulkWrite`, aggregation pipelines, change streams —
|
|
774
|
+
* and BSON types (`decimal128`, `long`, `geoPoint`, `binary`). Record and input types are
|
|
775
|
+
* inferred from the schema. Throws at first use on a PostgreSQL connection.
|
|
776
|
+
*/
|
|
777
|
+
declare function defineCollection<const S extends CollectionSchema, const O extends CollectionOptions = object>(name: string, schema: S, options?: O): CollectionModel<S, O>;
|
|
778
|
+
type Rec<S, O> = Simplify<InferSchema<S, O> & {
|
|
779
|
+
id: string;
|
|
780
|
+
}>;
|
|
781
|
+
type Elem<V> = V extends readonly (infer E)[] ? E : never;
|
|
782
|
+
/** A query filter: fields (with an array's element for "contains"), operators, dotted paths. */
|
|
783
|
+
type CollectionFilter<R> = {
|
|
784
|
+
[K in keyof R]?: R[K] | Elem<R[K]> | null | {
|
|
785
|
+
[op: `$${string}`]: unknown;
|
|
786
|
+
};
|
|
787
|
+
} & {
|
|
788
|
+
[path: `${string}.${string}`]: unknown;
|
|
789
|
+
_id?: unknown;
|
|
790
|
+
$and?: CollectionFilter<R>[];
|
|
791
|
+
$or?: CollectionFilter<R>[];
|
|
792
|
+
$nor?: CollectionFilter<R>[];
|
|
793
|
+
$text?: {
|
|
794
|
+
$search: string;
|
|
795
|
+
$language?: string;
|
|
796
|
+
$caseSensitive?: boolean;
|
|
797
|
+
};
|
|
798
|
+
$expr?: unknown;
|
|
799
|
+
};
|
|
800
|
+
type Fields<R> = {
|
|
801
|
+
[K in keyof R]?: unknown;
|
|
802
|
+
} & {
|
|
803
|
+
[path: `${string}.${string}`]: unknown;
|
|
804
|
+
};
|
|
805
|
+
/** Plain fields (shorthand for `$set`) and/or update operators. */
|
|
806
|
+
type CollectionUpdate<R> = Partial<R> | {
|
|
807
|
+
$set?: Fields<R>;
|
|
808
|
+
$unset?: Fields<R>;
|
|
809
|
+
$inc?: Fields<R>;
|
|
810
|
+
$mul?: Fields<R>;
|
|
811
|
+
$min?: Fields<R>;
|
|
812
|
+
$max?: Fields<R>;
|
|
813
|
+
$push?: Fields<R>;
|
|
814
|
+
$pull?: Fields<R>;
|
|
815
|
+
$addToSet?: Fields<R>;
|
|
816
|
+
$pop?: Fields<R>;
|
|
817
|
+
$rename?: Record<string, string>;
|
|
818
|
+
$setOnInsert?: Fields<R>;
|
|
819
|
+
$currentDate?: Fields<R>;
|
|
820
|
+
};
|
|
821
|
+
type CollectionBulkOp<R, C> = {
|
|
822
|
+
insertOne: {
|
|
823
|
+
document: C;
|
|
824
|
+
};
|
|
825
|
+
} | {
|
|
826
|
+
updateOne: {
|
|
827
|
+
filter: CollectionFilter<R>;
|
|
828
|
+
update: CollectionUpdate<R>;
|
|
829
|
+
upsert?: boolean;
|
|
830
|
+
};
|
|
831
|
+
} | {
|
|
832
|
+
updateMany: {
|
|
833
|
+
filter: CollectionFilter<R>;
|
|
834
|
+
update: CollectionUpdate<R>;
|
|
835
|
+
upsert?: boolean;
|
|
836
|
+
};
|
|
837
|
+
} | {
|
|
838
|
+
replaceOne: {
|
|
839
|
+
filter: CollectionFilter<R>;
|
|
840
|
+
replacement: C;
|
|
841
|
+
upsert?: boolean;
|
|
842
|
+
};
|
|
843
|
+
} | {
|
|
844
|
+
deleteOne: {
|
|
845
|
+
filter: CollectionFilter<R>;
|
|
846
|
+
};
|
|
847
|
+
} | {
|
|
848
|
+
deleteMany: {
|
|
849
|
+
filter: CollectionFilter<R>;
|
|
850
|
+
};
|
|
851
|
+
};
|
|
852
|
+
interface CollectionModel<S, O = object, R = Rec<S, O>, C = InferCreateInput<S>> {
|
|
853
|
+
readonly name: string;
|
|
854
|
+
/** Inferred types: `InferRecord<typeof Place>`, `InferCreate<typeof Place>`. */
|
|
855
|
+
readonly $types?: {
|
|
856
|
+
record: R;
|
|
857
|
+
create: C;
|
|
858
|
+
};
|
|
859
|
+
find(filter?: CollectionFilter<R>, options?: CollectionFindOptions): Promise<R[]>;
|
|
860
|
+
findOne(filter?: CollectionFilter<R>, options?: CollectionFindOptions): Promise<R | null>;
|
|
861
|
+
findById(id: string, options?: CollectionFindOptions): Promise<R | null>;
|
|
862
|
+
exists(filter: CollectionFilter<R>): Promise<boolean>;
|
|
863
|
+
countDocuments(filter?: CollectionFilter<R>): Promise<number>;
|
|
864
|
+
/** Fast count from collection metadata (ignores filters and transactions). */
|
|
865
|
+
estimatedDocumentCount(): Promise<number>;
|
|
866
|
+
distinct<K extends keyof R & string>(field: K | `${string}.${string}`, filter?: CollectionFilter<R>): Promise<(K extends keyof R ? Elem<R[K]> | Exclude<R[K], readonly unknown[]> : unknown)[]>;
|
|
867
|
+
create(data: C): Promise<R>;
|
|
868
|
+
insertMany(data: C[]): Promise<R[]>;
|
|
869
|
+
updateOne(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
870
|
+
upsert?: boolean;
|
|
871
|
+
}): Promise<CollectionWriteResult>;
|
|
872
|
+
updateMany(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
873
|
+
upsert?: boolean;
|
|
874
|
+
}): Promise<CollectionWriteResult>;
|
|
875
|
+
replaceOne(filter: CollectionFilter<R>, replacement: C, options?: {
|
|
876
|
+
upsert?: boolean;
|
|
877
|
+
}): Promise<CollectionWriteResult>;
|
|
878
|
+
/** Returns the document before the update unless `returnDocument: 'after'` (as mongoose). */
|
|
879
|
+
findOneAndUpdate(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
880
|
+
upsert?: boolean;
|
|
881
|
+
returnDocument?: 'before' | 'after';
|
|
882
|
+
projection?: CollectionFindOptions['projection'];
|
|
883
|
+
sort?: CollectionFindOptions['sort'];
|
|
884
|
+
}): Promise<R | null>;
|
|
885
|
+
findByIdAndUpdate(id: string, update: CollectionUpdate<R>, options?: {
|
|
886
|
+
returnDocument?: 'before' | 'after';
|
|
887
|
+
}): Promise<R | null>;
|
|
888
|
+
findOneAndDelete(filter: CollectionFilter<R>, options?: {
|
|
889
|
+
sort?: CollectionFindOptions['sort'];
|
|
890
|
+
}): Promise<R | null>;
|
|
891
|
+
findByIdAndDelete(id: string): Promise<R | null>;
|
|
892
|
+
deleteOne(filter: CollectionFilter<R>): Promise<{
|
|
893
|
+
deletedCount: number;
|
|
894
|
+
}>;
|
|
895
|
+
deleteMany(filter?: CollectionFilter<R>): Promise<{
|
|
896
|
+
deletedCount: number;
|
|
897
|
+
}>;
|
|
898
|
+
/** An aggregation pipeline; type the output with the generic: `aggregate<{ _id: string; n: number }>(…)`. */
|
|
899
|
+
aggregate<T = Record<string, unknown>>(pipeline: Record<string, unknown>[]): Promise<T[]>;
|
|
900
|
+
bulkWrite(ops: CollectionBulkOp<R, C>[], options?: {
|
|
901
|
+
ordered?: boolean;
|
|
902
|
+
}): Promise<CollectionBulkResult>;
|
|
903
|
+
/** A change stream (needs a replica set). */
|
|
904
|
+
watch(pipeline?: Record<string, unknown>[], options?: {
|
|
905
|
+
fullDocument?: 'default' | 'updateLookup' | 'whenAvailable' | 'required';
|
|
906
|
+
}): CollectionChangeStream<R>;
|
|
907
|
+
/** The mongoose `Model`. */
|
|
908
|
+
raw(): Promise<unknown>;
|
|
909
|
+
sync(options?: {
|
|
910
|
+
dryRun?: boolean;
|
|
911
|
+
}): Promise<string[]>;
|
|
912
|
+
drop(): Promise<void>;
|
|
913
|
+
}
|
|
914
|
+
|
|
725
915
|
type AnyClient = Record<string, unknown>;
|
|
726
916
|
declare function setDbClient(client: AnyClient): void;
|
|
727
917
|
declare function getDbClient(): AnyClient;
|
|
@@ -775,4 +965,4 @@ declare function workerCount(): number;
|
|
|
775
965
|
declare function ignite(config: EFCConfig): Promise<http.Server | undefined>;
|
|
776
966
|
declare function gracefulShutdown(server: http.Server | undefined, timeoutMs?: number): void;
|
|
777
967
|
|
|
778
|
-
export { EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|
|
968
|
+
export { type CollectionBulkOp, type CollectionBulkResult, type CollectionChange, type CollectionChangeStream, type CollectionFilter, type CollectionFindOptions, type CollectionModel, type CollectionOptions, CollectionSchema, type CollectionUpdate, type CollectionWriteResult, EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, SortDirection, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineCollection, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { S as Simplify, I as InferSchema, b as InferCreateInput, M as ModelSchema, c as ModelOptions, d as InferredModel, e as TableSchema, f as TableOptions, R as RouteEntry, E as EFCConfig } from './types-
|
|
3
|
-
export { A as AuthStrategy,
|
|
2
|
+
import { S as Simplify, I as InferSchema, b as InferCreateInput, M as ModelSchema, c as ModelOptions, d as InferredModel, e as TableSchema, f as TableOptions, g as SortDirection, C as CollectionSchema, R as RouteEntry, E as EFCConfig } from './types-BY-ObnZH.js';
|
|
3
|
+
export { A as AuthStrategy, h as CacheConfig, i as CollectionFieldDefinition, j as CorsConfig, D as DatabaseEngine, k as DatabasePoolConfig, l as DefaultOperator, F as FieldDefinition, m as Filter, n as FilterOperators, o as FindOptions, G as GeoPoint, p as IndexDefinition, q as InferCreate, r as InferRecord, L as LoggingConfig, s as MigrationContext, t as ModelCRUD, u as ModelQueryOptions, v as ModelRecord, Q as QueryLogConfig, w as RequestSchema, x as RouteMeta, y as RouteMethodMeta, z as RouteSchema, B as ScalarKeys, H as SchemaField, J as TableFieldDefinition, K as TableRelation, N as TableSchemaField, a as TaskDefinition, T as TaskOptions, U as Update, V as ValidationIssue, O as Validator } from './types-BY-ObnZH.js';
|
|
4
4
|
import { Logger } from 'pino';
|
|
5
5
|
import { Request, RequestHandler } from 'express';
|
|
6
6
|
export { listTasks } from './tasks/index.js';
|
|
@@ -722,6 +722,196 @@ declare function defineModel<T extends object = never, const S extends ModelSche
|
|
|
722
722
|
*/
|
|
723
723
|
declare function defineTable<const S extends TableSchema, const O extends TableOptions = object>(name: string, schema: S, options?: O): TableModel<S, O>;
|
|
724
724
|
|
|
725
|
+
type AnyRecord = Record<string, unknown>;
|
|
726
|
+
interface CollectionOptions extends ModelOptions {
|
|
727
|
+
/** Default collation for this collection's queries, e.g. `{ locale: 'en', strength: 2 }`. */
|
|
728
|
+
collation?: AnyRecord;
|
|
729
|
+
}
|
|
730
|
+
interface CollectionFindOptions {
|
|
731
|
+
/** Inclusion (`{ name: 1 }`) or exclusion (`{ secret: 0 }`) projection. */
|
|
732
|
+
projection?: Record<string, 0 | 1 | boolean | AnyRecord>;
|
|
733
|
+
sort?: Record<string, SortDirection | {
|
|
734
|
+
$meta: 'textScore';
|
|
735
|
+
}>;
|
|
736
|
+
skip?: number;
|
|
737
|
+
limit?: number;
|
|
738
|
+
/** Resolve `objectId` fields that have a `ref` into the referenced documents. */
|
|
739
|
+
populate?: string | string[];
|
|
740
|
+
collation?: AnyRecord;
|
|
741
|
+
}
|
|
742
|
+
interface CollectionWriteResult {
|
|
743
|
+
matchedCount: number;
|
|
744
|
+
modifiedCount: number;
|
|
745
|
+
upsertedCount: number;
|
|
746
|
+
upsertedId: string | null;
|
|
747
|
+
}
|
|
748
|
+
interface CollectionBulkResult {
|
|
749
|
+
insertedCount: number;
|
|
750
|
+
matchedCount: number;
|
|
751
|
+
modifiedCount: number;
|
|
752
|
+
deletedCount: number;
|
|
753
|
+
upsertedCount: number;
|
|
754
|
+
}
|
|
755
|
+
/** A change stream: iterate with `for await`, stop with `close()` (or `break`). */
|
|
756
|
+
interface CollectionChangeStream<R> extends AsyncIterable<CollectionChange<R>> {
|
|
757
|
+
close(): Promise<void>;
|
|
758
|
+
}
|
|
759
|
+
interface CollectionChange<R> {
|
|
760
|
+
operationType: string;
|
|
761
|
+
/** The document id. */
|
|
762
|
+
id: string | undefined;
|
|
763
|
+
/** The new document (inserts, replaces; updates with `fullDocument: 'updateLookup'`). */
|
|
764
|
+
fullDocument?: R;
|
|
765
|
+
updateDescription?: {
|
|
766
|
+
updatedFields: AnyRecord;
|
|
767
|
+
removedFields: string[];
|
|
768
|
+
};
|
|
769
|
+
raw: AnyRecord;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Defines a MongoDB-native model with mongoose's vocabulary — `find` with projections,
|
|
773
|
+
* `findOneAndUpdate` with upsert, `bulkWrite`, aggregation pipelines, change streams —
|
|
774
|
+
* and BSON types (`decimal128`, `long`, `geoPoint`, `binary`). Record and input types are
|
|
775
|
+
* inferred from the schema. Throws at first use on a PostgreSQL connection.
|
|
776
|
+
*/
|
|
777
|
+
declare function defineCollection<const S extends CollectionSchema, const O extends CollectionOptions = object>(name: string, schema: S, options?: O): CollectionModel<S, O>;
|
|
778
|
+
type Rec<S, O> = Simplify<InferSchema<S, O> & {
|
|
779
|
+
id: string;
|
|
780
|
+
}>;
|
|
781
|
+
type Elem<V> = V extends readonly (infer E)[] ? E : never;
|
|
782
|
+
/** A query filter: fields (with an array's element for "contains"), operators, dotted paths. */
|
|
783
|
+
type CollectionFilter<R> = {
|
|
784
|
+
[K in keyof R]?: R[K] | Elem<R[K]> | null | {
|
|
785
|
+
[op: `$${string}`]: unknown;
|
|
786
|
+
};
|
|
787
|
+
} & {
|
|
788
|
+
[path: `${string}.${string}`]: unknown;
|
|
789
|
+
_id?: unknown;
|
|
790
|
+
$and?: CollectionFilter<R>[];
|
|
791
|
+
$or?: CollectionFilter<R>[];
|
|
792
|
+
$nor?: CollectionFilter<R>[];
|
|
793
|
+
$text?: {
|
|
794
|
+
$search: string;
|
|
795
|
+
$language?: string;
|
|
796
|
+
$caseSensitive?: boolean;
|
|
797
|
+
};
|
|
798
|
+
$expr?: unknown;
|
|
799
|
+
};
|
|
800
|
+
type Fields<R> = {
|
|
801
|
+
[K in keyof R]?: unknown;
|
|
802
|
+
} & {
|
|
803
|
+
[path: `${string}.${string}`]: unknown;
|
|
804
|
+
};
|
|
805
|
+
/** Plain fields (shorthand for `$set`) and/or update operators. */
|
|
806
|
+
type CollectionUpdate<R> = Partial<R> | {
|
|
807
|
+
$set?: Fields<R>;
|
|
808
|
+
$unset?: Fields<R>;
|
|
809
|
+
$inc?: Fields<R>;
|
|
810
|
+
$mul?: Fields<R>;
|
|
811
|
+
$min?: Fields<R>;
|
|
812
|
+
$max?: Fields<R>;
|
|
813
|
+
$push?: Fields<R>;
|
|
814
|
+
$pull?: Fields<R>;
|
|
815
|
+
$addToSet?: Fields<R>;
|
|
816
|
+
$pop?: Fields<R>;
|
|
817
|
+
$rename?: Record<string, string>;
|
|
818
|
+
$setOnInsert?: Fields<R>;
|
|
819
|
+
$currentDate?: Fields<R>;
|
|
820
|
+
};
|
|
821
|
+
type CollectionBulkOp<R, C> = {
|
|
822
|
+
insertOne: {
|
|
823
|
+
document: C;
|
|
824
|
+
};
|
|
825
|
+
} | {
|
|
826
|
+
updateOne: {
|
|
827
|
+
filter: CollectionFilter<R>;
|
|
828
|
+
update: CollectionUpdate<R>;
|
|
829
|
+
upsert?: boolean;
|
|
830
|
+
};
|
|
831
|
+
} | {
|
|
832
|
+
updateMany: {
|
|
833
|
+
filter: CollectionFilter<R>;
|
|
834
|
+
update: CollectionUpdate<R>;
|
|
835
|
+
upsert?: boolean;
|
|
836
|
+
};
|
|
837
|
+
} | {
|
|
838
|
+
replaceOne: {
|
|
839
|
+
filter: CollectionFilter<R>;
|
|
840
|
+
replacement: C;
|
|
841
|
+
upsert?: boolean;
|
|
842
|
+
};
|
|
843
|
+
} | {
|
|
844
|
+
deleteOne: {
|
|
845
|
+
filter: CollectionFilter<R>;
|
|
846
|
+
};
|
|
847
|
+
} | {
|
|
848
|
+
deleteMany: {
|
|
849
|
+
filter: CollectionFilter<R>;
|
|
850
|
+
};
|
|
851
|
+
};
|
|
852
|
+
interface CollectionModel<S, O = object, R = Rec<S, O>, C = InferCreateInput<S>> {
|
|
853
|
+
readonly name: string;
|
|
854
|
+
/** Inferred types: `InferRecord<typeof Place>`, `InferCreate<typeof Place>`. */
|
|
855
|
+
readonly $types?: {
|
|
856
|
+
record: R;
|
|
857
|
+
create: C;
|
|
858
|
+
};
|
|
859
|
+
find(filter?: CollectionFilter<R>, options?: CollectionFindOptions): Promise<R[]>;
|
|
860
|
+
findOne(filter?: CollectionFilter<R>, options?: CollectionFindOptions): Promise<R | null>;
|
|
861
|
+
findById(id: string, options?: CollectionFindOptions): Promise<R | null>;
|
|
862
|
+
exists(filter: CollectionFilter<R>): Promise<boolean>;
|
|
863
|
+
countDocuments(filter?: CollectionFilter<R>): Promise<number>;
|
|
864
|
+
/** Fast count from collection metadata (ignores filters and transactions). */
|
|
865
|
+
estimatedDocumentCount(): Promise<number>;
|
|
866
|
+
distinct<K extends keyof R & string>(field: K | `${string}.${string}`, filter?: CollectionFilter<R>): Promise<(K extends keyof R ? Elem<R[K]> | Exclude<R[K], readonly unknown[]> : unknown)[]>;
|
|
867
|
+
create(data: C): Promise<R>;
|
|
868
|
+
insertMany(data: C[]): Promise<R[]>;
|
|
869
|
+
updateOne(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
870
|
+
upsert?: boolean;
|
|
871
|
+
}): Promise<CollectionWriteResult>;
|
|
872
|
+
updateMany(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
873
|
+
upsert?: boolean;
|
|
874
|
+
}): Promise<CollectionWriteResult>;
|
|
875
|
+
replaceOne(filter: CollectionFilter<R>, replacement: C, options?: {
|
|
876
|
+
upsert?: boolean;
|
|
877
|
+
}): Promise<CollectionWriteResult>;
|
|
878
|
+
/** Returns the document before the update unless `returnDocument: 'after'` (as mongoose). */
|
|
879
|
+
findOneAndUpdate(filter: CollectionFilter<R>, update: CollectionUpdate<R>, options?: {
|
|
880
|
+
upsert?: boolean;
|
|
881
|
+
returnDocument?: 'before' | 'after';
|
|
882
|
+
projection?: CollectionFindOptions['projection'];
|
|
883
|
+
sort?: CollectionFindOptions['sort'];
|
|
884
|
+
}): Promise<R | null>;
|
|
885
|
+
findByIdAndUpdate(id: string, update: CollectionUpdate<R>, options?: {
|
|
886
|
+
returnDocument?: 'before' | 'after';
|
|
887
|
+
}): Promise<R | null>;
|
|
888
|
+
findOneAndDelete(filter: CollectionFilter<R>, options?: {
|
|
889
|
+
sort?: CollectionFindOptions['sort'];
|
|
890
|
+
}): Promise<R | null>;
|
|
891
|
+
findByIdAndDelete(id: string): Promise<R | null>;
|
|
892
|
+
deleteOne(filter: CollectionFilter<R>): Promise<{
|
|
893
|
+
deletedCount: number;
|
|
894
|
+
}>;
|
|
895
|
+
deleteMany(filter?: CollectionFilter<R>): Promise<{
|
|
896
|
+
deletedCount: number;
|
|
897
|
+
}>;
|
|
898
|
+
/** An aggregation pipeline; type the output with the generic: `aggregate<{ _id: string; n: number }>(…)`. */
|
|
899
|
+
aggregate<T = Record<string, unknown>>(pipeline: Record<string, unknown>[]): Promise<T[]>;
|
|
900
|
+
bulkWrite(ops: CollectionBulkOp<R, C>[], options?: {
|
|
901
|
+
ordered?: boolean;
|
|
902
|
+
}): Promise<CollectionBulkResult>;
|
|
903
|
+
/** A change stream (needs a replica set). */
|
|
904
|
+
watch(pipeline?: Record<string, unknown>[], options?: {
|
|
905
|
+
fullDocument?: 'default' | 'updateLookup' | 'whenAvailable' | 'required';
|
|
906
|
+
}): CollectionChangeStream<R>;
|
|
907
|
+
/** The mongoose `Model`. */
|
|
908
|
+
raw(): Promise<unknown>;
|
|
909
|
+
sync(options?: {
|
|
910
|
+
dryRun?: boolean;
|
|
911
|
+
}): Promise<string[]>;
|
|
912
|
+
drop(): Promise<void>;
|
|
913
|
+
}
|
|
914
|
+
|
|
725
915
|
type AnyClient = Record<string, unknown>;
|
|
726
916
|
declare function setDbClient(client: AnyClient): void;
|
|
727
917
|
declare function getDbClient(): AnyClient;
|
|
@@ -775,4 +965,4 @@ declare function workerCount(): number;
|
|
|
775
965
|
declare function ignite(config: EFCConfig): Promise<http.Server | undefined>;
|
|
776
966
|
declare function gracefulShutdown(server: http.Server | undefined, timeoutMs?: number): void;
|
|
777
967
|
|
|
778
|
-
export { EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|
|
968
|
+
export { type CollectionBulkOp, type CollectionBulkResult, type CollectionChange, type CollectionChangeStream, type CollectionFilter, type CollectionFindOptions, type CollectionModel, type CollectionOptions, CollectionSchema, type CollectionUpdate, type CollectionWriteResult, EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, SortDirection, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineCollection, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
configureAuth,
|
|
5
5
|
configureCache,
|
|
6
6
|
servePrimaryCache
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-RSZB7VAO.js";
|
|
8
8
|
import {
|
|
9
9
|
scanDir
|
|
10
10
|
} from "./chunk-RS4MXCPW.js";
|
|
@@ -15,23 +15,24 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
connectMongo,
|
|
17
17
|
db,
|
|
18
|
+
defineCollection,
|
|
18
19
|
defineModel,
|
|
19
20
|
defineTable,
|
|
20
21
|
getDbClient,
|
|
21
22
|
setDbClient,
|
|
22
23
|
transaction
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-RRQ2RK5M.js";
|
|
24
25
|
import {
|
|
25
26
|
HttpError,
|
|
26
27
|
ModelValidationError,
|
|
27
28
|
isHttpError,
|
|
28
29
|
setAutoSync,
|
|
29
30
|
setDbEngine
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-QKQZF573.js";
|
|
31
32
|
import {
|
|
32
33
|
configureQueryLog,
|
|
33
34
|
connectPostgres
|
|
34
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-HXV543HZ.js";
|
|
35
36
|
import {
|
|
36
37
|
closePgBoss,
|
|
37
38
|
initPgBoss
|
|
@@ -1000,10 +1001,10 @@ async function ignite(config) {
|
|
|
1000
1001
|
if (database) setDbEngine(database);
|
|
1001
1002
|
setAutoSync(config.autoSync ?? true);
|
|
1002
1003
|
if (database === "mongodb" && databaseUrl) {
|
|
1003
|
-
const conn = await connectMongo(databaseUrl);
|
|
1004
|
+
const conn = await connectMongo(databaseUrl, config.databasePool);
|
|
1004
1005
|
setDbClient(conn);
|
|
1005
1006
|
} else if (database === "postgresql" && databaseUrl) {
|
|
1006
|
-
const pool = await connectPostgres(databaseUrl);
|
|
1007
|
+
const pool = await connectPostgres(databaseUrl, config.databasePool);
|
|
1007
1008
|
setDbClient(pool);
|
|
1008
1009
|
}
|
|
1009
1010
|
if (config.cache) {
|
|
@@ -1126,6 +1127,7 @@ export {
|
|
|
1126
1127
|
cacheResponse,
|
|
1127
1128
|
compose,
|
|
1128
1129
|
db,
|
|
1130
|
+
defineCollection,
|
|
1129
1131
|
defineModel,
|
|
1130
1132
|
defineTable,
|
|
1131
1133
|
getDbClient,
|