@fluidframework/container-definitions 0.42.0 → 0.44.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.
@@ -0,0 +1,132 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Specifies an environment on Fluid property of a IFluidPackage
8
+ */
9
+ export interface IFluidPackageEnvironment {
10
+
11
+ /**
12
+ * The name of the target. For a browser environment, this could be umd for scripts
13
+ * or css for styles.
14
+ */
15
+ [target: string]: undefined | {
16
+ /**
17
+ * List of files for the target. These can be relative or absolute.
18
+ * The code loader should resolve relative paths, and validate all
19
+ * full urls.
20
+ */
21
+ files: string[];
22
+
23
+ /**
24
+ * General access for extended fields as specific usages will
25
+ * likely have additional infornamation like a definition
26
+ * of Library, the entrypoint for umd packages
27
+ */
28
+ [key: string]: unknown;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Fluid-specific properties expected on a package to be loaded by the code loader.
34
+ * While compatible with the npm package format it is not necessary that that package is an
35
+ * npm package:
36
+ * {@link https://stackoverflow.com/questions/10065564/add-custom-metadata-or-config-to-package-json-is-it-valid}
37
+ */
38
+ export interface IFluidPackage {
39
+ /**
40
+ * The name of the package that this code represnets
41
+ */
42
+ name: string;
43
+ /**
44
+ * This object represents the Fluid specific properties of the package
45
+ */
46
+ fluid: {
47
+ /**
48
+ * The name of the of the environment. This should be something like browser, or node
49
+ * and contain the necessary targets for loading this code in that environment.
50
+ */
51
+ [environment: string]: undefined | IFluidPackageEnvironment;
52
+ };
53
+ /**
54
+ * General access for extended fields as specific usages will
55
+ * likely have additional infornamation like a definition of
56
+ * compatible versions, or deployment information like rings or rollouts.
57
+ */
58
+ [key: string]: unknown;
59
+ }
60
+
61
+ /**
62
+ * Check if the package.json defines a Fluid package
63
+ * @param pkg - the package json data to check if it is a Fluid package.
64
+ */
65
+ export const isFluidPackage = (pkg: any): pkg is Readonly<IFluidPackage> =>
66
+ typeof pkg === "object"
67
+ && typeof pkg?.name === "string"
68
+ && typeof pkg?.fluid === "object";
69
+
70
+ /**
71
+ * Package manager configuration. Provides a key value mapping of config values
72
+ */
73
+ export interface IFluidCodeDetailsConfig {
74
+ readonly [key: string]: string;
75
+ }
76
+
77
+ /**
78
+ * Data structure used to describe the code to load on the Fluid document
79
+ */
80
+ export interface IFluidCodeDetails {
81
+ /**
82
+ * The code package to be used on the Fluid document. This is either the package name which will be loaded
83
+ * from a package manager. Or the expanded Fluid package.
84
+ */
85
+ readonly package: string | Readonly<IFluidPackage>;
86
+
87
+ /**
88
+ * Configuration details. This includes links to the package manager and base CDNs.
89
+ */
90
+ readonly config?: IFluidCodeDetailsConfig;
91
+ }
92
+
93
+ export const isFluidCodeDetails = (details: unknown): details is Readonly<IFluidCodeDetails> =>{
94
+ const maybeCodeDetails = details as Partial<IFluidCodeDetails> | undefined;
95
+ return typeof maybeCodeDetails === "object"
96
+ && (typeof maybeCodeDetails?.package === "string" || isFluidPackage(maybeCodeDetails?.package))
97
+ && (maybeCodeDetails?.config === undefined || typeof maybeCodeDetails?.config === "object");
98
+ };
99
+
100
+ export const IFluidCodeDetailsComparer: keyof IProvideFluidCodeDetailsComparer = "IFluidCodeDetailsComparer";
101
+
102
+ export interface IProvideFluidCodeDetailsComparer {
103
+ readonly IFluidCodeDetailsComparer: IFluidCodeDetailsComparer ;
104
+ }
105
+
106
+ /**
107
+ * Provides capability to compare Fluid code details.
108
+ */
109
+ export interface IFluidCodeDetailsComparer extends IProvideFluidCodeDetailsComparer {
110
+
111
+ /**
112
+ * Determines if the `candidate` code details satisfy the constraints specified in `constraint` code details.
113
+ *
114
+ * Similar semantics to:
115
+ * {@link https://github.com/npm/node-semver#usage}
116
+ */
117
+ satisfies(candidate: IFluidCodeDetails, constraint: IFluidCodeDetails): Promise<boolean>;
118
+
119
+ /* eslint-disable max-len */
120
+ /**
121
+ * Return a number representing the ascending sort order of the `a` and `b` code details;
122
+ * `< 0` if `a < b`.
123
+ * `= 0` if `a === b`.
124
+ * `> 0` if `a > b`.
125
+ * `undefined` if `a` is not comparable to `b`.
126
+ *
127
+ * Similar semantics to:
128
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description | Array.sort}
129
+ */
130
+ compare(a: IFluidCodeDetails, b: IFluidCodeDetails): Promise<number | undefined>;
131
+ /* eslint-enable max-len */
132
+ }
package/src/index.ts CHANGED
@@ -10,5 +10,6 @@ export * from "./deltas";
10
10
  export * from "./error";
11
11
  export * from "./loader";
12
12
  export * from "./fluidModule";
13
+ export * from "./fluidPackage";
13
14
  export * from "./proxyLoader";
14
15
  export * from "./runtime";
package/src/loader.ts CHANGED
@@ -20,7 +20,8 @@ import {
20
20
  } from "@fluidframework/protocol-definitions";
21
21
  import { IResolvedUrl } from "@fluidframework/driver-definitions";
22
22
  import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
23
- import { IDeltaManager } from "./deltas";
23
+ import { IAudience } from "./audience";
24
+ import { IDeltaManager, ReadOnlyInfo } from "./deltas";
24
25
  import { ICriticalContainerError, ContainerWarning } from "./error";
25
26
  import { IFluidModule } from "./fluidModule";
26
27
  import { AttachState } from "./runtime";
@@ -37,6 +38,35 @@ export interface ICodeLoader extends Partial<IProvideFluidCodeDetailsComparer> {
37
38
  load(source: IFluidCodeDetails): Promise<IFluidModule>;
38
39
  }
39
40
 
41
+ /**
42
+ * Encapsulates a module entry point with corresponding code details.
43
+ */
44
+ export interface IFluidModuleWithDetails {
45
+ /** Fluid code module that implements the runtime factory needed to instantiate the container runtime. */
46
+ module: IFluidModule;
47
+ /**
48
+ * Code details associated with the module. Represents a document schema this module supports.
49
+ * If the code loader implements the {@link @fluidframework/core-interfaces#IFluidCodeDetailsComparer} interface,
50
+ * it'll be called to determine whether the module code details satisfy the new code proposal in the quorum.
51
+ */
52
+ details: IFluidCodeDetails;
53
+ }
54
+
55
+ /**
56
+ * Fluid code loader resolves a code module matching the document schema, i.e. code details, such as
57
+ * a package name and package version range.
58
+ */
59
+ export interface ICodeDetailsLoader
60
+ extends Partial<IProvideFluidCodeDetailsComparer> {
61
+ /**
62
+ * Load the code module (package) that is capable to interact with the document.
63
+ *
64
+ * @param source - Code proposal that articulates the current schema the document is written in.
65
+ * @returns - Code module entry point along with the code details associated with it.
66
+ */
67
+ load(source: IFluidCodeDetails): Promise<IFluidModuleWithDetails>;
68
+ }
69
+
40
70
  /**
41
71
  * The interface returned from a IFluidCodeResolver which represents IFluidCodeDetails
42
72
  * that have been resolved and are ready to load
@@ -93,6 +123,31 @@ export interface IContainerEvents extends IEvent {
93
123
  (event: "dirty" | "saved", listener: (dirty: boolean) => void);
94
124
  }
95
125
 
126
+ /**
127
+ * Namespace for the different connection states a container can be in
128
+ */
129
+ export namespace ConnectionState {
130
+ /**
131
+ * The document is no longer connected to the delta server
132
+ */
133
+ export type Disconnected = 0;
134
+
135
+ /**
136
+ * The document has an inbound connection but is still pending for outbound deltas
137
+ */
138
+ export type Connecting = 1;
139
+
140
+ /**
141
+ * The document is fully connected
142
+ */
143
+ export type Connected = 2;
144
+ }
145
+
146
+ /**
147
+ * Type defining the different states of connectivity a container can be in
148
+ */
149
+ export type ConnectionState = ConnectionState.Disconnected | ConnectionState.Connecting | ConnectionState.Connected;
150
+
96
151
  /**
97
152
  * The Host's view of the Container and its connection to storage
98
153
  */
@@ -119,14 +174,6 @@ export interface IContainer extends IEventProvider<IContainerEvents>, IFluidRout
119
174
  */
120
175
  readonly attachState: AttachState;
121
176
 
122
- /**
123
- * The current code details for the container's runtime
124
- * @deprecated use getSpecifiedCodeDetails for the code details currently specified for this container, or
125
- * getLoadedCodeDetails for the code details that the container's context was loaded with.
126
- * To be removed after getSpecifiedCodeDetails and getLoadedCodeDetails become ubiquitous.
127
- */
128
- readonly codeDetails: IFluidCodeDetails | undefined;
129
-
130
177
  /**
131
178
  * Get the code details that are currently specified for the container.
132
179
  * @returns The current code details if any are specified, undefined if none are specified.
@@ -197,6 +244,63 @@ export interface IContainer extends IEventProvider<IContainerEvents>, IFluidRout
197
244
  * @param request - The request to be issued against the container
198
245
  */
199
246
  request(request: IRequest): Promise<IResponse>;
247
+
248
+ /**
249
+ * Provides the current connected state of the container
250
+ */
251
+ readonly connectionState: ConnectionState;
252
+
253
+ /**
254
+ * Boolean indicating whether the container is currently connected or not
255
+ */
256
+ readonly connected: boolean;
257
+
258
+ /**
259
+ * Dictates whether or not the current container will automatically attempt to reconnect to the delta stream
260
+ * after receiving a disconnect event
261
+ * @param reconnect - Boolean indicating if reconnect should automatically occur
262
+ * @alpha
263
+ */
264
+ setAutoReconnect?(reconnect: boolean): void;
265
+
266
+ /**
267
+ * Have the container attempt to resume processing ops
268
+ * @alpha
269
+ */
270
+ resume?(): void;
271
+
272
+ /**
273
+ * The audience information for all clients currently associated with the document in the current session
274
+ */
275
+ readonly audience: IAudience;
276
+
277
+ /**
278
+ * The server provided ID of the client.
279
+ * Set once this.connected is true, otherwise undefined
280
+ * @alpha
281
+ */
282
+ readonly clientId?: string | undefined;
283
+
284
+ /**
285
+ * Tells if container is in read-only mode.
286
+ * Data stores should listen for "readonly" notifications and disallow user making changes to data stores.
287
+ * Readonly state can be because of no storage write permission,
288
+ * or due to host forcing readonly mode for container.
289
+ *
290
+ * We do not differentiate here between no write access to storage vs. host disallowing changes to container -
291
+ * in all cases container runtime and data stores should respect readonly state and not allow local changes.
292
+ *
293
+ * It is undefined if we have not yet established websocket connection
294
+ * and do not know if user has write access to a file.
295
+ */
296
+ readonly readOnlyInfo: ReadOnlyInfo;
297
+
298
+ /**
299
+ * Allows the host to have the container force to be in read-only mode
300
+ * @param readonly - Boolean that toggles if read-only policies will be enforced
301
+ * @alpha
302
+ */
303
+ forceReadonly?(readonly: boolean);
200
304
  }
201
305
 
202
306
  /**
package/src/runtime.ts CHANGED
@@ -5,11 +5,12 @@
5
5
 
6
6
  import { ITelemetryBaseLogger, IDisposable } from "@fluidframework/common-definitions";
7
7
  import {
8
- IFluidObject,
8
+ FluidObject,
9
+ IFluidCodeDetails,
9
10
  IFluidConfiguration,
11
+ IFluidObject,
10
12
  IRequest,
11
13
  IResponse,
12
- FluidObject,
13
14
  } from "@fluidframework/core-interfaces";
14
15
  import { IDocumentStorageService } from "@fluidframework/driver-definitions";
15
16
  import {
@@ -120,6 +121,9 @@ export interface IRuntime extends IDisposable {
120
121
  * and the Container has created a new ContainerContext.
121
122
  */
122
123
  export interface IContainerContext extends IDisposable {
124
+ /**
125
+ * @deprecated This will be removed in a later release. Deprecated in 0.44 of container-definitions
126
+ */
123
127
  readonly id: string;
124
128
  readonly existing: boolean | undefined;
125
129
  readonly options: ILoaderOptions;
@@ -134,6 +138,14 @@ export interface IContainerContext extends IDisposable {
134
138
  readonly closeFn: (error?: ICriticalContainerError) => void;
135
139
  readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
136
140
  readonly quorum: IQuorum;
141
+ /**
142
+ * @deprecated This method is provided as a migration tool for customers currently reading the code details
143
+ * from within the Container by directly accessing the Quorum proposals. The code details should not be accessed
144
+ * from within the Container as this requires coupling between the container contents and the code loader.
145
+ * Direct access to Quorum proposals will be removed in an upcoming release, and in a further future release this
146
+ * migration tool will be removed.
147
+ */
148
+ getSpecifiedCodeDetails?(): IFluidCodeDetails | undefined;
137
149
  readonly audience: IAudience | undefined;
138
150
  readonly loader: ILoader;
139
151
  /** @deprecated - Use `taggedLogger` if present. Otherwise, be sure to handle tagged data