@fluidframework/datastore-definitions 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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.
Files changed (40) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/CHANGELOG.md +215 -0
  3. package/README.md +45 -7
  4. package/api-extractor-lint.json +4 -0
  5. package/api-extractor.json +2 -2
  6. package/api-report/datastore-definitions.api.md +156 -0
  7. package/dist/channel.d.ts +71 -16
  8. package/dist/channel.d.ts.map +1 -1
  9. package/dist/channel.js.map +1 -1
  10. package/dist/dataStoreRuntime.d.ts +28 -7
  11. package/dist/dataStoreRuntime.d.ts.map +1 -1
  12. package/dist/dataStoreRuntime.js.map +1 -1
  13. package/dist/datastore-definitions-alpha.d.ts +480 -0
  14. package/dist/datastore-definitions-beta.d.ts +395 -0
  15. package/dist/datastore-definitions-public.d.ts +395 -0
  16. package/dist/datastore-definitions-untrimmed.d.ts +480 -0
  17. package/dist/index.d.ts +10 -10
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +0 -21
  20. package/dist/index.js.map +1 -1
  21. package/dist/jsonable.d.ts +46 -14
  22. package/dist/jsonable.d.ts.map +1 -1
  23. package/dist/jsonable.js.map +1 -1
  24. package/dist/serializable.d.ts +5 -4
  25. package/dist/serializable.d.ts.map +1 -1
  26. package/dist/serializable.js.map +1 -1
  27. package/dist/storage.d.ts +1 -0
  28. package/dist/storage.d.ts.map +1 -1
  29. package/dist/storage.js.map +1 -1
  30. package/dist/tsdoc-metadata.json +11 -0
  31. package/package.json +64 -42
  32. package/prettier.config.cjs +8 -0
  33. package/src/channel.ts +256 -200
  34. package/src/dataStoreRuntime.ts +117 -96
  35. package/src/index.ts +17 -10
  36. package/src/jsonable.ts +80 -23
  37. package/src/serializable.ts +5 -4
  38. package/src/storage.ts +14 -13
  39. package/tsconfig.json +10 -12
  40. package/.eslintrc.js +0 -13
@@ -3,113 +3,134 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from "@fluidframework/common-definitions";
7
6
  import {
8
- IFluidHandleContext,
9
- IFluidRouter,
10
- IFluidHandle,
7
+ IEvent,
8
+ IEventProvider,
9
+ ITelemetryLogger,
10
+ IDisposable,
11
+ IFluidHandleContext,
12
+ IFluidHandle,
13
+ FluidObject,
11
14
  } from "@fluidframework/core-interfaces";
12
15
  import {
13
- IAudience,
14
- IDeltaManager,
15
- AttachState,
16
- ILoaderOptions,
16
+ IAudience,
17
+ IDeltaManager,
18
+ AttachState,
19
+ ILoaderOptions,
17
20
  } from "@fluidframework/container-definitions";
18
21
  import {
19
- IDocumentMessage,
20
- IQuorumClients,
21
- ISequencedDocumentMessage,
22
+ IDocumentMessage,
23
+ IQuorumClients,
24
+ ISequencedDocumentMessage,
22
25
  } from "@fluidframework/protocol-definitions";
23
- import { IInboundSignalMessage, IProvideFluidDataStoreRegistry } from "@fluidframework/runtime-definitions";
24
- import { IChannel } from ".";
26
+ import { IInboundSignalMessage } from "@fluidframework/runtime-definitions";
27
+ import { IIdCompressor } from "@fluidframework/id-compressor";
28
+ import { IChannel } from "./channel";
25
29
 
30
+ /**
31
+ * Events emitted by {@link IFluidDataStoreRuntime}.
32
+ * @public
33
+ */
26
34
  export interface IFluidDataStoreRuntimeEvents extends IEvent {
27
- (
28
- // eslint-disable-next-line @typescript-eslint/unified-signatures
29
- event: "disconnected" | "dispose" | "attaching" | "attached",
30
- listener: () => void,
31
- );
32
- (event: "op", listener: (message: ISequencedDocumentMessage) => void);
33
- (event: "signal", listener: (message: IInboundSignalMessage, local: boolean) => void);
34
- (event: "connected", listener: (clientId: string) => void);
35
+ (event: "disconnected" | "dispose" | "attaching" | "attached", listener: () => void);
36
+ (event: "op", listener: (message: ISequencedDocumentMessage) => void);
37
+ (event: "signal", listener: (message: IInboundSignalMessage, local: boolean) => void);
38
+ (event: "connected", listener: (clientId: string) => void);
35
39
  }
36
40
 
37
41
  /**
38
42
  * Represents the runtime for the data store. Contains helper functions/state of the data store.
43
+ * @public
39
44
  */
40
- export interface IFluidDataStoreRuntime extends
41
- IFluidRouter,
42
- IEventProvider<IFluidDataStoreRuntimeEvents>,
43
- IDisposable,
44
- Partial<IProvideFluidDataStoreRegistry> {
45
-
46
- readonly id: string;
47
-
48
- readonly IFluidHandleContext: IFluidHandleContext;
49
-
50
- readonly rootRoutingContext: IFluidHandleContext;
51
- readonly channelsRoutingContext: IFluidHandleContext;
52
- readonly objectsRoutingContext: IFluidHandleContext;
53
-
54
- readonly options: ILoaderOptions;
55
-
56
- readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
57
-
58
- readonly clientId: string | undefined;
59
-
60
- readonly connected: boolean;
61
-
62
- readonly logger: ITelemetryLogger;
63
-
64
- /**
65
- * Indicates the attachment state of the data store to a host service.
66
- */
67
- readonly attachState: AttachState;
68
-
69
- /**
70
- * Returns the channel with the given id
71
- */
72
- getChannel(id: string): Promise<IChannel>;
73
-
74
- /**
75
- * Creates a new channel of the given type.
76
- * @param id - ID of the channel to be created. A unique ID will be generated if left undefined.
77
- * @param type - Type of the channel.
78
- */
79
- createChannel(id: string | undefined, type: string): IChannel;
80
-
81
- /**
82
- * Bind the channel with the data store runtime. If the runtime
83
- * is attached then we attach the channel to make it live.
84
- */
85
- bindChannel(channel: IChannel): void;
86
-
87
- // Blob related calls
88
- /**
89
- * Api to upload a blob of data.
90
- * @param blob - blob to be uploaded.
91
- */
92
- uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;
93
-
94
- /**
95
- * Submits the signal to be sent to other clients.
96
- * @param type - Type of the signal.
97
- * @param content - Content of the signal.
98
- */
99
- submitSignal(type: string, content: any): void;
100
-
101
- /**
102
- * Returns the current quorum.
103
- */
104
- getQuorum(): IQuorumClients;
105
-
106
- /**
107
- * Returns the current audience.
108
- */
109
- getAudience(): IAudience;
110
-
111
- /**
112
- * Resolves when a local data store is attached.
113
- */
114
- waitAttached(): Promise<void>;
45
+ export interface IFluidDataStoreRuntime
46
+ extends IEventProvider<IFluidDataStoreRuntimeEvents>,
47
+ IDisposable {
48
+ readonly id: string;
49
+
50
+ readonly IFluidHandleContext: IFluidHandleContext;
51
+
52
+ readonly rootRoutingContext: IFluidHandleContext;
53
+ readonly channelsRoutingContext: IFluidHandleContext;
54
+ readonly objectsRoutingContext: IFluidHandleContext;
55
+
56
+ readonly options: ILoaderOptions;
57
+
58
+ readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
59
+
60
+ readonly clientId: string | undefined;
61
+
62
+ readonly connected: boolean;
63
+
64
+ readonly logger: ITelemetryLogger;
65
+
66
+ /**
67
+ * Indicates the attachment state of the data store to a host service.
68
+ */
69
+ readonly attachState: AttachState;
70
+
71
+ readonly idCompressor?: IIdCompressor;
72
+
73
+ /**
74
+ * Returns the channel with the given id
75
+ */
76
+ getChannel(id: string): Promise<IChannel>;
77
+
78
+ /**
79
+ * Invokes the given callback and expects that no ops are submitted
80
+ * until execution finishes. If an op is submitted, an error will be raised.
81
+ *
82
+ * Can be disabled by feature gate `Fluid.ContainerRuntime.DisableOpReentryCheck`
83
+ *
84
+ * @param callback - the callback to be invoked
85
+ */
86
+ ensureNoDataModelChanges<T>(callback: () => T): T;
87
+
88
+ /**
89
+ * Creates a new channel of the given type.
90
+ * @param id - ID of the channel to be created. A unique ID will be generated if left undefined.
91
+ * @param type - Type of the channel.
92
+ */
93
+ createChannel(id: string | undefined, type: string): IChannel;
94
+
95
+ /**
96
+ * Bind the channel with the data store runtime. If the runtime
97
+ * is attached then we attach the channel to make it live.
98
+ */
99
+ bindChannel(channel: IChannel): void;
100
+
101
+ // Blob related calls
102
+ /**
103
+ * Api to upload a blob of data.
104
+ * @param blob - blob to be uploaded.
105
+ */
106
+ uploadBlob(blob: ArrayBufferLike, signal?: AbortSignal): Promise<IFluidHandle<ArrayBufferLike>>;
107
+
108
+ /**
109
+ * Submits the signal to be sent to other clients.
110
+ * @param type - Type of the signal.
111
+ * @param content - Content of the signal.
112
+ * @param targetClientId - When specified, the signal is only sent to the provided client id.
113
+ */
114
+ submitSignal(type: string, content: any, targetClientId?: string): void;
115
+
116
+ /**
117
+ * Returns the current quorum.
118
+ */
119
+ getQuorum(): IQuorumClients;
120
+
121
+ /**
122
+ * Returns the current audience.
123
+ */
124
+ getAudience(): IAudience;
125
+
126
+ /**
127
+ * Resolves when a local data store is attached.
128
+ */
129
+ waitAttached(): Promise<void>;
130
+
131
+ /**
132
+ * Exposes a handle to the root object / entryPoint of the data store. Use this as the primary way of interacting
133
+ * with it.
134
+ */
135
+ readonly entryPoint: IFluidHandle<FluidObject>;
115
136
  }
package/src/index.ts CHANGED
@@ -4,14 +4,21 @@
4
4
  */
5
5
 
6
6
  /**
7
- * This package defines the interfaces required to implement and/or communicate
8
- * with a data store.
9
- *
10
- * @packageDocumentation
11
- */
7
+ * This library defines the interfaces required to implement and/or communicate
8
+ * with a data store.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
12
 
13
- export * from "./channel";
14
- export * from "./dataStoreRuntime";
15
- export * from "./jsonable";
16
- export * from "./serializable";
17
- export * from "./storage";
13
+ export {
14
+ IChannel,
15
+ IChannelFactory,
16
+ IChannelServices,
17
+ IChannelStorageService,
18
+ IDeltaConnection,
19
+ IDeltaHandler,
20
+ } from "./channel";
21
+ export { IFluidDataStoreRuntime, IFluidDataStoreRuntimeEvents } from "./dataStoreRuntime";
22
+ export type { Jsonable, JsonableTypeWith, Internal_InterfaceOfJsonableTypesWith } from "./jsonable";
23
+ export { Serializable } from "./serializable";
24
+ export { IChannelAttributes } from "./storage";
package/src/jsonable.ts CHANGED
@@ -3,6 +3,43 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ /**
7
+ * Type constraint for types that are likely serializable as JSON or have a custom
8
+ * alternate type.
9
+ *
10
+ * @remarks
11
+ * Use `JsonableTypeWith<never>` for just JSON serializable types.
12
+ * See {@link Jsonable} for serialization pitfalls.
13
+ *
14
+ * @privateRemarks
15
+ * Perfer using `Jsonable<unknown>` over this type that is an implementation detail.
16
+ * @alpha
17
+ */
18
+ export type JsonableTypeWith<T> =
19
+ | undefined
20
+ | null
21
+ | boolean
22
+ | number
23
+ | string
24
+ | T
25
+ | Internal_InterfaceOfJsonableTypesWith<T>
26
+ | ArrayLike<JsonableTypeWith<T>>;
27
+
28
+ /**
29
+ * @remarks
30
+ * This type is a kludge and not intended for general use.
31
+ *
32
+ * @privateRemarks
33
+ * Internal type testing for compatibility uses TypeOnly filter which cannot handle recursive "pure" types.
34
+ * This interface along with ArrayLike above avoids pure type recursion issues, but introduces a limitation on
35
+ * the ability of {@link Jsonable} to detect array-like types that are not handled naively ({@link JSON.stringify}).
36
+ * The TypeOnly filter is not useful for {@link JsonableTypeWith}; so, if type testing improves, this can be removed.
37
+ * @alpha
38
+ */
39
+ export interface Internal_InterfaceOfJsonableTypesWith<T> {
40
+ [index: string | number]: JsonableTypeWith<T>;
41
+ }
42
+
6
43
  /**
7
44
  * Used to constrain a type `T` to types that are serializable as JSON.
8
45
  * Produces a compile-time error if `T` contains non-Jsonable members.
@@ -10,42 +47,62 @@
10
47
  * @remarks
11
48
  * Note that this does NOT prevent using of values with non-json compatible data,
12
49
  * it only prevents using values with types that include non-json compatible data.
13
- * This means that one can, for example, pass an a value typed with json compatible
50
+ * This means that one can, for example, pass in a value typed with json compatible
14
51
  * interface into this function,
15
52
  * that could actually be a class with lots on non-json compatible fields and methods.
16
53
  *
17
54
  * Important: `T extends Jsonable<T>` is incorrect (does not even compile).
18
- * `T extends Jsonable` is also incorrect since `Jsonable` is just `any` and thus applies no constraint at all.
19
55
  *
20
56
  * The optional 'TReplaced' parameter may be used to permit additional leaf types to support
21
57
  * situations where a `replacer` is used to handle special values (e.g., `Jsonable<{ x: IFluidHandle }, IFluidHandle>`).
22
58
  *
23
59
  * Note that `Jsonable<T>` does not protect against the following pitfalls when serializing with JSON.stringify():
24
60
  *
25
- * - `undefined` properties on objects are omitted (i.e., properties become undefined instead of equal to undefined).
26
- * - When `undefined` appears as the root object or as an array element it is coerced to `null`.
27
- * - Non-finite numbers (`NaN`, `+/-Infinity`) are also coerced to `null`.
28
- * - prototypes and non-enumerable properties are lost.
61
+ * - `undefined` properties on objects are omitted (i.e., properties become undefined instead of equal to undefined).
62
+ *
63
+ * - When `undefined` appears as the root object or as an array element it is coerced to `null`.
64
+ *
65
+ * - Non-finite numbers (`NaN`, `+/-Infinity`) are also coerced to `null`.
66
+ *
67
+ * - prototypes and non-enumerable properties are lost.
68
+ *
69
+ * - `ArrayLike` types that are not arrays and are serialized as `{ length: number }`.
29
70
  *
30
71
  * Also, `Jsonable<T>` does not prevent the construction of circular references.
31
72
  *
32
- * Using `Jsonable` (with no type parameters) or `Jsonable<any>` is just a type alias for `any`
33
- * and should not be used if type safety is desired.
73
+ * Using `Jsonable<unknown>` or `Jsonable<any>` is a type alias for
74
+ * {@link JsonableTypeWith}`<never>` and should not be used if precise type safety is desired.
75
+ *
76
+ * @example Typical usage
34
77
  *
35
- * @example
36
- * Typical usage:
37
- * ```ts
38
- * function foo<T>(value: Jsonable<T>) { ... }
78
+ * ```typescript
79
+ * function foo<T>(value: Jsonable<T>) { ... }
39
80
  * ```
81
+ * @alpha
40
82
  */
41
- export type Jsonable<T = any, TReplaced = void> =
42
- T extends undefined | null | boolean | number | string | TReplaced
43
- ? T
44
- // eslint-disable-next-line @typescript-eslint/ban-types
45
- : Extract<T, Function> extends never
46
- ? {
47
- [K in keyof T]: Extract<K, symbol> extends never
48
- ? Jsonable<T[K], TReplaced>
49
- : never
50
- }
51
- : never;
83
+ export type Jsonable<T, TReplaced = never> = /* test for 'any' */ boolean extends (
84
+ T extends never ? true : false
85
+ )
86
+ ? /* 'any' => */ JsonableTypeWith<TReplaced>
87
+ : /* test for 'unknown' */ unknown extends T
88
+ ? /* 'unknown' => */ JsonableTypeWith<TReplaced>
89
+ : /* test for Jsonable primitive types */ T extends
90
+ | undefined /* is not serialized */
91
+ | null
92
+ | boolean
93
+ | number
94
+ | string
95
+ | TReplaced
96
+ ? /* primitive types => */ T
97
+ : // eslint-disable-next-line @typescript-eslint/ban-types
98
+ /* test for not a function */ Extract<T, Function> extends never
99
+ ? /* not a function => => test for object */ T extends object
100
+ ? /* object => test for array */ T extends (infer U)[] // prefer ArrayLike test to catch non-array array-like types
101
+ ? /* array => */ Jsonable<U, TReplaced>[]
102
+ : /* property bag => */ {
103
+ [K in keyof T]: Extract<K, symbol> extends never
104
+ ? Jsonable<T[K], TReplaced>
105
+ : never;
106
+ }
107
+ : /* not an object => */ never
108
+ : /* function => */ never;
@@ -17,10 +17,11 @@ import { Jsonable } from "./jsonable";
17
17
  * Important: `T extends Serializable<T>` is generally incorrect.
18
18
  * (Any value of `T` extends the serializable subset of itself.)
19
19
  *
20
- * @example
21
- * Typical usage:
20
+ * @example Typical usage
21
+ *
22
22
  * ```typescript
23
- * function serialize<T>(value: Serializable<T>) { ... }
23
+ * function serialize<T>(value: Serializable<T>) { ... }
24
24
  * ```
25
+ * @alpha
25
26
  */
26
- export type Serializable<T = any> = Jsonable<T, IFluidHandle>;
27
+ export type Serializable<T> = Jsonable<T, IFluidHandle>;
package/src/storage.ts CHANGED
@@ -5,21 +5,22 @@
5
5
 
6
6
  /**
7
7
  * Represents the attributes of a channel/DDS.
8
+ * @public
8
9
  */
9
10
  export interface IChannelAttributes {
10
- /**
11
- * Type name of the DDS for factory look up with ISharedObjectRegistry
12
- */
13
- readonly type: string;
11
+ /**
12
+ * Type name of the DDS for factory look up with ISharedObjectRegistry
13
+ */
14
+ readonly type: string;
14
15
 
15
- /**
16
- * Format version of the snapshot
17
- * Currently, only use to display a debug message if the version is incompatible
18
- */
19
- readonly snapshotFormatVersion: string;
16
+ /**
17
+ * Format version of the snapshot
18
+ * Currently, only use to display a debug message if the version is incompatible
19
+ */
20
+ readonly snapshotFormatVersion: string;
20
21
 
21
- /**
22
- * The package version of the code of the DDS, for debug only
23
- */
24
- readonly packageVersion?: string;
22
+ /**
23
+ * The package version of the code of the DDS, for debug only
24
+ */
25
+ readonly packageVersion?: string;
25
26
  }
package/tsconfig.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true,
10
- },
11
- "include": [
12
- "src/**/*"
13
- ]
2
+ "extends": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.esm-only.json",
5
+ ],
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/test/**/*"],
8
+ "compilerOptions": {
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ },
14
12
  }
package/.eslintrc.js DELETED
@@ -1,13 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- module.exports = {
7
- "parserOptions": {
8
- "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
9
- },
10
- "extends": [
11
- "@fluidframework/eslint-config-fluid"
12
- ]
13
- }