@shaxpir/duiduidui-models 1.35.1 → 1.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/ContentKind.d.ts +1 -0
- package/dist/models/ContentKind.js +1 -0
- package/dist/models/Manifest.d.ts +1 -0
- package/dist/models/Manifest.js +1 -0
- package/dist/models/Model.js +2 -2
- package/dist/models/Usage.d.ts +14 -0
- package/dist/models/Usage.js +40 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/repo/ShareSync.js +4 -0
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ var ContentKind;
|
|
|
17
17
|
ContentKind["TERM"] = "term";
|
|
18
18
|
ContentKind["USER"] = "user";
|
|
19
19
|
ContentKind["IMAGE"] = "image";
|
|
20
|
+
ContentKind["USAGE"] = "usage";
|
|
20
21
|
ContentKind["WORKSPACE"] = "workspace";
|
|
21
22
|
// These are used in the ShareDB system, but for internal bookkeeping, not for Content subclasses.
|
|
22
23
|
ContentKind["MANIFEST"] = "manifest";
|
package/dist/models/Manifest.js
CHANGED
package/dist/models/Model.js
CHANGED
|
@@ -292,13 +292,13 @@ class Model {
|
|
|
292
292
|
return data.meta.owner === userId;
|
|
293
293
|
}
|
|
294
294
|
static doesUserHaveContentPermission(kind, body, userId, type) {
|
|
295
|
-
// Users are allowed to read any of their own content, but they are not allowed to write their User, Billing, Social, or
|
|
295
|
+
// Users are allowed to read any of their own content, but they are not allowed to write their User, Billing, Social, Chat, or Usage objects.
|
|
296
296
|
if (body.meta.owner === userId) {
|
|
297
297
|
if (type === Permissions_1.PermissionType.READ) {
|
|
298
298
|
return true;
|
|
299
299
|
}
|
|
300
300
|
else if (type === Permissions_1.PermissionType.WRITE) {
|
|
301
|
-
return kind !== ContentKind_1.ContentKind.USER && kind !== ContentKind_1.ContentKind.BILLING && kind !== ContentKind_1.ContentKind.SOCIAL && kind !== ContentKind_1.ContentKind.CHAT;
|
|
301
|
+
return kind !== ContentKind_1.ContentKind.USER && kind !== ContentKind_1.ContentKind.BILLING && kind !== ContentKind_1.ContentKind.SOCIAL && kind !== ContentKind_1.ContentKind.CHAT && kind !== ContentKind_1.ContentKind.USAGE;
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
// Shared content: participants can read but not write (server-controlled).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
+
import { ShareSync } from '../repo';
|
|
3
|
+
import { ContentId } from "./Content";
|
|
4
|
+
import { Metric } from './Metric';
|
|
5
|
+
export declare enum UsageName {
|
|
6
|
+
AI_TOKENS = "ai_tokens"
|
|
7
|
+
}
|
|
8
|
+
export declare class Usage extends Metric {
|
|
9
|
+
static makeUsageId(userId: ContentId, usageName: UsageName): ContentId;
|
|
10
|
+
static createUsage(userId: ContentId, usageName: UsageName, entries?: {
|
|
11
|
+
[key: string]: number;
|
|
12
|
+
}): Usage;
|
|
13
|
+
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
14
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Usage = exports.UsageName = void 0;
|
|
4
|
+
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
5
|
+
const repo_1 = require("../repo");
|
|
6
|
+
const ContentKind_1 = require("./ContentKind");
|
|
7
|
+
const Metric_1 = require("./Metric");
|
|
8
|
+
var UsageName;
|
|
9
|
+
(function (UsageName) {
|
|
10
|
+
UsageName["AI_TOKENS"] = "ai_tokens";
|
|
11
|
+
})(UsageName || (exports.UsageName = UsageName = {}));
|
|
12
|
+
class Usage extends Metric_1.Metric {
|
|
13
|
+
static makeUsageId(userId, usageName) {
|
|
14
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-usage-" + usageName);
|
|
15
|
+
}
|
|
16
|
+
static createUsage(userId, usageName, entries = {}) {
|
|
17
|
+
const usageId = Usage.makeUsageId(userId, usageName);
|
|
18
|
+
const now = shaxpir_common_1.ClockService.getClock().now();
|
|
19
|
+
return repo_1.ShareSyncFactory.get().createContent({
|
|
20
|
+
meta: {
|
|
21
|
+
ref: usageId,
|
|
22
|
+
kind: ContentKind_1.ContentKind.USAGE,
|
|
23
|
+
id: usageId,
|
|
24
|
+
owner: userId,
|
|
25
|
+
created_at: now,
|
|
26
|
+
updated_at: now
|
|
27
|
+
},
|
|
28
|
+
payload: {
|
|
29
|
+
metric_name: usageName,
|
|
30
|
+
min_date: null,
|
|
31
|
+
max_date: null,
|
|
32
|
+
entries: entries
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
constructor(doc, shouldAcquire, shareSync) {
|
|
37
|
+
super(doc, shouldAcquire, shareSync);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Usage = Usage;
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/index.js
CHANGED
|
@@ -48,5 +48,6 @@ __exportStar(require("./SkillLevel"), exports);
|
|
|
48
48
|
__exportStar(require("./Social"), exports);
|
|
49
49
|
__exportStar(require("./Streaks"), exports);
|
|
50
50
|
__exportStar(require("./Term"), exports);
|
|
51
|
+
__exportStar(require("./Usage"), exports);
|
|
51
52
|
__exportStar(require("./User"), exports);
|
|
52
53
|
__exportStar(require("./Workspace"), exports);
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -49,6 +49,7 @@ const ContentKind_1 = require("../models/ContentKind");
|
|
|
49
49
|
const Device_1 = require("../models/Device");
|
|
50
50
|
const Manifest_1 = require("../models/Manifest");
|
|
51
51
|
const Session_1 = require("../models/Session");
|
|
52
|
+
const Usage_1 = require("../models/Usage");
|
|
52
53
|
const User_1 = require("../models/User");
|
|
53
54
|
// Register the ShareDB types
|
|
54
55
|
const Json1 = __importStar(require("./PermissiveJson1"));
|
|
@@ -518,6 +519,9 @@ class ShareSync {
|
|
|
518
519
|
else if (kind === ContentKind_1.ContentKind.TERM) {
|
|
519
520
|
return new models_1.Term(doc, shouldAcquire, shareSync);
|
|
520
521
|
}
|
|
522
|
+
else if (kind === ContentKind_1.ContentKind.USAGE) {
|
|
523
|
+
return new Usage_1.Usage(doc, shouldAcquire, shareSync);
|
|
524
|
+
}
|
|
521
525
|
else if (kind === ContentKind_1.ContentKind.USER) {
|
|
522
526
|
return new User_1.User(doc, shouldAcquire, shareSync);
|
|
523
527
|
}
|