@prisma-next/target-mongo 0.3.0-dev.146 → 0.3.0-dev.162
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 +19 -5
- package/dist/codec-types.d.mts +34 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +1 -0
- package/dist/control.d.mts +21 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +62 -0
- package/dist/control.mjs.map +1 -0
- package/dist/pack.d.mts +9 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +2 -1
- package/dist/pack.mjs.map +1 -1
- package/package.json +11 -2
- package/src/core/marker-ledger.ts +98 -0
- package/src/exports/codec-types.ts +12 -0
- package/src/exports/control.ts +1 -0
- package/src/exports/pack.ts +8 -1
package/README.md
CHANGED
|
@@ -4,10 +4,24 @@ MongoDB target pack for Prisma Next.
|
|
|
4
4
|
|
|
5
5
|
## Responsibilities
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **Target
|
|
7
|
+
- **Target pack assembly**: Exports the MongoDB target pack for authoring and family composition
|
|
8
|
+
- **Target metadata**: Defines the stable Mongo target identity (`kind`, `familyId`, `targetId`, `version`, `capabilities`)
|
|
9
|
+
- **Codec type surface**: Exposes the base Mongo codec type map used by authoring-time type composition
|
|
9
10
|
|
|
10
|
-
##
|
|
11
|
+
## Entrypoints
|
|
11
12
|
|
|
12
|
-
-
|
|
13
|
-
|
|
13
|
+
- `./pack`: pure target pack ref used by `@prisma-next/family-mongo` and `@prisma-next/mongo-contract-ts`
|
|
14
|
+
- `./codec-types`: base Mongo codec type map
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import mongoFamily from '@prisma-next/family-mongo/pack';
|
|
20
|
+
import { defineContract } from '@prisma-next/mongo-contract-ts/contract-builder';
|
|
21
|
+
import mongoTarget from '@prisma-next/target-mongo/pack';
|
|
22
|
+
|
|
23
|
+
const contract = defineContract({
|
|
24
|
+
family: mongoFamily,
|
|
25
|
+
target: mongoTarget,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/exports/codec-types.d.ts
|
|
2
|
+
type CodecTypes = {
|
|
3
|
+
readonly 'mongo/objectId@1': {
|
|
4
|
+
readonly input: string;
|
|
5
|
+
readonly output: string;
|
|
6
|
+
};
|
|
7
|
+
readonly 'mongo/string@1': {
|
|
8
|
+
readonly input: string;
|
|
9
|
+
readonly output: string;
|
|
10
|
+
};
|
|
11
|
+
readonly 'mongo/double@1': {
|
|
12
|
+
readonly input: number;
|
|
13
|
+
readonly output: number;
|
|
14
|
+
};
|
|
15
|
+
readonly 'mongo/int32@1': {
|
|
16
|
+
readonly input: number;
|
|
17
|
+
readonly output: number;
|
|
18
|
+
};
|
|
19
|
+
readonly 'mongo/bool@1': {
|
|
20
|
+
readonly input: boolean;
|
|
21
|
+
readonly output: boolean;
|
|
22
|
+
};
|
|
23
|
+
readonly 'mongo/date@1': {
|
|
24
|
+
readonly input: Date;
|
|
25
|
+
readonly output: Date;
|
|
26
|
+
};
|
|
27
|
+
readonly 'mongo/vector@1': {
|
|
28
|
+
readonly input: readonly number[];
|
|
29
|
+
readonly output: readonly number[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { CodecTypes };
|
|
34
|
+
//# sourceMappingURL=codec-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types.d.mts","names":[],"sources":["../src/exports/codec-types.ts"],"sourcesContent":[],"mappings":";KAAY,UAAA;EAAA,SAAA,kBAMiC,EAAA;;;;;;;;;;;;;;;;;;;;;oBAAA;qBAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
2
|
+
import { Db } from "mongodb";
|
|
3
|
+
|
|
4
|
+
//#region src/core/marker-ledger.d.ts
|
|
5
|
+
declare function readMarker(db: Db): Promise<ContractMarkerRecord | null>;
|
|
6
|
+
declare function initMarker(db: Db, destination: {
|
|
7
|
+
readonly storageHash: string;
|
|
8
|
+
readonly profileHash: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
declare function updateMarker(db: Db, expectedFrom: string, destination: {
|
|
11
|
+
readonly storageHash: string;
|
|
12
|
+
readonly profileHash: string;
|
|
13
|
+
}): Promise<boolean>;
|
|
14
|
+
declare function writeLedgerEntry(db: Db, entry: {
|
|
15
|
+
readonly edgeId: string;
|
|
16
|
+
readonly from: string;
|
|
17
|
+
readonly to: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { initMarker, readMarker, updateMarker, writeLedgerEntry };
|
|
21
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/marker-ledger.ts"],"sourcesContent":[],"mappings":";;;;iBA+BsB,UAAA,KAAe,KAAK,QAAQ;iBAgB5B,UAAA,KAChB;EAjBgB,SAAA,WAAU,EAAA,MAAA;EAAK,SAAA,WAAA,EAAA,MAAA;CAAa,CAAA,EAmB/C,OAnB+C,CAAA,IAAA,CAAA;AAAR,iBAiCpB,YAAA,CAjCoB,EAAA,EAkCpC,EAlCoC,EAAA,YAAA,EAAA,MAAA,EAAA,WAAA,EAAA;EAAO,SAAA,WAAA,EAAA,MAAA;EAgB3B,SAAA,WAAU,EAAA,MAG7B;AAcH,CAAA,CAAA,EAIG,OAJmB,CAAA,OAAY,CAAA;AAqBZ,iBAAA,gBAAA,CAGnB,EAAA,EAFG,EAEI,EAAA,KAAA,EAAA;;;;IAAP"}
|
package/dist/control.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { RawAggregateCommand, RawFindOneAndUpdateCommand, RawInsertOneCommand } from "@prisma-next/mongo-query-ast/execution";
|
|
2
|
+
|
|
3
|
+
//#region src/core/marker-ledger.ts
|
|
4
|
+
const COLLECTION = "_prisma_migrations";
|
|
5
|
+
const MARKER_ID = "marker";
|
|
6
|
+
async function executeAggregate(db, cmd) {
|
|
7
|
+
return db.collection(cmd.collection).aggregate(cmd.pipeline).toArray();
|
|
8
|
+
}
|
|
9
|
+
async function executeInsertOne(db, cmd) {
|
|
10
|
+
await db.collection(cmd.collection).insertOne(cmd.document);
|
|
11
|
+
}
|
|
12
|
+
async function executeFindOneAndUpdate(db, cmd) {
|
|
13
|
+
return db.collection(cmd.collection).findOneAndUpdate(cmd.filter, cmd.update, { upsert: cmd.upsert });
|
|
14
|
+
}
|
|
15
|
+
async function readMarker(db) {
|
|
16
|
+
const doc = (await executeAggregate(db, new RawAggregateCommand(COLLECTION, [{ $match: { _id: MARKER_ID } }, { $limit: 1 }])))[0];
|
|
17
|
+
if (!doc) return null;
|
|
18
|
+
return {
|
|
19
|
+
storageHash: doc["storageHash"],
|
|
20
|
+
profileHash: doc["profileHash"],
|
|
21
|
+
contractJson: doc["contractJson"] ?? null,
|
|
22
|
+
canonicalVersion: doc["canonicalVersion"] ?? null,
|
|
23
|
+
updatedAt: doc["updatedAt"],
|
|
24
|
+
appTag: doc["appTag"] ?? null,
|
|
25
|
+
meta: doc["meta"] ?? {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function initMarker(db, destination) {
|
|
29
|
+
await executeInsertOne(db, new RawInsertOneCommand(COLLECTION, {
|
|
30
|
+
_id: MARKER_ID,
|
|
31
|
+
storageHash: destination.storageHash,
|
|
32
|
+
profileHash: destination.profileHash,
|
|
33
|
+
contractJson: null,
|
|
34
|
+
canonicalVersion: null,
|
|
35
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
36
|
+
appTag: null,
|
|
37
|
+
meta: {}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
async function updateMarker(db, expectedFrom, destination) {
|
|
41
|
+
return await executeFindOneAndUpdate(db, new RawFindOneAndUpdateCommand(COLLECTION, {
|
|
42
|
+
_id: MARKER_ID,
|
|
43
|
+
storageHash: expectedFrom
|
|
44
|
+
}, { $set: {
|
|
45
|
+
storageHash: destination.storageHash,
|
|
46
|
+
profileHash: destination.profileHash,
|
|
47
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
48
|
+
} }, false)) !== null;
|
|
49
|
+
}
|
|
50
|
+
async function writeLedgerEntry(db, entry) {
|
|
51
|
+
await executeInsertOne(db, new RawInsertOneCommand(COLLECTION, {
|
|
52
|
+
type: "ledger",
|
|
53
|
+
edgeId: entry.edgeId,
|
|
54
|
+
from: entry.from,
|
|
55
|
+
to: entry.to,
|
|
56
|
+
appliedAt: /* @__PURE__ */ new Date()
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { initMarker, readMarker, updateMarker, writeLedgerEntry };
|
|
62
|
+
//# sourceMappingURL=control.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../src/core/marker-ledger.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport {\n RawAggregateCommand,\n RawFindOneAndUpdateCommand,\n RawInsertOneCommand,\n} from '@prisma-next/mongo-query-ast/execution';\nimport type { Db, Document } from 'mongodb';\n\nconst COLLECTION = '_prisma_migrations';\nconst MARKER_ID = 'marker';\n\nasync function executeAggregate(db: Db, cmd: RawAggregateCommand): Promise<Document[]> {\n return db\n .collection(cmd.collection)\n .aggregate(cmd.pipeline as Record<string, unknown>[])\n .toArray();\n}\n\nasync function executeInsertOne(db: Db, cmd: RawInsertOneCommand): Promise<void> {\n await db.collection(cmd.collection).insertOne(cmd.document);\n}\n\nasync function executeFindOneAndUpdate(\n db: Db,\n cmd: RawFindOneAndUpdateCommand,\n): Promise<Document | null> {\n return db\n .collection(cmd.collection)\n .findOneAndUpdate(cmd.filter, cmd.update as Record<string, unknown>, { upsert: cmd.upsert });\n}\n\nexport async function readMarker(db: Db): Promise<ContractMarkerRecord | null> {\n const cmd = new RawAggregateCommand(COLLECTION, [{ $match: { _id: MARKER_ID } }, { $limit: 1 }]);\n const docs = await executeAggregate(db, cmd);\n const doc = docs[0];\n if (!doc) return null;\n return {\n storageHash: doc['storageHash'] as string,\n profileHash: doc['profileHash'] as string,\n contractJson: (doc['contractJson'] as unknown) ?? null,\n canonicalVersion: (doc['canonicalVersion'] as number) ?? null,\n updatedAt: doc['updatedAt'] as Date,\n appTag: (doc['appTag'] as string) ?? null,\n meta: (doc['meta'] as Record<string, unknown>) ?? {},\n };\n}\n\nexport async function initMarker(\n db: Db,\n destination: { readonly storageHash: string; readonly profileHash: string },\n): Promise<void> {\n const cmd = new RawInsertOneCommand(COLLECTION, {\n _id: MARKER_ID,\n storageHash: destination.storageHash,\n profileHash: destination.profileHash,\n contractJson: null,\n canonicalVersion: null,\n updatedAt: new Date(),\n appTag: null,\n meta: {},\n });\n await executeInsertOne(db, cmd);\n}\n\nexport async function updateMarker(\n db: Db,\n expectedFrom: string,\n destination: { readonly storageHash: string; readonly profileHash: string },\n): Promise<boolean> {\n const cmd = new RawFindOneAndUpdateCommand(\n COLLECTION,\n { _id: MARKER_ID, storageHash: expectedFrom },\n {\n $set: {\n storageHash: destination.storageHash,\n profileHash: destination.profileHash,\n updatedAt: new Date(),\n },\n },\n false,\n );\n const result = await executeFindOneAndUpdate(db, cmd);\n return result !== null;\n}\n\nexport async function writeLedgerEntry(\n db: Db,\n entry: { readonly edgeId: string; readonly from: string; readonly to: string },\n): Promise<void> {\n const cmd = new RawInsertOneCommand(COLLECTION, {\n type: 'ledger',\n edgeId: entry.edgeId,\n from: entry.from,\n to: entry.to,\n appliedAt: new Date(),\n });\n await executeInsertOne(db, cmd);\n}\n"],"mappings":";;;AAQA,MAAM,aAAa;AACnB,MAAM,YAAY;AAElB,eAAe,iBAAiB,IAAQ,KAA+C;AACrF,QAAO,GACJ,WAAW,IAAI,WAAW,CAC1B,UAAU,IAAI,SAAsC,CACpD,SAAS;;AAGd,eAAe,iBAAiB,IAAQ,KAAyC;AAC/E,OAAM,GAAG,WAAW,IAAI,WAAW,CAAC,UAAU,IAAI,SAAS;;AAG7D,eAAe,wBACb,IACA,KAC0B;AAC1B,QAAO,GACJ,WAAW,IAAI,WAAW,CAC1B,iBAAiB,IAAI,QAAQ,IAAI,QAAmC,EAAE,QAAQ,IAAI,QAAQ,CAAC;;AAGhG,eAAsB,WAAW,IAA8C;CAG7E,MAAM,OADO,MAAM,iBAAiB,IADxB,IAAI,oBAAoB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,CAAC,CACpD,EAC3B;AACjB,KAAI,CAAC,IAAK,QAAO;AACjB,QAAO;EACL,aAAa,IAAI;EACjB,aAAa,IAAI;EACjB,cAAe,IAAI,mBAA+B;EAClD,kBAAmB,IAAI,uBAAkC;EACzD,WAAW,IAAI;EACf,QAAS,IAAI,aAAwB;EACrC,MAAO,IAAI,WAAuC,EAAE;EACrD;;AAGH,eAAsB,WACpB,IACA,aACe;AAWf,OAAM,iBAAiB,IAVX,IAAI,oBAAoB,YAAY;EAC9C,KAAK;EACL,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,cAAc;EACd,kBAAkB;EAClB,2BAAW,IAAI,MAAM;EACrB,QAAQ;EACR,MAAM,EAAE;EACT,CAAC,CAC6B;;AAGjC,eAAsB,aACpB,IACA,cACA,aACkB;AAclB,QADe,MAAM,wBAAwB,IAZjC,IAAI,2BACd,YACA;EAAE,KAAK;EAAW,aAAa;EAAc,EAC7C,EACE,MAAM;EACJ,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,2BAAW,IAAI,MAAM;EACtB,EACF,EACD,MACD,CACoD,KACnC;;AAGpB,eAAsB,iBACpB,IACA,OACe;AAQf,OAAM,iBAAiB,IAPX,IAAI,oBAAoB,YAAY;EAC9C,MAAM;EACN,QAAQ,MAAM;EACd,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,2BAAW,IAAI,MAAM;EACtB,CAAC,CAC6B"}
|
package/dist/pack.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { CodecTypes } from "./codec-types.mjs";
|
|
2
|
+
import { TargetPackRef } from "@prisma-next/framework-components/components";
|
|
3
|
+
|
|
4
|
+
//#region src/exports/pack.d.ts
|
|
5
|
+
declare const mongoTargetPack: {
|
|
3
6
|
readonly kind: "target";
|
|
4
7
|
readonly familyId: "mongo";
|
|
5
8
|
readonly targetId: "mongo";
|
|
@@ -7,6 +10,9 @@ declare const mongoTargetDescriptorMeta: {
|
|
|
7
10
|
readonly version: "0.0.1";
|
|
8
11
|
readonly capabilities: {};
|
|
9
12
|
};
|
|
13
|
+
declare const _default: typeof mongoTargetPack & TargetPackRef<"mongo", "mongo"> & {
|
|
14
|
+
readonly __codecTypes?: CodecTypes;
|
|
15
|
+
};
|
|
10
16
|
//#endregion
|
|
11
|
-
export {
|
|
17
|
+
export { _default as default };
|
|
12
18
|
//# sourceMappingURL=pack.d.mts.map
|
package/dist/pack.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":[],"mappings":";;;;cAIM;;EAAA,SAAA,QAAA,EAA2C,OAAA;EAAA,SAAA,QAK9C,EAAA,OAAA;EAHsC,SAAA,EAAA,EAAA,OAAA;EACvC,SAAA,OAAA,EAAA,OAAA;EAC0B,SAAA,YAAA,EAAA,CAAA,CAAA;CAAU;cAJW,iBAER,kBACvC;0BAC0B"}
|
package/dist/pack.mjs
CHANGED
|
@@ -10,7 +10,8 @@ const mongoTargetDescriptorMeta = {
|
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
//#region src/exports/pack.ts
|
|
13
|
-
|
|
13
|
+
const mongoTargetPack = mongoTargetDescriptorMeta;
|
|
14
|
+
var pack_default = mongoTargetPack;
|
|
14
15
|
|
|
15
16
|
//#endregion
|
|
16
17
|
export { pack_default as default };
|
package/dist/pack.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.mjs","names":[],"sources":["../src/core/descriptor-meta.ts","../src/exports/pack.ts"],"sourcesContent":["export const mongoTargetDescriptorMeta = {\n kind: 'target',\n familyId: 'mongo',\n targetId: 'mongo',\n id: 'mongo',\n version: '0.0.1',\n capabilities: {},\n} as const;\n","import { mongoTargetDescriptorMeta } from '../core/descriptor-meta';\n\nexport default
|
|
1
|
+
{"version":3,"file":"pack.mjs","names":[],"sources":["../src/core/descriptor-meta.ts","../src/exports/pack.ts"],"sourcesContent":["export const mongoTargetDescriptorMeta = {\n kind: 'target',\n familyId: 'mongo',\n targetId: 'mongo',\n id: 'mongo',\n version: '0.0.1',\n capabilities: {},\n} as const;\n","import type { TargetPackRef } from '@prisma-next/framework-components/components';\nimport { mongoTargetDescriptorMeta } from '../core/descriptor-meta';\nimport type { CodecTypes } from './codec-types';\n\nconst mongoTargetPack = mongoTargetDescriptorMeta;\n\nexport default mongoTargetPack as typeof mongoTargetPack &\n TargetPackRef<'mongo', 'mongo'> & {\n readonly __codecTypes?: CodecTypes;\n };\n"],"mappings":";AAAA,MAAa,4BAA4B;CACvC,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,EAAE;CACjB;;;;ACHD,MAAM,kBAAkB;AAExB,mBAAe"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-mongo",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.162",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "MongoDB target pack for Prisma Next",
|
|
7
|
-
"dependencies": {
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"mongodb": "^6.16.0",
|
|
9
|
+
"@prisma-next/contract": "0.3.0-dev.162",
|
|
10
|
+
"@prisma-next/framework-components": "0.3.0-dev.162",
|
|
11
|
+
"@prisma-next/mongo-query-ast": "0.3.0-dev.162"
|
|
12
|
+
},
|
|
8
13
|
"devDependencies": {
|
|
14
|
+
"mongodb-memory-server": "10.4.3",
|
|
9
15
|
"tsdown": "0.18.4",
|
|
10
16
|
"typescript": "5.9.3",
|
|
11
17
|
"vitest": "4.0.17",
|
|
18
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
12
19
|
"@prisma-next/tsconfig": "0.0.0",
|
|
13
20
|
"@prisma-next/tsdown": "0.0.0"
|
|
14
21
|
},
|
|
@@ -17,6 +24,8 @@
|
|
|
17
24
|
"src"
|
|
18
25
|
],
|
|
19
26
|
"exports": {
|
|
27
|
+
"./codec-types": "./dist/codec-types.mjs",
|
|
28
|
+
"./control": "./dist/control.mjs",
|
|
20
29
|
"./pack": "./dist/pack.mjs",
|
|
21
30
|
"./package.json": "./package.json"
|
|
22
31
|
},
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ContractMarkerRecord } from '@prisma-next/contract/types';
|
|
2
|
+
import {
|
|
3
|
+
RawAggregateCommand,
|
|
4
|
+
RawFindOneAndUpdateCommand,
|
|
5
|
+
RawInsertOneCommand,
|
|
6
|
+
} from '@prisma-next/mongo-query-ast/execution';
|
|
7
|
+
import type { Db, Document } from 'mongodb';
|
|
8
|
+
|
|
9
|
+
const COLLECTION = '_prisma_migrations';
|
|
10
|
+
const MARKER_ID = 'marker';
|
|
11
|
+
|
|
12
|
+
async function executeAggregate(db: Db, cmd: RawAggregateCommand): Promise<Document[]> {
|
|
13
|
+
return db
|
|
14
|
+
.collection(cmd.collection)
|
|
15
|
+
.aggregate(cmd.pipeline as Record<string, unknown>[])
|
|
16
|
+
.toArray();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function executeInsertOne(db: Db, cmd: RawInsertOneCommand): Promise<void> {
|
|
20
|
+
await db.collection(cmd.collection).insertOne(cmd.document);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function executeFindOneAndUpdate(
|
|
24
|
+
db: Db,
|
|
25
|
+
cmd: RawFindOneAndUpdateCommand,
|
|
26
|
+
): Promise<Document | null> {
|
|
27
|
+
return db
|
|
28
|
+
.collection(cmd.collection)
|
|
29
|
+
.findOneAndUpdate(cmd.filter, cmd.update as Record<string, unknown>, { upsert: cmd.upsert });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function readMarker(db: Db): Promise<ContractMarkerRecord | null> {
|
|
33
|
+
const cmd = new RawAggregateCommand(COLLECTION, [{ $match: { _id: MARKER_ID } }, { $limit: 1 }]);
|
|
34
|
+
const docs = await executeAggregate(db, cmd);
|
|
35
|
+
const doc = docs[0];
|
|
36
|
+
if (!doc) return null;
|
|
37
|
+
return {
|
|
38
|
+
storageHash: doc['storageHash'] as string,
|
|
39
|
+
profileHash: doc['profileHash'] as string,
|
|
40
|
+
contractJson: (doc['contractJson'] as unknown) ?? null,
|
|
41
|
+
canonicalVersion: (doc['canonicalVersion'] as number) ?? null,
|
|
42
|
+
updatedAt: doc['updatedAt'] as Date,
|
|
43
|
+
appTag: (doc['appTag'] as string) ?? null,
|
|
44
|
+
meta: (doc['meta'] as Record<string, unknown>) ?? {},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function initMarker(
|
|
49
|
+
db: Db,
|
|
50
|
+
destination: { readonly storageHash: string; readonly profileHash: string },
|
|
51
|
+
): Promise<void> {
|
|
52
|
+
const cmd = new RawInsertOneCommand(COLLECTION, {
|
|
53
|
+
_id: MARKER_ID,
|
|
54
|
+
storageHash: destination.storageHash,
|
|
55
|
+
profileHash: destination.profileHash,
|
|
56
|
+
contractJson: null,
|
|
57
|
+
canonicalVersion: null,
|
|
58
|
+
updatedAt: new Date(),
|
|
59
|
+
appTag: null,
|
|
60
|
+
meta: {},
|
|
61
|
+
});
|
|
62
|
+
await executeInsertOne(db, cmd);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function updateMarker(
|
|
66
|
+
db: Db,
|
|
67
|
+
expectedFrom: string,
|
|
68
|
+
destination: { readonly storageHash: string; readonly profileHash: string },
|
|
69
|
+
): Promise<boolean> {
|
|
70
|
+
const cmd = new RawFindOneAndUpdateCommand(
|
|
71
|
+
COLLECTION,
|
|
72
|
+
{ _id: MARKER_ID, storageHash: expectedFrom },
|
|
73
|
+
{
|
|
74
|
+
$set: {
|
|
75
|
+
storageHash: destination.storageHash,
|
|
76
|
+
profileHash: destination.profileHash,
|
|
77
|
+
updatedAt: new Date(),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
false,
|
|
81
|
+
);
|
|
82
|
+
const result = await executeFindOneAndUpdate(db, cmd);
|
|
83
|
+
return result !== null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function writeLedgerEntry(
|
|
87
|
+
db: Db,
|
|
88
|
+
entry: { readonly edgeId: string; readonly from: string; readonly to: string },
|
|
89
|
+
): Promise<void> {
|
|
90
|
+
const cmd = new RawInsertOneCommand(COLLECTION, {
|
|
91
|
+
type: 'ledger',
|
|
92
|
+
edgeId: entry.edgeId,
|
|
93
|
+
from: entry.from,
|
|
94
|
+
to: entry.to,
|
|
95
|
+
appliedAt: new Date(),
|
|
96
|
+
});
|
|
97
|
+
await executeInsertOne(db, cmd);
|
|
98
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CodecTypes = {
|
|
2
|
+
readonly 'mongo/objectId@1': { readonly input: string; readonly output: string };
|
|
3
|
+
readonly 'mongo/string@1': { readonly input: string; readonly output: string };
|
|
4
|
+
readonly 'mongo/double@1': { readonly input: number; readonly output: number };
|
|
5
|
+
readonly 'mongo/int32@1': { readonly input: number; readonly output: number };
|
|
6
|
+
readonly 'mongo/bool@1': { readonly input: boolean; readonly output: boolean };
|
|
7
|
+
readonly 'mongo/date@1': { readonly input: Date; readonly output: Date };
|
|
8
|
+
readonly 'mongo/vector@1': {
|
|
9
|
+
readonly input: readonly number[];
|
|
10
|
+
readonly output: readonly number[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initMarker, readMarker, updateMarker, writeLedgerEntry } from '../core/marker-ledger';
|
package/src/exports/pack.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type { TargetPackRef } from '@prisma-next/framework-components/components';
|
|
1
2
|
import { mongoTargetDescriptorMeta } from '../core/descriptor-meta';
|
|
3
|
+
import type { CodecTypes } from './codec-types';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
const mongoTargetPack = mongoTargetDescriptorMeta;
|
|
6
|
+
|
|
7
|
+
export default mongoTargetPack as typeof mongoTargetPack &
|
|
8
|
+
TargetPackRef<'mongo', 'mongo'> & {
|
|
9
|
+
readonly __codecTypes?: CodecTypes;
|
|
10
|
+
};
|