@shaxpir/duiduidui-models 1.9.4 → 1.9.6

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.
@@ -30,6 +30,11 @@ export declare class Workspace extends Content {
30
30
  get payload(): WorkspacePayload;
31
31
  getGlobalConditions(): ConditionFilters;
32
32
  static makeWorkspaceId(userId: ContentId): ContentId;
33
+ /**
34
+ * Validate that a WorkspacePayload has all required fields.
35
+ * Throws an error if validation fails.
36
+ */
37
+ static validatePayload(payload: WorkspacePayload): void;
33
38
  static create(userId: ContentId, payload: WorkspacePayload): Workspace;
34
39
  get sessions(): ArrayView<MultiTime>;
35
40
  get devices(): ArrayView<ContentId>;
@@ -25,7 +25,32 @@ class Workspace extends Content_1.Content {
25
25
  static makeWorkspaceId(userId) {
26
26
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.WORKSPACE);
27
27
  }
28
+ /**
29
+ * Validate that a WorkspacePayload has all required fields.
30
+ * Throws an error if validation fails.
31
+ */
32
+ static validatePayload(payload) {
33
+ if (!payload || typeof payload !== 'object') {
34
+ throw new Error('Workspace.create: payload must be an object');
35
+ }
36
+ if (!Array.isArray(payload.devices)) {
37
+ throw new Error('Workspace.create: payload.devices must be an array');
38
+ }
39
+ if (!Array.isArray(payload.sessions)) {
40
+ throw new Error('Workspace.create: payload.sessions must be an array');
41
+ }
42
+ if (!payload.journey || typeof payload.journey !== 'object' || Array.isArray(payload.journey)) {
43
+ throw new Error('Workspace.create: payload.journey must be an object');
44
+ }
45
+ if (!payload.global_conditions || typeof payload.global_conditions !== 'object' || Array.isArray(payload.global_conditions)) {
46
+ throw new Error('Workspace.create: payload.global_conditions must be an object');
47
+ }
48
+ if (!Array.isArray(payload.uploaded_avatars)) {
49
+ throw new Error('Workspace.create: payload.uploaded_avatars must be an array');
50
+ }
51
+ }
28
52
  static create(userId, payload) {
53
+ Workspace.validatePayload(payload);
29
54
  const now = shaxpir_common_1.ClockService.getClock().now();
30
55
  const workspaceId = Workspace.makeWorkspaceId(userId);
31
56
  return repo_1.ShareSyncFactory.get().createContent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"