@micro-cms/mock-db 1.0.5 → 1.0.8
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 +31 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +148 -117
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -0
- package/package.json +8 -7
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DataProvider, Schema, CmsModule } from '@micro-cms/types';
|
|
2
|
+
|
|
3
|
+
declare class MockDataProvider implements DataProvider {
|
|
4
|
+
introspect(): Promise<Schema>;
|
|
5
|
+
find(entity: string, query?: {
|
|
6
|
+
page?: number;
|
|
7
|
+
limit?: number;
|
|
8
|
+
}): Promise<any>;
|
|
9
|
+
findById(entity: string, id: any): Promise<any>;
|
|
10
|
+
create(entity: string, data: any): Promise<any>;
|
|
11
|
+
update(entity: string, id: any, data: any): Promise<any>;
|
|
12
|
+
delete(entity: string, id: any): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
declare class MockPaymentProvider {
|
|
15
|
+
initiatePayment(orderId: string, options: any): Promise<{
|
|
16
|
+
orderId: string;
|
|
17
|
+
paymentAddress: string;
|
|
18
|
+
amount: any;
|
|
19
|
+
currency: any;
|
|
20
|
+
network: string;
|
|
21
|
+
nonce: string;
|
|
22
|
+
}>;
|
|
23
|
+
verifyPayment(txHash: string, orderId: string): Promise<{
|
|
24
|
+
transactionHash: string;
|
|
25
|
+
orderId: string;
|
|
26
|
+
status: "confirmed";
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
declare const mockDbModule: CmsModule;
|
|
30
|
+
|
|
31
|
+
export { MockDataProvider, MockPaymentProvider, mockDbModule as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DataProvider, Schema, CmsModule } from '@micro-cms/types';
|
|
2
|
+
|
|
3
|
+
declare class MockDataProvider implements DataProvider {
|
|
3
4
|
introspect(): Promise<Schema>;
|
|
4
5
|
find(entity: string, query?: {
|
|
5
6
|
page?: number;
|
|
@@ -10,7 +11,7 @@ export declare class MockDataProvider implements DataProvider {
|
|
|
10
11
|
update(entity: string, id: any, data: any): Promise<any>;
|
|
11
12
|
delete(entity: string, id: any): Promise<any>;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
declare class MockPaymentProvider {
|
|
14
15
|
initiatePayment(orderId: string, options: any): Promise<{
|
|
15
16
|
orderId: string;
|
|
16
17
|
paymentAddress: string;
|
|
@@ -22,9 +23,9 @@ export declare class MockPaymentProvider {
|
|
|
22
23
|
verifyPayment(txHash: string, orderId: string): Promise<{
|
|
23
24
|
transactionHash: string;
|
|
24
25
|
orderId: string;
|
|
25
|
-
status:
|
|
26
|
+
status: "confirmed";
|
|
26
27
|
}>;
|
|
27
28
|
}
|
|
28
29
|
declare const mockDbModule: CmsModule;
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
export { MockDataProvider, MockPaymentProvider, mockDbModule as default };
|
package/dist/index.js
CHANGED
|
@@ -1,122 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{ name: 'isActive', type: 'boolean', label: 'Active User' },
|
|
10
|
-
{ name: 'role', type: 'select', constraints: { options: ['admin', 'editor', 'viewer'] } }
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
name: 'posts',
|
|
15
|
-
fields: [
|
|
16
|
-
{ name: 'id', type: 'number', constraints: { required: true } },
|
|
17
|
-
{ name: 'title', type: 'text', constraints: { required: true } },
|
|
18
|
-
{ name: 'content', type: 'text' },
|
|
19
|
-
{ name: 'publishedAt', type: 'date' },
|
|
20
|
-
{ name: 'authorId', type: 'relation', relation: { targetEntity: 'users', displayField: 'name' } }
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'orders',
|
|
25
|
-
fields: [
|
|
26
|
-
{ name: 'id', type: 'number', constraints: { required: true } },
|
|
27
|
-
{ name: 'amount', type: 'number', label: 'Amount', constraints: { required: true } },
|
|
28
|
-
{ name: 'currency', type: 'text', label: 'Currency', constraints: { required: true } },
|
|
29
|
-
{ name: 'status', type: 'select', constraints: { options: ['pending', 'paid', 'failed'] } },
|
|
30
|
-
{ name: 'userId', type: 'relation', relation: { targetEntity: 'users', displayField: 'name' } }
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
]
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
34
9
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
],
|
|
43
|
-
orders: [
|
|
44
|
-
{ id: 1, amount: 0.5, currency: 'SOL', status: 'pending', userId: 1 },
|
|
45
|
-
{ id: 2, amount: 0.01, currency: 'ETH', status: 'pending', userId: 2 }
|
|
46
|
-
]
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
47
17
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return Promise.resolve({ success: true });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export class MockPaymentProvider {
|
|
83
|
-
async initiatePayment(orderId, options) {
|
|
84
|
-
console.log(`[MockPayment] Initiating for order ${orderId}`, options);
|
|
85
|
-
return {
|
|
86
|
-
orderId,
|
|
87
|
-
paymentAddress: '0x1234...5678_MOCK_ADDRESS',
|
|
88
|
-
amount: options.amount || '0.1',
|
|
89
|
-
currency: options.currency || 'ETH',
|
|
90
|
-
network: 'MockNetwork',
|
|
91
|
-
nonce: Math.random().toString(36).substring(7)
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async verifyPayment(txHash, orderId) {
|
|
95
|
-
console.log(`[MockPayment] Verifying tx ${txHash} for order ${orderId}`);
|
|
96
|
-
return {
|
|
97
|
-
transactionHash: txHash,
|
|
98
|
-
orderId,
|
|
99
|
-
status: 'confirmed'
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const mockDbModule = {
|
|
104
|
-
manifest: {
|
|
105
|
-
name: '@micro-cms/mock-db',
|
|
106
|
-
version: '0.0.1',
|
|
107
|
-
provides: ['database-adapter', 'introspection', 'payment-provider'],
|
|
108
|
-
publishes: {
|
|
109
|
-
'database.schema': 'The current database schema'
|
|
110
|
-
}
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
MockDataProvider: () => MockDataProvider,
|
|
24
|
+
MockPaymentProvider: () => MockPaymentProvider,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var MOCK_SCHEMA = {
|
|
29
|
+
entities: [
|
|
30
|
+
{
|
|
31
|
+
name: "users",
|
|
32
|
+
fields: [
|
|
33
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
34
|
+
{ name: "name", type: "text", label: "Full Name", constraints: { required: true, minLength: 2 } },
|
|
35
|
+
{ name: "email", type: "text", label: "Email Address", constraints: { required: true } },
|
|
36
|
+
{ name: "isActive", type: "boolean", label: "Active User" },
|
|
37
|
+
{ name: "role", type: "select", constraints: { options: ["admin", "editor", "viewer"] } }
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "posts",
|
|
42
|
+
fields: [
|
|
43
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
44
|
+
{ name: "title", type: "text", constraints: { required: true } },
|
|
45
|
+
{ name: "content", type: "text" },
|
|
46
|
+
{ name: "publishedAt", type: "date" },
|
|
47
|
+
{ name: "authorId", type: "relation", relation: { targetEntity: "users", displayField: "name" } }
|
|
48
|
+
]
|
|
111
49
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
50
|
+
{
|
|
51
|
+
name: "orders",
|
|
52
|
+
fields: [
|
|
53
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
54
|
+
{ name: "amount", type: "number", label: "Amount", constraints: { required: true } },
|
|
55
|
+
{ name: "currency", type: "text", label: "Currency", constraints: { required: true } },
|
|
56
|
+
{ name: "status", type: "select", constraints: { options: ["pending", "paid", "failed"] } },
|
|
57
|
+
{ name: "userId", type: "relation", relation: { targetEntity: "users", displayField: "name" } }
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
var MOCK_DATA = {
|
|
63
|
+
users: [
|
|
64
|
+
{ id: 1, name: "Alice Admin", email: "alice@example.com", isActive: true, role: "admin" },
|
|
65
|
+
{ id: 2, name: "Bob Builder", email: "bob@example.com", isActive: false, role: "editor" }
|
|
66
|
+
],
|
|
67
|
+
posts: [
|
|
68
|
+
{ id: 1, title: "Hello World", content: "First post", publishedAt: "2023-01-01", authorId: 1 }
|
|
69
|
+
],
|
|
70
|
+
orders: [
|
|
71
|
+
{ id: 1, amount: 0.5, currency: "SOL", status: "pending", userId: 1 },
|
|
72
|
+
{ id: 2, amount: 0.01, currency: "ETH", status: "pending", userId: 2 }
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
var MockDataProvider = class {
|
|
76
|
+
async introspect() {
|
|
77
|
+
return Promise.resolve(MOCK_SCHEMA);
|
|
78
|
+
}
|
|
79
|
+
async find(entity, query) {
|
|
80
|
+
const table = MOCK_DATA[entity] || [];
|
|
81
|
+
const page = query?.page || 1;
|
|
82
|
+
const limit = query?.limit || 10;
|
|
83
|
+
const start = (page - 1) * limit;
|
|
84
|
+
const end = start + limit;
|
|
85
|
+
return Promise.resolve({
|
|
86
|
+
data: table.slice(start, end),
|
|
87
|
+
total: table.length,
|
|
88
|
+
page,
|
|
89
|
+
limit
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async findById(entity, id) {
|
|
93
|
+
const table = MOCK_DATA[entity] || [];
|
|
94
|
+
return Promise.resolve(table.find((item) => String(item.id) === String(id)));
|
|
95
|
+
}
|
|
96
|
+
async create(entity, data) {
|
|
97
|
+
const table = MOCK_DATA[entity] || [];
|
|
98
|
+
const newItem = { ...data, id: table.length + 1 };
|
|
99
|
+
MOCK_DATA[entity] = [...table, newItem];
|
|
100
|
+
return Promise.resolve(newItem);
|
|
101
|
+
}
|
|
102
|
+
async update(entity, id, data) {
|
|
103
|
+
return Promise.resolve(data);
|
|
104
|
+
}
|
|
105
|
+
async delete(entity, id) {
|
|
106
|
+
return Promise.resolve({ success: true });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var MockPaymentProvider = class {
|
|
110
|
+
async initiatePayment(orderId, options) {
|
|
111
|
+
console.log(`[MockPayment] Initiating for order ${orderId}`, options);
|
|
112
|
+
return {
|
|
113
|
+
orderId,
|
|
114
|
+
paymentAddress: "0x1234...5678_MOCK_ADDRESS",
|
|
115
|
+
amount: options.amount || "0.1",
|
|
116
|
+
currency: options.currency || "ETH",
|
|
117
|
+
network: "MockNetwork",
|
|
118
|
+
nonce: Math.random().toString(36).substring(7)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async verifyPayment(txHash, orderId) {
|
|
122
|
+
console.log(`[MockPayment] Verifying tx ${txHash} for order ${orderId}`);
|
|
123
|
+
return {
|
|
124
|
+
transactionHash: txHash,
|
|
125
|
+
orderId,
|
|
126
|
+
status: "confirmed"
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var mockDbModule = {
|
|
131
|
+
manifest: {
|
|
132
|
+
name: "@micro-cms/mock-db",
|
|
133
|
+
version: "0.0.1",
|
|
134
|
+
provides: ["database-adapter", "introspection", "payment-provider"],
|
|
135
|
+
publishes: {
|
|
136
|
+
"database.schema": "The current database schema"
|
|
119
137
|
}
|
|
138
|
+
},
|
|
139
|
+
async load({ runtime, context }) {
|
|
140
|
+
const provider = new MockDataProvider();
|
|
141
|
+
runtime.register("database-adapter", provider);
|
|
142
|
+
const paymentProvider = new MockPaymentProvider();
|
|
143
|
+
runtime.register("payment-provider", paymentProvider);
|
|
144
|
+
const schema = await provider.introspect();
|
|
145
|
+
context.publish("database.schema", schema);
|
|
146
|
+
}
|
|
120
147
|
};
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
var index_default = mockDbModule;
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
MockDataProvider,
|
|
152
|
+
MockPaymentProvider
|
|
153
|
+
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAW;IAC1B,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,OAAO;YACb,MAAM,EAAE;gBACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gBAC/D,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE;gBACjG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gBACxF,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE;gBAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;aAC1F;SACF;QACD;YACE,IAAI,EAAE,OAAO;YACb,MAAM,EAAE;gBACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gBAC/D,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gB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ED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var MOCK_SCHEMA = {
|
|
3
|
+
entities: [
|
|
4
|
+
{
|
|
5
|
+
name: "users",
|
|
6
|
+
fields: [
|
|
7
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
8
|
+
{ name: "name", type: "text", label: "Full Name", constraints: { required: true, minLength: 2 } },
|
|
9
|
+
{ name: "email", type: "text", label: "Email Address", constraints: { required: true } },
|
|
10
|
+
{ name: "isActive", type: "boolean", label: "Active User" },
|
|
11
|
+
{ name: "role", type: "select", constraints: { options: ["admin", "editor", "viewer"] } }
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "posts",
|
|
16
|
+
fields: [
|
|
17
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
18
|
+
{ name: "title", type: "text", constraints: { required: true } },
|
|
19
|
+
{ name: "content", type: "text" },
|
|
20
|
+
{ name: "publishedAt", type: "date" },
|
|
21
|
+
{ name: "authorId", type: "relation", relation: { targetEntity: "users", displayField: "name" } }
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "orders",
|
|
26
|
+
fields: [
|
|
27
|
+
{ name: "id", type: "number", constraints: { required: true } },
|
|
28
|
+
{ name: "amount", type: "number", label: "Amount", constraints: { required: true } },
|
|
29
|
+
{ name: "currency", type: "text", label: "Currency", constraints: { required: true } },
|
|
30
|
+
{ name: "status", type: "select", constraints: { options: ["pending", "paid", "failed"] } },
|
|
31
|
+
{ name: "userId", type: "relation", relation: { targetEntity: "users", displayField: "name" } }
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
var MOCK_DATA = {
|
|
37
|
+
users: [
|
|
38
|
+
{ id: 1, name: "Alice Admin", email: "alice@example.com", isActive: true, role: "admin" },
|
|
39
|
+
{ id: 2, name: "Bob Builder", email: "bob@example.com", isActive: false, role: "editor" }
|
|
40
|
+
],
|
|
41
|
+
posts: [
|
|
42
|
+
{ id: 1, title: "Hello World", content: "First post", publishedAt: "2023-01-01", authorId: 1 }
|
|
43
|
+
],
|
|
44
|
+
orders: [
|
|
45
|
+
{ id: 1, amount: 0.5, currency: "SOL", status: "pending", userId: 1 },
|
|
46
|
+
{ id: 2, amount: 0.01, currency: "ETH", status: "pending", userId: 2 }
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
var MockDataProvider = class {
|
|
50
|
+
async introspect() {
|
|
51
|
+
return Promise.resolve(MOCK_SCHEMA);
|
|
52
|
+
}
|
|
53
|
+
async find(entity, query) {
|
|
54
|
+
const table = MOCK_DATA[entity] || [];
|
|
55
|
+
const page = query?.page || 1;
|
|
56
|
+
const limit = query?.limit || 10;
|
|
57
|
+
const start = (page - 1) * limit;
|
|
58
|
+
const end = start + limit;
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
data: table.slice(start, end),
|
|
61
|
+
total: table.length,
|
|
62
|
+
page,
|
|
63
|
+
limit
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async findById(entity, id) {
|
|
67
|
+
const table = MOCK_DATA[entity] || [];
|
|
68
|
+
return Promise.resolve(table.find((item) => String(item.id) === String(id)));
|
|
69
|
+
}
|
|
70
|
+
async create(entity, data) {
|
|
71
|
+
const table = MOCK_DATA[entity] || [];
|
|
72
|
+
const newItem = { ...data, id: table.length + 1 };
|
|
73
|
+
MOCK_DATA[entity] = [...table, newItem];
|
|
74
|
+
return Promise.resolve(newItem);
|
|
75
|
+
}
|
|
76
|
+
async update(entity, id, data) {
|
|
77
|
+
return Promise.resolve(data);
|
|
78
|
+
}
|
|
79
|
+
async delete(entity, id) {
|
|
80
|
+
return Promise.resolve({ success: true });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var MockPaymentProvider = class {
|
|
84
|
+
async initiatePayment(orderId, options) {
|
|
85
|
+
console.log(`[MockPayment] Initiating for order ${orderId}`, options);
|
|
86
|
+
return {
|
|
87
|
+
orderId,
|
|
88
|
+
paymentAddress: "0x1234...5678_MOCK_ADDRESS",
|
|
89
|
+
amount: options.amount || "0.1",
|
|
90
|
+
currency: options.currency || "ETH",
|
|
91
|
+
network: "MockNetwork",
|
|
92
|
+
nonce: Math.random().toString(36).substring(7)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async verifyPayment(txHash, orderId) {
|
|
96
|
+
console.log(`[MockPayment] Verifying tx ${txHash} for order ${orderId}`);
|
|
97
|
+
return {
|
|
98
|
+
transactionHash: txHash,
|
|
99
|
+
orderId,
|
|
100
|
+
status: "confirmed"
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var mockDbModule = {
|
|
105
|
+
manifest: {
|
|
106
|
+
name: "@micro-cms/mock-db",
|
|
107
|
+
version: "0.0.1",
|
|
108
|
+
provides: ["database-adapter", "introspection", "payment-provider"],
|
|
109
|
+
publishes: {
|
|
110
|
+
"database.schema": "The current database schema"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
async load({ runtime, context }) {
|
|
114
|
+
const provider = new MockDataProvider();
|
|
115
|
+
runtime.register("database-adapter", provider);
|
|
116
|
+
const paymentProvider = new MockPaymentProvider();
|
|
117
|
+
runtime.register("payment-provider", paymentProvider);
|
|
118
|
+
const schema = await provider.introspect();
|
|
119
|
+
context.publish("database.schema", schema);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var index_default = mockDbModule;
|
|
123
|
+
export {
|
|
124
|
+
MockDataProvider,
|
|
125
|
+
MockPaymentProvider,
|
|
126
|
+
index_default as default
|
|
127
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-cms/mock-db",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.8",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
5
|
+
"module": "dist/index.mjs",
|
|
7
6
|
"types": "dist/index.d.ts",
|
|
8
7
|
"files": [
|
|
9
8
|
"dist"
|
|
@@ -11,18 +10,20 @@
|
|
|
11
10
|
"exports": {
|
|
12
11
|
".": {
|
|
13
12
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@micro-cms/types": "1.0.
|
|
19
|
+
"@micro-cms/types": "^1.0.8"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
23
23
|
"prepare": "pnpm build"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"typescript": "^5.0.0"
|
|
26
|
+
"typescript": "^5.0.0",
|
|
27
|
+
"tsup": "^8.0.2"
|
|
27
28
|
}
|
|
28
29
|
}
|