@prisma-next/mongo-wire 0.13.0-dev.4 → 0.13.0-dev.40
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/index.d.mts +65 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +74 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/exports/index.ts +11 -1
- package/src/wire-commands.ts +150 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DeleteManyResult, DeleteOneResult, InsertManyResult, InsertOneResult, UpdateManyResult, UpdateOneResult } from "@prisma-next/mongo-query-ast/execution";
|
|
2
|
+
import { CollModOptions, CreateCollectionOptions, CreateIndexOptions, MongoIndexKeyDirection } from "@prisma-next/mongo-query-ast/control";
|
|
2
3
|
import { Document, RawPipeline } from "@prisma-next/mongo-value";
|
|
4
|
+
import { CollationOptions, CreateCollectionOptions as CreateCollectionOptions$1, CreateIndexesOptions } from "@prisma-next/mongo-value/mongodb-types";
|
|
3
5
|
|
|
4
6
|
//#region src/wire-commands.d.ts
|
|
5
7
|
declare abstract class MongoWireCommand {
|
|
@@ -66,7 +68,68 @@ declare class AggregateWireCommand extends MongoWireCommand {
|
|
|
66
68
|
readonly pipeline: RawPipeline;
|
|
67
69
|
constructor(collection: string, pipeline: RawPipeline);
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
declare class CreateCollectionWireCommand extends MongoWireCommand implements CreateCollectionOptions$1 {
|
|
72
|
+
readonly kind: "createCollection";
|
|
73
|
+
readonly validator?: Record<string, unknown>;
|
|
74
|
+
readonly validationLevel?: 'strict' | 'moderate';
|
|
75
|
+
readonly validationAction?: 'error' | 'warn';
|
|
76
|
+
readonly capped?: boolean;
|
|
77
|
+
readonly size?: number;
|
|
78
|
+
readonly max?: number;
|
|
79
|
+
readonly timeseries?: {
|
|
80
|
+
timeField: string;
|
|
81
|
+
metaField?: string;
|
|
82
|
+
granularity?: 'seconds' | 'minutes' | 'hours';
|
|
83
|
+
};
|
|
84
|
+
readonly collation?: CollationOptions;
|
|
85
|
+
readonly changeStreamPreAndPostImages?: {
|
|
86
|
+
enabled: boolean;
|
|
87
|
+
};
|
|
88
|
+
readonly clusteredIndex?: {
|
|
89
|
+
key: Record<string, number>;
|
|
90
|
+
unique: boolean;
|
|
91
|
+
name?: string;
|
|
92
|
+
};
|
|
93
|
+
constructor(collection: string, options: CreateCollectionOptions);
|
|
94
|
+
}
|
|
95
|
+
declare class CreateIndexWireCommand extends MongoWireCommand implements CreateIndexesOptions {
|
|
96
|
+
readonly kind: "createIndex";
|
|
97
|
+
readonly key: Record<string, MongoIndexKeyDirection>;
|
|
98
|
+
readonly unique?: boolean;
|
|
99
|
+
readonly sparse?: boolean;
|
|
100
|
+
readonly expireAfterSeconds?: number;
|
|
101
|
+
readonly partialFilterExpression?: Record<string, unknown>;
|
|
102
|
+
readonly name?: string;
|
|
103
|
+
readonly wildcardProjection?: Record<string, 0 | 1>;
|
|
104
|
+
readonly collation?: CollationOptions;
|
|
105
|
+
readonly weights?: Record<string, number>;
|
|
106
|
+
readonly default_language?: string;
|
|
107
|
+
readonly language_override?: string;
|
|
108
|
+
constructor(collection: string, key: Record<string, MongoIndexKeyDirection>, options: CreateIndexOptions);
|
|
109
|
+
}
|
|
110
|
+
declare class DropCollectionWireCommand extends MongoWireCommand {
|
|
111
|
+
readonly kind: "dropCollection";
|
|
112
|
+
constructor(collection: string);
|
|
113
|
+
}
|
|
114
|
+
declare class DropIndexWireCommand extends MongoWireCommand {
|
|
115
|
+
readonly kind: "dropIndex";
|
|
116
|
+
readonly name: string;
|
|
117
|
+
constructor(collection: string, name: string);
|
|
118
|
+
}
|
|
119
|
+
declare class CollModWireCommand extends MongoWireCommand {
|
|
120
|
+
readonly kind: "collMod";
|
|
121
|
+
readonly validator?: Record<string, unknown>;
|
|
122
|
+
readonly validationLevel?: 'strict' | 'moderate';
|
|
123
|
+
readonly validationAction?: 'error' | 'warn';
|
|
124
|
+
readonly changeStreamPreAndPostImages?: {
|
|
125
|
+
enabled: boolean;
|
|
126
|
+
};
|
|
127
|
+
constructor(collection: string, options: CollModOptions);
|
|
128
|
+
}
|
|
129
|
+
type AnyMongoDmlWireCommand = InsertOneWireCommand | InsertManyWireCommand | UpdateOneWireCommand | UpdateManyWireCommand | DeleteOneWireCommand | DeleteManyWireCommand | FindOneAndUpdateWireCommand | FindOneAndDeleteWireCommand | AggregateWireCommand;
|
|
130
|
+
type AnyMongoDdlWireCommand = CreateCollectionWireCommand | CreateIndexWireCommand | DropCollectionWireCommand | DropIndexWireCommand | CollModWireCommand;
|
|
131
|
+
type AnyMongoWireCommand = AnyMongoDmlWireCommand | AnyMongoDdlWireCommand;
|
|
132
|
+
declare function isDdlWireCommand(cmd: AnyMongoWireCommand): cmd is AnyMongoDdlWireCommand;
|
|
70
133
|
//#endregion
|
|
71
|
-
export { AggregateWireCommand, type AnyMongoWireCommand, type DeleteManyResult, DeleteManyWireCommand, type DeleteOneResult, DeleteOneWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, type InsertManyResult, InsertManyWireCommand, type InsertOneResult, InsertOneWireCommand, type UpdateManyResult, UpdateManyWireCommand, type UpdateOneResult, UpdateOneWireCommand };
|
|
134
|
+
export { AggregateWireCommand, type AnyMongoDdlWireCommand, type AnyMongoDmlWireCommand, type AnyMongoWireCommand, CollModWireCommand, CreateCollectionWireCommand, CreateIndexWireCommand, type DeleteManyResult, DeleteManyWireCommand, type DeleteOneResult, DeleteOneWireCommand, DropCollectionWireCommand, DropIndexWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, type InsertManyResult, InsertManyWireCommand, type InsertOneResult, InsertOneWireCommand, type UpdateManyResult, UpdateManyWireCommand, type UpdateOneResult, UpdateOneWireCommand, isDdlWireCommand };
|
|
72
135
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/wire-commands.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/wire-commands.ts"],"mappings":";;;;;;uBAae,gBAAA;EAAA,kBACK,IAAA;EAAA,SACT,UAAA;EAAA,UAEA,WAAA,CAAa,UAAA;EAAA,UAIZ,MAAA;AAAA;AAAA,cAKC,oBAAA,SAA6B,gBAAA;EAAA,SAC/B,IAAA;EAAA,SACA,QAAA,EAAU,QAAA;cAEP,UAAA,UAAoB,QAAA,EAAU,QAAA;AAAA;AAAA,cAO/B,oBAAA,SAA6B,gBAAA;EAAA,SAC/B,IAAA;EAAA,SACA,MAAA,EAAQ,QAAA;EAAA,SACR,MAAA,EAAQ,QAAA,GAAW,aAAA,CAAc,QAAA;EAAA,SACjC,MAAA;cAGP,UAAA,UACA,MAAA,EAAQ,QAAA,EACR,MAAA,EAAQ,QAAA,GAAW,aAAA,CAAc,QAAA,GACjC,MAAA;AAAA;AAAA,cAUS,oBAAA,SAA6B,gBAAA;EAAA,SAC/B,IAAA;EAAA,SACA,MAAA,EAAQ,QAAA;cAEL,UAAA,UAAoB,MAAA,EAAQ,QAAA;AAAA;AAAA,cAO7B,qBAAA,SAA8B,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,SAAA,EAAW,aAAA,CAAc,QAAA;cAEtB,UAAA,UAAoB,SAAA,EAAW,aAAA,CAAc,QAAA;AAAA;AAAA,cAO9C,qBAAA,SAA8B,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,MAAA,EAAQ,QAAA;EAAA,SACR,MAAA,EAAQ,QAAA,GAAW,aAAA,CAAc,QAAA;EAAA,SACjC,MAAA;cAGP,UAAA,UACA,MAAA,EAAQ,QAAA,EACR,MAAA,EAAQ,QAAA,GAAW,aAAA,CAAc,QAAA,GACjC,MAAA;AAAA;AAAA,cAUS,qBAAA,SAA8B,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,MAAA,EA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SAAe,sBAAA;EAAA,SACZ,MAAA;EAAA,SACA,MAAA;EAAA,SACA,kBAAA;EAAA,SACA,uBAAA,GAA0B,MAAA;EAAA,SAC1B,IAAA;EAAA,SACA,kBAAA,GAAqB,MAAA;EAAA,SACrB,SAAA,GAAY,gBAAA;EAAA,SACZ,OAAA,GAAU,MAAA;EAAA,SACV,gBAAA;EAAA,SACA,iBAAA;cAGf,UAAA,UACA,GAAA,EAAK,MAAA,SAAe,sBAAA,GACpB,OAAA,EAAS,kBAAA;AAAA;AAAA,cAqBA,yBAAA,SAAkC,gBAAgB;EAAA,SACpD,IAAA;cAEG,UAAA;AAAA;AAAA,cAMD,oBAAA,SAA6B,gBAAgB;EAAA,SAC/C,IAAA;EAAA,SACA,IAAA;cAEG,UAAA,UAAoB,IAAA;AAAA;AAAA,cAOrB,kBAAA,SAA2B,gBAAA;EAAA,SAC7B,IAAA;EAAA,SACQ,SAAA,GAAY,MAAA;EAAA,SACZ,eAAA;EAAA,SACA,gBAAA;EAAA,SACA,4BAAA;IAAiC,OAAA;EAAA;cAEtC,UAAA,UAAoB,OAAA,EAAS,cAAA;AAAA;AAAA,KAW/B,sBAAA,GACR,oBAAA,GACA,qBAAA,GACA,oBAAA,GACA,qBAAA,GACA,oBAAA,GACA,qBAAA,GACA,2BAAA,GACA,2BAAA,GACA,oBAAA;AAAA,KAEQ,sBAAA,GACR,2BAAA,GACA,sBAAA,GACA,yBAAA,GACA,oBAAA,GACA,kBAAA;AAAA,KAEQ,mBAAA,GAAsB,sBAAA,GAAyB,sBAAsB;AAAA,iBAUjE,gBAAA,CAAiB,GAAA,EAAK,mBAAA,GAAsB,GAAA,IAAO,sBAAsB"}
|
package/dist/index.mjs
CHANGED
|
@@ -111,7 +111,80 @@ var AggregateWireCommand = class extends MongoWireCommand {
|
|
|
111
111
|
this.freeze();
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
|
+
var CreateCollectionWireCommand = class extends MongoWireCommand {
|
|
115
|
+
kind = "createCollection";
|
|
116
|
+
constructor(collection, options) {
|
|
117
|
+
super(collection);
|
|
118
|
+
if (options.validator !== void 0) this.validator = options.validator;
|
|
119
|
+
if (options.validationLevel !== void 0) this.validationLevel = options.validationLevel;
|
|
120
|
+
if (options.validationAction !== void 0) this.validationAction = options.validationAction;
|
|
121
|
+
if (options.capped !== void 0) this.capped = options.capped;
|
|
122
|
+
if (options.size !== void 0) this.size = options.size;
|
|
123
|
+
if (options.max !== void 0) this.max = options.max;
|
|
124
|
+
if (options.timeseries !== void 0) this.timeseries = options.timeseries;
|
|
125
|
+
if (options.collation !== void 0) this.collation = options.collation;
|
|
126
|
+
if (options.changeStreamPreAndPostImages !== void 0) this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;
|
|
127
|
+
if (options.clusteredIndex !== void 0) this.clusteredIndex = options.clusteredIndex;
|
|
128
|
+
this.freeze();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var CreateIndexWireCommand = class extends MongoWireCommand {
|
|
132
|
+
kind = "createIndex";
|
|
133
|
+
key;
|
|
134
|
+
constructor(collection, key, options) {
|
|
135
|
+
super(collection);
|
|
136
|
+
this.key = key;
|
|
137
|
+
if (options.unique !== void 0) this.unique = options.unique;
|
|
138
|
+
if (options.sparse !== void 0) this.sparse = options.sparse;
|
|
139
|
+
if (options.expireAfterSeconds !== void 0) this.expireAfterSeconds = options.expireAfterSeconds;
|
|
140
|
+
if (options.partialFilterExpression !== void 0) this.partialFilterExpression = options.partialFilterExpression;
|
|
141
|
+
if (options.name !== void 0) this.name = options.name;
|
|
142
|
+
if (options.wildcardProjection !== void 0) this.wildcardProjection = options.wildcardProjection;
|
|
143
|
+
if (options.collation !== void 0) this.collation = options.collation;
|
|
144
|
+
if (options.weights !== void 0) this.weights = options.weights;
|
|
145
|
+
if (options.default_language !== void 0) this.default_language = options.default_language;
|
|
146
|
+
if (options.language_override !== void 0) this.language_override = options.language_override;
|
|
147
|
+
this.freeze();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var DropCollectionWireCommand = class extends MongoWireCommand {
|
|
151
|
+
kind = "dropCollection";
|
|
152
|
+
constructor(collection) {
|
|
153
|
+
super(collection);
|
|
154
|
+
this.freeze();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var DropIndexWireCommand = class extends MongoWireCommand {
|
|
158
|
+
kind = "dropIndex";
|
|
159
|
+
name;
|
|
160
|
+
constructor(collection, name) {
|
|
161
|
+
super(collection);
|
|
162
|
+
this.name = name;
|
|
163
|
+
this.freeze();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var CollModWireCommand = class extends MongoWireCommand {
|
|
167
|
+
kind = "collMod";
|
|
168
|
+
constructor(collection, options) {
|
|
169
|
+
super(collection);
|
|
170
|
+
if (options.validator !== void 0) this.validator = options.validator;
|
|
171
|
+
if (options.validationLevel !== void 0) this.validationLevel = options.validationLevel;
|
|
172
|
+
if (options.validationAction !== void 0) this.validationAction = options.validationAction;
|
|
173
|
+
if (options.changeStreamPreAndPostImages !== void 0) this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;
|
|
174
|
+
this.freeze();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const DDL_KINDS = new Set([
|
|
178
|
+
"createCollection",
|
|
179
|
+
"createIndex",
|
|
180
|
+
"dropCollection",
|
|
181
|
+
"dropIndex",
|
|
182
|
+
"collMod"
|
|
183
|
+
]);
|
|
184
|
+
function isDdlWireCommand(cmd) {
|
|
185
|
+
return DDL_KINDS.has(cmd.kind);
|
|
186
|
+
}
|
|
114
187
|
//#endregion
|
|
115
|
-
export { AggregateWireCommand, DeleteManyWireCommand, DeleteOneWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyWireCommand, InsertOneWireCommand, UpdateManyWireCommand, UpdateOneWireCommand };
|
|
188
|
+
export { AggregateWireCommand, CollModWireCommand, CreateCollectionWireCommand, CreateIndexWireCommand, DeleteManyWireCommand, DeleteOneWireCommand, DropCollectionWireCommand, DropIndexWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyWireCommand, InsertOneWireCommand, UpdateManyWireCommand, UpdateOneWireCommand, isDdlWireCommand };
|
|
116
189
|
|
|
117
190
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/wire-commands.ts"],"sourcesContent":["import type { Document, RawPipeline } from '@prisma-next/mongo-value';\n\nabstract class MongoWireCommand {\n abstract readonly kind: string;\n readonly collection: string;\n\n protected constructor(collection: string) {\n this.collection = collection;\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\nexport class InsertOneWireCommand extends MongoWireCommand {\n readonly kind = 'insertOne' as const;\n readonly document: Document;\n\n constructor(collection: string, document: Document) {\n super(collection);\n this.document = document;\n this.freeze();\n }\n}\n\nexport class UpdateOneWireCommand extends MongoWireCommand {\n readonly kind = 'updateOne' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.freeze();\n }\n}\n\nexport class DeleteOneWireCommand extends MongoWireCommand {\n readonly kind = 'deleteOne' as const;\n readonly filter: Document;\n\n constructor(collection: string, filter: Document) {\n super(collection);\n this.filter = filter;\n this.freeze();\n }\n}\n\nexport class InsertManyWireCommand extends MongoWireCommand {\n readonly kind = 'insertMany' as const;\n readonly documents: ReadonlyArray<Document>;\n\n constructor(collection: string, documents: ReadonlyArray<Document>) {\n super(collection);\n this.documents = documents;\n this.freeze();\n }\n}\n\nexport class UpdateManyWireCommand extends MongoWireCommand {\n readonly kind = 'updateMany' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.freeze();\n }\n}\n\nexport class DeleteManyWireCommand extends MongoWireCommand {\n readonly kind = 'deleteMany' as const;\n readonly filter: Document;\n\n constructor(collection: string, filter: Document) {\n super(collection);\n this.filter = filter;\n this.freeze();\n }\n}\n\nexport class FindOneAndUpdateWireCommand extends MongoWireCommand {\n readonly kind = 'findOneAndUpdate' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n readonly sort: Record<string, 1 | -1> | undefined;\n /**\n * When `undefined`, the option is omitted from the underlying driver\n * call so Mongo's documented default (pre-image document) applies.\n */\n readonly returnDocument: 'before' | 'after' | undefined;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n sort?: Record<string, 1 | -1>,\n returnDocument?: 'before' | 'after',\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.sort = sort;\n this.returnDocument = returnDocument;\n this.freeze();\n }\n}\n\nexport class FindOneAndDeleteWireCommand extends MongoWireCommand {\n readonly kind = 'findOneAndDelete' as const;\n readonly filter: Document;\n readonly sort: Record<string, 1 | -1> | undefined;\n\n constructor(collection: string, filter: Document, sort?: Record<string, 1 | -1>) {\n super(collection);\n this.filter = filter;\n this.sort = sort;\n this.freeze();\n }\n}\n\nexport class AggregateWireCommand extends MongoWireCommand {\n readonly kind = 'aggregate' as const;\n readonly pipeline: RawPipeline;\n\n constructor(collection: string, pipeline: RawPipeline) {\n super(collection);\n this.pipeline = pipeline;\n this.freeze();\n }\n}\n\nexport type AnyMongoWireCommand =\n | InsertOneWireCommand\n | InsertManyWireCommand\n | UpdateOneWireCommand\n | UpdateManyWireCommand\n | DeleteOneWireCommand\n | DeleteManyWireCommand\n | FindOneAndUpdateWireCommand\n | FindOneAndDeleteWireCommand\n | AggregateWireCommand;\n"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A,MAAM,UAAU;EAChB,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,iBAAiB;EACtB,KAAK,OAAO;CACd;AACF;AAEA,IAAa,8BAAb,cAAiD,iBAAiB;CAChE,OAAgB;CAChB;CACA;CAEA,YAAY,YAAoB,QAAkB,MAA+B;EAC/E,MAAM,UAAU;EAChB,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,YAAoB,UAAuB;EACrD,MAAM,UAAU;EAChB,KAAK,WAAW;EAChB,KAAK,OAAO;CACd;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/wire-commands.ts"],"sourcesContent":["import type {\n CollModOptions,\n CreateCollectionOptions as CreateCollectionCommandOptions,\n CreateIndexOptions,\n MongoIndexKeyDirection,\n} from '@prisma-next/mongo-query-ast/control';\nimport type { Document, RawPipeline } from '@prisma-next/mongo-value';\nimport type {\n CollationOptions,\n CreateCollectionOptions,\n CreateIndexesOptions,\n} from '@prisma-next/mongo-value/mongodb-types';\n\nabstract class MongoWireCommand {\n abstract readonly kind: string;\n readonly collection: string;\n\n protected constructor(collection: string) {\n this.collection = collection;\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\nexport class InsertOneWireCommand extends MongoWireCommand {\n readonly kind = 'insertOne' as const;\n readonly document: Document;\n\n constructor(collection: string, document: Document) {\n super(collection);\n this.document = document;\n this.freeze();\n }\n}\n\nexport class UpdateOneWireCommand extends MongoWireCommand {\n readonly kind = 'updateOne' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.freeze();\n }\n}\n\nexport class DeleteOneWireCommand extends MongoWireCommand {\n readonly kind = 'deleteOne' as const;\n readonly filter: Document;\n\n constructor(collection: string, filter: Document) {\n super(collection);\n this.filter = filter;\n this.freeze();\n }\n}\n\nexport class InsertManyWireCommand extends MongoWireCommand {\n readonly kind = 'insertMany' as const;\n readonly documents: ReadonlyArray<Document>;\n\n constructor(collection: string, documents: ReadonlyArray<Document>) {\n super(collection);\n this.documents = documents;\n this.freeze();\n }\n}\n\nexport class UpdateManyWireCommand extends MongoWireCommand {\n readonly kind = 'updateMany' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.freeze();\n }\n}\n\nexport class DeleteManyWireCommand extends MongoWireCommand {\n readonly kind = 'deleteMany' as const;\n readonly filter: Document;\n\n constructor(collection: string, filter: Document) {\n super(collection);\n this.filter = filter;\n this.freeze();\n }\n}\n\nexport class FindOneAndUpdateWireCommand extends MongoWireCommand {\n readonly kind = 'findOneAndUpdate' as const;\n readonly filter: Document;\n readonly update: Document | ReadonlyArray<Document>;\n readonly upsert: boolean;\n readonly sort: Record<string, 1 | -1> | undefined;\n /**\n * When `undefined`, the option is omitted from the underlying driver\n * call so Mongo's documented default (pre-image document) applies.\n */\n readonly returnDocument: 'before' | 'after' | undefined;\n\n constructor(\n collection: string,\n filter: Document,\n update: Document | ReadonlyArray<Document>,\n upsert = false,\n sort?: Record<string, 1 | -1>,\n returnDocument?: 'before' | 'after',\n ) {\n super(collection);\n this.filter = filter;\n this.update = update;\n this.upsert = upsert;\n this.sort = sort;\n this.returnDocument = returnDocument;\n this.freeze();\n }\n}\n\nexport class FindOneAndDeleteWireCommand extends MongoWireCommand {\n readonly kind = 'findOneAndDelete' as const;\n readonly filter: Document;\n readonly sort: Record<string, 1 | -1> | undefined;\n\n constructor(collection: string, filter: Document, sort?: Record<string, 1 | -1>) {\n super(collection);\n this.filter = filter;\n this.sort = sort;\n this.freeze();\n }\n}\n\nexport class AggregateWireCommand extends MongoWireCommand {\n readonly kind = 'aggregate' as const;\n readonly pipeline: RawPipeline;\n\n constructor(collection: string, pipeline: RawPipeline) {\n super(collection);\n this.pipeline = pipeline;\n this.freeze();\n }\n}\n\nexport class CreateCollectionWireCommand\n extends MongoWireCommand\n implements CreateCollectionOptions\n{\n readonly kind = 'createCollection' as const;\n declare readonly validator?: Record<string, unknown>;\n declare readonly validationLevel?: 'strict' | 'moderate';\n declare readonly validationAction?: 'error' | 'warn';\n declare readonly capped?: boolean;\n declare readonly size?: number;\n declare readonly max?: number;\n declare readonly timeseries?: {\n timeField: string;\n metaField?: string;\n granularity?: 'seconds' | 'minutes' | 'hours';\n };\n declare readonly collation?: CollationOptions;\n declare readonly changeStreamPreAndPostImages?: { enabled: boolean };\n declare readonly clusteredIndex?: {\n key: Record<string, number>;\n unique: boolean;\n name?: string;\n };\n\n constructor(collection: string, options: CreateCollectionCommandOptions) {\n super(collection);\n if (options.validator !== undefined) this.validator = options.validator;\n if (options.validationLevel !== undefined) this.validationLevel = options.validationLevel;\n if (options.validationAction !== undefined) this.validationAction = options.validationAction;\n if (options.capped !== undefined) this.capped = options.capped;\n if (options.size !== undefined) this.size = options.size;\n if (options.max !== undefined) this.max = options.max;\n if (options.timeseries !== undefined) this.timeseries = options.timeseries;\n if (options.collation !== undefined) this.collation = options.collation;\n if (options.changeStreamPreAndPostImages !== undefined)\n this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;\n if (options.clusteredIndex !== undefined) this.clusteredIndex = options.clusteredIndex;\n this.freeze();\n }\n}\n\nexport class CreateIndexWireCommand extends MongoWireCommand implements CreateIndexesOptions {\n readonly kind = 'createIndex' as const;\n readonly key: Record<string, MongoIndexKeyDirection>;\n declare readonly unique?: boolean;\n declare readonly sparse?: boolean;\n declare readonly expireAfterSeconds?: number;\n declare readonly partialFilterExpression?: Record<string, unknown>;\n declare readonly name?: string;\n declare readonly wildcardProjection?: Record<string, 0 | 1>;\n declare readonly collation?: CollationOptions;\n declare readonly weights?: Record<string, number>;\n declare readonly default_language?: string;\n declare readonly language_override?: string;\n\n constructor(\n collection: string,\n key: Record<string, MongoIndexKeyDirection>,\n options: CreateIndexOptions,\n ) {\n super(collection);\n this.key = key;\n if (options.unique !== undefined) this.unique = options.unique;\n if (options.sparse !== undefined) this.sparse = options.sparse;\n if (options.expireAfterSeconds !== undefined)\n this.expireAfterSeconds = options.expireAfterSeconds;\n if (options.partialFilterExpression !== undefined)\n this.partialFilterExpression = options.partialFilterExpression;\n if (options.name !== undefined) this.name = options.name;\n if (options.wildcardProjection !== undefined)\n this.wildcardProjection = options.wildcardProjection;\n if (options.collation !== undefined) this.collation = options.collation;\n if (options.weights !== undefined) this.weights = options.weights;\n if (options.default_language !== undefined) this.default_language = options.default_language;\n if (options.language_override !== undefined) this.language_override = options.language_override;\n this.freeze();\n }\n}\n\nexport class DropCollectionWireCommand extends MongoWireCommand {\n readonly kind = 'dropCollection' as const;\n\n constructor(collection: string) {\n super(collection);\n this.freeze();\n }\n}\n\nexport class DropIndexWireCommand extends MongoWireCommand {\n readonly kind = 'dropIndex' as const;\n readonly name: string;\n\n constructor(collection: string, name: string) {\n super(collection);\n this.name = name;\n this.freeze();\n }\n}\n\nexport class CollModWireCommand extends MongoWireCommand {\n readonly kind = 'collMod' as const;\n declare readonly validator?: Record<string, unknown>;\n declare readonly validationLevel?: 'strict' | 'moderate';\n declare readonly validationAction?: 'error' | 'warn';\n declare readonly changeStreamPreAndPostImages?: { enabled: boolean };\n\n constructor(collection: string, options: CollModOptions) {\n super(collection);\n if (options.validator !== undefined) this.validator = options.validator;\n if (options.validationLevel !== undefined) this.validationLevel = options.validationLevel;\n if (options.validationAction !== undefined) this.validationAction = options.validationAction;\n if (options.changeStreamPreAndPostImages !== undefined)\n this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;\n this.freeze();\n }\n}\n\nexport type AnyMongoDmlWireCommand =\n | InsertOneWireCommand\n | InsertManyWireCommand\n | UpdateOneWireCommand\n | UpdateManyWireCommand\n | DeleteOneWireCommand\n | DeleteManyWireCommand\n | FindOneAndUpdateWireCommand\n | FindOneAndDeleteWireCommand\n | AggregateWireCommand;\n\nexport type AnyMongoDdlWireCommand =\n | CreateCollectionWireCommand\n | CreateIndexWireCommand\n | DropCollectionWireCommand\n | DropIndexWireCommand\n | CollModWireCommand;\n\nexport type AnyMongoWireCommand = AnyMongoDmlWireCommand | AnyMongoDdlWireCommand;\n\nconst DDL_KINDS: ReadonlySet<string> = new Set([\n 'createCollection',\n 'createIndex',\n 'dropCollection',\n 'dropIndex',\n 'collMod',\n]);\n\nexport function isDdlWireCommand(cmd: AnyMongoWireCommand): cmd is AnyMongoDdlWireCommand {\n return DDL_KINDS.has(cmd.kind);\n}\n"],"mappings":";AAaA,IAAe,mBAAf,MAAgC;CAE9B;CAEA,YAAsB,YAAoB;EACxC,KAAK,aAAa;CACpB;CAEA,SAAyB;EACvB,OAAO,OAAO,IAAI;CACpB;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,YAAoB,UAAoB;EAClD,MAAM,UAAU;EAChB,KAAK,WAAW;EAChB,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CACA;CACA;CAEA,YACE,YACA,QACA,QACA,SAAS,OACT;EACA,MAAM,UAAU;EAChB,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,YAAoB,QAAkB;EAChD,MAAM,UAAU;EAChB,KAAK,SAAS;EACd,KAAK,OAAO;CACd;AACF;AAEA,IAAa,wBAAb,cAA2C,iBAAiB;CAC1D,OAAgB;CAChB;C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Aa,4BAAb,cAA+C,iBAAiB;CAC9D,OAAgB;CAEhB,YAAY,YAAoB;EAC9B,MAAM,UAAU;EAChB,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,YAAoB,MAAc;EAC5C,MAAM,UAAU;EAChB,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,iBAAiB;CACvD,OAAgB;CAMhB,YAAY,YAAoB,SAAyB;EACvD,MAAM,UAAU;EAChB,IAAI,QAAQ,cAAc,KAAA,GAAW,KAAK,YAAY,QAAQ;EAC9D,IAAI,QAAQ,oBAAoB,KAAA,GAAW,KAAK,kBAAkB,QAAQ;EAC1E,IAAI,QAAQ,qBAAqB,KAAA,GAAW,KAAK,mBAAmB,QAAQ;EAC5E,IAAI,QAAQ,iCAAiC,KAAA,GAC3C,KAAK,+BAA+B,QAAQ;EAC9C,KAAK,OAAO;CACd;AACF;AAsBA,MAAM,YAAiC,IAAI,IAAI;CAC7C;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,KAAyD;CACxF,OAAO,UAAU,IAAI,IAAI,IAAI;AAC/B"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/mongo-wire",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.40",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Wire command types and result types for Prisma Next MongoDB support",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/mongo-query-ast": "0.13.0-dev.
|
|
10
|
-
"@prisma-next/mongo-value": "0.13.0-dev.
|
|
9
|
+
"@prisma-next/mongo-query-ast": "0.13.0-dev.40",
|
|
10
|
+
"@prisma-next/mongo-value": "0.13.0-dev.40",
|
|
11
|
+
"@prisma-next/utils": "0.13.0-dev.40"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
14
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
14
|
+
"@prisma-next/tsconfig": "0.13.0-dev.40",
|
|
15
|
+
"@prisma-next/tsdown": "0.13.0-dev.40",
|
|
15
16
|
"tsdown": "0.22.1",
|
|
16
17
|
"typescript": "5.9.3",
|
|
17
18
|
"vitest": "4.1.8"
|
package/src/exports/index.ts
CHANGED
|
@@ -6,15 +6,25 @@ export type {
|
|
|
6
6
|
UpdateManyResult,
|
|
7
7
|
UpdateOneResult,
|
|
8
8
|
} from '../results';
|
|
9
|
-
export type {
|
|
9
|
+
export type {
|
|
10
|
+
AnyMongoDdlWireCommand,
|
|
11
|
+
AnyMongoDmlWireCommand,
|
|
12
|
+
AnyMongoWireCommand,
|
|
13
|
+
} from '../wire-commands';
|
|
10
14
|
export {
|
|
11
15
|
AggregateWireCommand,
|
|
16
|
+
CollModWireCommand,
|
|
17
|
+
CreateCollectionWireCommand,
|
|
18
|
+
CreateIndexWireCommand,
|
|
12
19
|
DeleteManyWireCommand,
|
|
13
20
|
DeleteOneWireCommand,
|
|
21
|
+
DropCollectionWireCommand,
|
|
22
|
+
DropIndexWireCommand,
|
|
14
23
|
FindOneAndDeleteWireCommand,
|
|
15
24
|
FindOneAndUpdateWireCommand,
|
|
16
25
|
InsertManyWireCommand,
|
|
17
26
|
InsertOneWireCommand,
|
|
27
|
+
isDdlWireCommand,
|
|
18
28
|
UpdateManyWireCommand,
|
|
19
29
|
UpdateOneWireCommand,
|
|
20
30
|
} from '../wire-commands';
|
package/src/wire-commands.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CollModOptions,
|
|
3
|
+
CreateCollectionOptions as CreateCollectionCommandOptions,
|
|
4
|
+
CreateIndexOptions,
|
|
5
|
+
MongoIndexKeyDirection,
|
|
6
|
+
} from '@prisma-next/mongo-query-ast/control';
|
|
1
7
|
import type { Document, RawPipeline } from '@prisma-next/mongo-value';
|
|
8
|
+
import type {
|
|
9
|
+
CollationOptions,
|
|
10
|
+
CreateCollectionOptions,
|
|
11
|
+
CreateIndexesOptions,
|
|
12
|
+
} from '@prisma-next/mongo-value/mongodb-types';
|
|
2
13
|
|
|
3
14
|
abstract class MongoWireCommand {
|
|
4
15
|
abstract readonly kind: string;
|
|
@@ -151,7 +162,124 @@ export class AggregateWireCommand extends MongoWireCommand {
|
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
164
|
|
|
154
|
-
export
|
|
165
|
+
export class CreateCollectionWireCommand
|
|
166
|
+
extends MongoWireCommand
|
|
167
|
+
implements CreateCollectionOptions
|
|
168
|
+
{
|
|
169
|
+
readonly kind = 'createCollection' as const;
|
|
170
|
+
declare readonly validator?: Record<string, unknown>;
|
|
171
|
+
declare readonly validationLevel?: 'strict' | 'moderate';
|
|
172
|
+
declare readonly validationAction?: 'error' | 'warn';
|
|
173
|
+
declare readonly capped?: boolean;
|
|
174
|
+
declare readonly size?: number;
|
|
175
|
+
declare readonly max?: number;
|
|
176
|
+
declare readonly timeseries?: {
|
|
177
|
+
timeField: string;
|
|
178
|
+
metaField?: string;
|
|
179
|
+
granularity?: 'seconds' | 'minutes' | 'hours';
|
|
180
|
+
};
|
|
181
|
+
declare readonly collation?: CollationOptions;
|
|
182
|
+
declare readonly changeStreamPreAndPostImages?: { enabled: boolean };
|
|
183
|
+
declare readonly clusteredIndex?: {
|
|
184
|
+
key: Record<string, number>;
|
|
185
|
+
unique: boolean;
|
|
186
|
+
name?: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
constructor(collection: string, options: CreateCollectionCommandOptions) {
|
|
190
|
+
super(collection);
|
|
191
|
+
if (options.validator !== undefined) this.validator = options.validator;
|
|
192
|
+
if (options.validationLevel !== undefined) this.validationLevel = options.validationLevel;
|
|
193
|
+
if (options.validationAction !== undefined) this.validationAction = options.validationAction;
|
|
194
|
+
if (options.capped !== undefined) this.capped = options.capped;
|
|
195
|
+
if (options.size !== undefined) this.size = options.size;
|
|
196
|
+
if (options.max !== undefined) this.max = options.max;
|
|
197
|
+
if (options.timeseries !== undefined) this.timeseries = options.timeseries;
|
|
198
|
+
if (options.collation !== undefined) this.collation = options.collation;
|
|
199
|
+
if (options.changeStreamPreAndPostImages !== undefined)
|
|
200
|
+
this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;
|
|
201
|
+
if (options.clusteredIndex !== undefined) this.clusteredIndex = options.clusteredIndex;
|
|
202
|
+
this.freeze();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class CreateIndexWireCommand extends MongoWireCommand implements CreateIndexesOptions {
|
|
207
|
+
readonly kind = 'createIndex' as const;
|
|
208
|
+
readonly key: Record<string, MongoIndexKeyDirection>;
|
|
209
|
+
declare readonly unique?: boolean;
|
|
210
|
+
declare readonly sparse?: boolean;
|
|
211
|
+
declare readonly expireAfterSeconds?: number;
|
|
212
|
+
declare readonly partialFilterExpression?: Record<string, unknown>;
|
|
213
|
+
declare readonly name?: string;
|
|
214
|
+
declare readonly wildcardProjection?: Record<string, 0 | 1>;
|
|
215
|
+
declare readonly collation?: CollationOptions;
|
|
216
|
+
declare readonly weights?: Record<string, number>;
|
|
217
|
+
declare readonly default_language?: string;
|
|
218
|
+
declare readonly language_override?: string;
|
|
219
|
+
|
|
220
|
+
constructor(
|
|
221
|
+
collection: string,
|
|
222
|
+
key: Record<string, MongoIndexKeyDirection>,
|
|
223
|
+
options: CreateIndexOptions,
|
|
224
|
+
) {
|
|
225
|
+
super(collection);
|
|
226
|
+
this.key = key;
|
|
227
|
+
if (options.unique !== undefined) this.unique = options.unique;
|
|
228
|
+
if (options.sparse !== undefined) this.sparse = options.sparse;
|
|
229
|
+
if (options.expireAfterSeconds !== undefined)
|
|
230
|
+
this.expireAfterSeconds = options.expireAfterSeconds;
|
|
231
|
+
if (options.partialFilterExpression !== undefined)
|
|
232
|
+
this.partialFilterExpression = options.partialFilterExpression;
|
|
233
|
+
if (options.name !== undefined) this.name = options.name;
|
|
234
|
+
if (options.wildcardProjection !== undefined)
|
|
235
|
+
this.wildcardProjection = options.wildcardProjection;
|
|
236
|
+
if (options.collation !== undefined) this.collation = options.collation;
|
|
237
|
+
if (options.weights !== undefined) this.weights = options.weights;
|
|
238
|
+
if (options.default_language !== undefined) this.default_language = options.default_language;
|
|
239
|
+
if (options.language_override !== undefined) this.language_override = options.language_override;
|
|
240
|
+
this.freeze();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export class DropCollectionWireCommand extends MongoWireCommand {
|
|
245
|
+
readonly kind = 'dropCollection' as const;
|
|
246
|
+
|
|
247
|
+
constructor(collection: string) {
|
|
248
|
+
super(collection);
|
|
249
|
+
this.freeze();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export class DropIndexWireCommand extends MongoWireCommand {
|
|
254
|
+
readonly kind = 'dropIndex' as const;
|
|
255
|
+
readonly name: string;
|
|
256
|
+
|
|
257
|
+
constructor(collection: string, name: string) {
|
|
258
|
+
super(collection);
|
|
259
|
+
this.name = name;
|
|
260
|
+
this.freeze();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export class CollModWireCommand extends MongoWireCommand {
|
|
265
|
+
readonly kind = 'collMod' as const;
|
|
266
|
+
declare readonly validator?: Record<string, unknown>;
|
|
267
|
+
declare readonly validationLevel?: 'strict' | 'moderate';
|
|
268
|
+
declare readonly validationAction?: 'error' | 'warn';
|
|
269
|
+
declare readonly changeStreamPreAndPostImages?: { enabled: boolean };
|
|
270
|
+
|
|
271
|
+
constructor(collection: string, options: CollModOptions) {
|
|
272
|
+
super(collection);
|
|
273
|
+
if (options.validator !== undefined) this.validator = options.validator;
|
|
274
|
+
if (options.validationLevel !== undefined) this.validationLevel = options.validationLevel;
|
|
275
|
+
if (options.validationAction !== undefined) this.validationAction = options.validationAction;
|
|
276
|
+
if (options.changeStreamPreAndPostImages !== undefined)
|
|
277
|
+
this.changeStreamPreAndPostImages = options.changeStreamPreAndPostImages;
|
|
278
|
+
this.freeze();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type AnyMongoDmlWireCommand =
|
|
155
283
|
| InsertOneWireCommand
|
|
156
284
|
| InsertManyWireCommand
|
|
157
285
|
| UpdateOneWireCommand
|
|
@@ -161,3 +289,24 @@ export type AnyMongoWireCommand =
|
|
|
161
289
|
| FindOneAndUpdateWireCommand
|
|
162
290
|
| FindOneAndDeleteWireCommand
|
|
163
291
|
| AggregateWireCommand;
|
|
292
|
+
|
|
293
|
+
export type AnyMongoDdlWireCommand =
|
|
294
|
+
| CreateCollectionWireCommand
|
|
295
|
+
| CreateIndexWireCommand
|
|
296
|
+
| DropCollectionWireCommand
|
|
297
|
+
| DropIndexWireCommand
|
|
298
|
+
| CollModWireCommand;
|
|
299
|
+
|
|
300
|
+
export type AnyMongoWireCommand = AnyMongoDmlWireCommand | AnyMongoDdlWireCommand;
|
|
301
|
+
|
|
302
|
+
const DDL_KINDS: ReadonlySet<string> = new Set([
|
|
303
|
+
'createCollection',
|
|
304
|
+
'createIndex',
|
|
305
|
+
'dropCollection',
|
|
306
|
+
'dropIndex',
|
|
307
|
+
'collMod',
|
|
308
|
+
]);
|
|
309
|
+
|
|
310
|
+
export function isDdlWireCommand(cmd: AnyMongoWireCommand): cmd is AnyMongoDdlWireCommand {
|
|
311
|
+
return DDL_KINDS.has(cmd.kind);
|
|
312
|
+
}
|