@verdant-web/common 2.4.0 → 2.5.1

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.
@@ -8,7 +8,8 @@ export * from './utils.js';
8
8
  export * from './indexes.js';
9
9
  export { migrate, migrationRange, createDefaultMigration, createMigration, } from './migration.js';
10
10
  export type { Migration, MigrationIndexDescription, MigrationEngine, } from './migration.js';
11
- export type { UserInfo } from './presence.js';
11
+ export type * from './presence.js';
12
+ export { initialInternalPresence } from './presence.js';
12
13
  export * from './patch.js';
13
14
  export * from './oids.js';
14
15
  export * from './oidsLegacy.js';
package/dist/esm/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './schema/index.js';
7
7
  export * from './utils.js';
8
8
  export * from './indexes.js';
9
9
  export { migrate, migrationRange, createDefaultMigration, createMigration, } from './migration.js';
10
+ export { initialInternalPresence } from './presence.js';
10
11
  export * from './patch.js';
11
12
  export * from './oids.js';
12
13
  export * from './oidsLegacy.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,EACN,OAAO,EACP,cAAc,EACd,sBAAsB,EACtB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAOxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC3E,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,EACN,OAAO,EACP,cAAc,EACd,sBAAsB,EACtB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC3E,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -24,4 +24,19 @@ export interface UserInfo<Profile, Presence> {
24
24
  * makes changes. The shape of presence is up to you.
25
25
  */
26
26
  presence: Presence;
27
+ /**
28
+ * This is the internal presence data that Verdant uses
29
+ * for some built-in presence functionality. The client
30
+ * should manage it transparently to the user.
31
+ */
32
+ internal: VerdantInternalPresence;
33
+ }
34
+ export type UserInfoUpdate<Profile = any, Presence = any> = Omit<UserInfo<Profile, Presence>, 'internal' | 'profile'> & {
35
+ internal?: VerdantInternalPresence;
36
+ };
37
+ export interface VerdantInternalPresence {
38
+ viewId?: string;
39
+ lastFieldId?: string;
40
+ lastFieldTimestamp?: number;
27
41
  }
42
+ export declare const initialInternalPresence: VerdantInternalPresence;
@@ -1,2 +1,2 @@
1
- export {};
1
+ export const initialInternalPresence = {};
2
2
  //# sourceMappingURL=presence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"presence.js","sourceRoot":"","sources":["../../src/presence.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"presence.js","sourceRoot":"","sources":["../../src/presence.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAC,MAAM,uBAAuB,GAA4B,EAAE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { DocumentBaseline } from './baseline.js';
2
2
  import { Operation } from './operation.js';
3
- import { UserInfo } from './presence.js';
3
+ import { UserInfo, VerdantInternalPresence } from './presence.js';
4
4
  export type HeartbeatMessage = {
5
5
  type: 'heartbeat';
6
6
  timestamp: string;
@@ -108,7 +108,9 @@ export type PresenceUpdateMessage = {
108
108
  /** The client's replica ID */
109
109
  replicaId: string;
110
110
  /** new presence value */
111
- presence: any;
111
+ presence?: any;
112
+ /** presence that is internal to verdant */
113
+ internal?: VerdantInternalPresence;
112
114
  };
113
115
  export type PresenceChangedMessage = {
114
116
  type: 'presence-changed';
@@ -32,4 +32,5 @@ export declare const fields: {
32
32
  nullable?: boolean;
33
33
  downloadRemote?: boolean;
34
34
  }) => StorageFileFieldSchema;
35
+ id: () => StorageStringFieldSchema;
35
36
  };
@@ -1,3 +1,4 @@
1
+ import cuid from 'cuid';
1
2
  const objectField = (args) => {
2
3
  return Object.assign({ type: 'object' }, args);
3
4
  };
@@ -22,6 +23,12 @@ const mapField = (args) => {
22
23
  const fileField = (args) => {
23
24
  return Object.assign({ type: 'file' }, args);
24
25
  };
26
+ const idField = () => {
27
+ return {
28
+ type: 'string',
29
+ default: cuid,
30
+ };
31
+ };
25
32
  export const fields = {
26
33
  object: objectField,
27
34
  array: arrayField,
@@ -31,5 +38,6 @@ export const fields = {
31
38
  any: anyField,
32
39
  map: mapField,
33
40
  file: fileField,
41
+ id: idField,
34
42
  };
35
43
  //# sourceMappingURL=fieldHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fieldHelpers.js","sourceRoot":"","sources":["../../../src/schema/fieldHelpers.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,GAAG,CAAoC,IAMvD,EAAmC,EAAE;IACrC,uBACC,IAAI,EAAE,QAAQ,IACX,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAA+B,IAGjD,EAA8B,EAAE;IAChC,uBACC,IAAI,EAAE,OAAO,IACV,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAIpB,EAA4B,EAAE;IAC9B,uBACC,IAAI,EAAE,QAAQ,IACX,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAGpB,EAA4B,EAAE;IAC9B,uBACC,IAAI,EAAE,QAAQ,IACX,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAGrB,EAA6B,EAAE;IAC/B,uBACC,IAAI,EAAE,SAAS,IACZ,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAS,IAEzB,EAAiC,EAAE;IACnC,uBACC,IAAI,EAAE,KAAK,IACR,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAA+B,IAE/C,EAA4B,EAAE;IAC9B,uBACC,IAAI,EAAE,KAAK,IACR,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,IAGlB,EAA0B,EAAE;IAC5B,uBACC,IAAI,EAAE,MAAM,IACT,IAAI,EACN;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,GAAG,EAAE,Q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AEF,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,OAAO;CACX,CAAC"}
@@ -38,6 +38,7 @@ export declare namespace schema {
38
38
  nullable?: boolean | undefined;
39
39
  downloadRemote?: boolean | undefined;
40
40
  } | undefined) => import("./types.js").StorageFileFieldSchema;
41
+ id: () => import("./types.js").StorageStringFieldSchema;
41
42
  };
42
43
  var generated: {
43
44
  id: (() => string) & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdant-web/common",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "access": "public",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -17,7 +17,8 @@ export type {
17
17
  MigrationIndexDescription,
18
18
  MigrationEngine,
19
19
  } from './migration.js';
20
- export type { UserInfo } from './presence.js';
20
+ export type * from './presence.js';
21
+ export { initialInternalPresence } from './presence.js';
21
22
  export * from './patch.js';
22
23
  export * from './oids.js';
23
24
  export * from './oidsLegacy.js';
package/src/presence.ts CHANGED
@@ -26,4 +26,26 @@ export interface UserInfo<Profile, Presence> {
26
26
  * makes changes. The shape of presence is up to you.
27
27
  */
28
28
  presence: Presence;
29
+
30
+ /**
31
+ * This is the internal presence data that Verdant uses
32
+ * for some built-in presence functionality. The client
33
+ * should manage it transparently to the user.
34
+ */
35
+ internal: VerdantInternalPresence;
29
36
  }
37
+
38
+ export type UserInfoUpdate<Profile = any, Presence = any> = Omit<
39
+ UserInfo<Profile, Presence>,
40
+ 'internal' | 'profile'
41
+ > & {
42
+ internal?: VerdantInternalPresence;
43
+ };
44
+
45
+ export interface VerdantInternalPresence {
46
+ viewId?: string;
47
+ lastFieldId?: string;
48
+ lastFieldTimestamp?: number;
49
+ }
50
+
51
+ export const initialInternalPresence: VerdantInternalPresence = {};
package/src/protocol.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  // client ID, and therefore library ID, is inferred
2
2
 
3
3
  import { DocumentBaseline } from './baseline.js';
4
- import { Operation, OperationPatch } from './operation.js';
5
- import { UserInfo } from './presence.js';
4
+ import { Operation } from './operation.js';
5
+ import {
6
+ UserInfo,
7
+ UserInfoUpdate,
8
+ VerdantInternalPresence,
9
+ } from './presence.js';
6
10
 
7
11
  export type HeartbeatMessage = {
8
12
  type: 'heartbeat';
@@ -124,7 +128,9 @@ export type PresenceUpdateMessage = {
124
128
  /** The client's replica ID */
125
129
  replicaId: string;
126
130
  /** new presence value */
127
- presence: any;
131
+ presence?: any;
132
+ /** presence that is internal to verdant */
133
+ internal?: VerdantInternalPresence;
128
134
  };
129
135
 
130
136
  export type PresenceChangedMessage = {
@@ -1,3 +1,4 @@
1
+ import cuid from 'cuid';
1
2
  import {
2
3
  ShapeFromFieldsWithDefaults,
3
4
  StorageAnyFieldSchema,
@@ -94,6 +95,13 @@ const fileField = (args?: {
94
95
  };
95
96
  };
96
97
 
98
+ const idField = (): StorageStringFieldSchema => {
99
+ return {
100
+ type: 'string',
101
+ default: cuid,
102
+ };
103
+ };
104
+
97
105
  export const fields = {
98
106
  object: objectField,
99
107
  array: arrayField,
@@ -103,4 +111,5 @@ export const fields = {
103
111
  any: anyField,
104
112
  map: mapField,
105
113
  file: fileField,
114
+ id: idField,
106
115
  };