@fluidframework/aqueduct 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.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/.eslintrc.cjs +14 -0
- package/.mocharc.cjs +12 -0
- package/CHANGELOG.md +342 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/aqueduct.api.md +165 -0
- package/dist/container-runtime-factories/baseContainerRuntimeFactory.d.ts +7 -7
- package/dist/container-runtime-factories/baseContainerRuntimeFactory.d.ts.map +1 -1
- package/dist/container-runtime-factories/baseContainerRuntimeFactory.js +9 -10
- package/dist/container-runtime-factories/baseContainerRuntimeFactory.js.map +1 -1
- package/dist/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.d.ts +5 -5
- package/dist/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.d.ts.map +1 -1
- package/dist/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.js +2 -2
- package/dist/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.js.map +1 -1
- package/dist/data-object-factories/dataObjectFactory.d.ts +4 -4
- package/dist/data-object-factories/dataObjectFactory.d.ts.map +1 -1
- package/dist/data-object-factories/dataObjectFactory.js +7 -7
- package/dist/data-object-factories/dataObjectFactory.js.map +1 -1
- package/dist/data-object-factories/pureDataObjectFactory.d.ts +5 -5
- package/dist/data-object-factories/pureDataObjectFactory.d.ts.map +1 -1
- package/dist/data-object-factories/pureDataObjectFactory.js +9 -9
- package/dist/data-object-factories/pureDataObjectFactory.js.map +1 -1
- package/dist/data-objects/dataObject.d.ts +1 -1
- package/dist/data-objects/dataObject.d.ts.map +1 -1
- package/dist/data-objects/dataObject.js +3 -3
- package/dist/data-objects/dataObject.js.map +1 -1
- package/dist/data-objects/pureDataObject.d.ts +2 -2
- package/dist/data-objects/pureDataObject.d.ts.map +1 -1
- package/dist/data-objects/pureDataObject.js +6 -6
- package/dist/data-objects/pureDataObject.js.map +1 -1
- package/dist/data-objects/types.d.ts +3 -3
- package/dist/data-objects/types.d.ts.map +1 -1
- package/dist/data-objects/types.js.map +1 -1
- package/dist/legacy.d.ts +23 -0
- package/dist/public.d.ts +12 -0
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/container-runtime-factories/baseContainerRuntimeFactory.d.ts +7 -7
- package/lib/container-runtime-factories/baseContainerRuntimeFactory.d.ts.map +1 -1
- package/lib/container-runtime-factories/baseContainerRuntimeFactory.js +5 -4
- package/lib/container-runtime-factories/baseContainerRuntimeFactory.js.map +1 -1
- package/lib/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.d.ts +5 -5
- package/lib/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.d.ts.map +1 -1
- package/lib/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.js +1 -1
- package/lib/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.js.map +1 -1
- package/lib/data-object-factories/dataObjectFactory.d.ts +4 -4
- package/lib/data-object-factories/dataObjectFactory.d.ts.map +1 -1
- package/lib/data-object-factories/dataObjectFactory.js +2 -2
- package/lib/data-object-factories/dataObjectFactory.js.map +1 -1
- package/lib/data-object-factories/pureDataObjectFactory.d.ts +5 -5
- package/lib/data-object-factories/pureDataObjectFactory.d.ts.map +1 -1
- package/lib/data-object-factories/pureDataObjectFactory.js +3 -3
- package/lib/data-object-factories/pureDataObjectFactory.js.map +1 -1
- package/lib/data-objects/dataObject.d.ts +1 -1
- package/lib/data-objects/dataObject.d.ts.map +1 -1
- package/lib/data-objects/dataObject.js +1 -1
- package/lib/data-objects/dataObject.js.map +1 -1
- package/lib/data-objects/pureDataObject.d.ts +2 -2
- package/lib/data-objects/pureDataObject.d.ts.map +1 -1
- package/lib/data-objects/pureDataObject.js +2 -2
- package/lib/data-objects/pureDataObject.js.map +1 -1
- package/lib/data-objects/types.d.ts +3 -3
- package/lib/data-objects/types.d.ts.map +1 -1
- package/lib/data-objects/types.js.map +1 -1
- package/lib/legacy.d.ts +23 -0
- package/lib/public.d.ts +12 -0
- package/package.json +39 -64
- package/prettier.config.cjs +8 -0
- package/src/container-runtime-factories/baseContainerRuntimeFactory.ts +142 -0
- package/src/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.ts +110 -0
- package/src/container-runtime-factories/index.ts +13 -0
- package/src/data-object-factories/dataObjectFactory.ts +61 -0
- package/src/data-object-factories/index.ts +7 -0
- package/src/data-object-factories/pureDataObjectFactory.ts +379 -0
- package/src/data-objects/dataObject.ts +78 -0
- package/src/data-objects/index.ts +8 -0
- package/src/data-objects/pureDataObject.ts +186 -0
- package/src/data-objects/types.ts +40 -0
- package/src/index.ts +33 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +9 -0
- package/dist/aqueduct-alpha.d.ts +0 -433
- package/dist/aqueduct-beta.d.ts +0 -110
- package/dist/aqueduct-public.d.ts +0 -110
- package/dist/aqueduct-untrimmed.d.ts +0 -433
- package/lib/aqueduct-alpha.d.ts +0 -433
- package/lib/aqueduct-beta.d.ts +0 -110
- package/lib/aqueduct-public.d.ts +0 -110
- package/lib/aqueduct-untrimmed.d.ts +0 -433
- package/lib/test/aqueduct.spec.js +0 -8
- package/lib/test/aqueduct.spec.js.map +0 -1
- package/lib/test/tsconfig.tsbuildinfo +0 -1
- package/lib/test/types/validateAqueductPrevious.generated.js +0 -24
- package/lib/test/types/validateAqueductPrevious.generated.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
|
+
import {
|
|
8
|
+
type IEvent,
|
|
9
|
+
type IFluidHandle,
|
|
10
|
+
type IFluidLoadable,
|
|
11
|
+
type IProvideFluidHandle,
|
|
12
|
+
type IRequest,
|
|
13
|
+
type IResponse,
|
|
14
|
+
} from "@fluidframework/core-interfaces";
|
|
15
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
16
|
+
import { type IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
17
|
+
import { type IFluidDataStoreContext } from "@fluidframework/runtime-definitions/internal";
|
|
18
|
+
import { create404Response } from "@fluidframework/runtime-utils/internal";
|
|
19
|
+
import { type AsyncFluidObjectProvider } from "@fluidframework/synthesize/internal";
|
|
20
|
+
|
|
21
|
+
import { type DataObjectTypes, type IDataObjectProps } from "./types.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This is a bare-bones base class that does basic setup and enables for factory on an initialize call.
|
|
25
|
+
* You probably don't want to inherit from this data store directly unless
|
|
26
|
+
* you are creating another base data store class
|
|
27
|
+
*
|
|
28
|
+
* @typeParam I - The optional input types used to strongly type the data object
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export abstract class PureDataObject<I extends DataObjectTypes = DataObjectTypes>
|
|
32
|
+
extends TypedEventEmitter<I["Events"] & IEvent>
|
|
33
|
+
implements IFluidLoadable, IProvideFluidHandle
|
|
34
|
+
{
|
|
35
|
+
/**
|
|
36
|
+
* This is your FluidDataStoreRuntime object
|
|
37
|
+
*/
|
|
38
|
+
protected readonly runtime: IFluidDataStoreRuntime;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This context is used to talk up to the ContainerRuntime
|
|
42
|
+
*/
|
|
43
|
+
protected readonly context: IFluidDataStoreContext;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Providers are FluidObject keyed objects that provide back
|
|
47
|
+
* a promise to the corresponding FluidObject or undefined.
|
|
48
|
+
* Providers injected/provided by the Container and/or HostingApplication
|
|
49
|
+
*
|
|
50
|
+
* To define providers set FluidObject interfaces in the OptionalProviders generic type for your data store
|
|
51
|
+
*/
|
|
52
|
+
protected readonly providers: AsyncFluidObjectProvider<I["OptionalProviders"]>;
|
|
53
|
+
|
|
54
|
+
protected initProps?: I["InitialState"];
|
|
55
|
+
|
|
56
|
+
protected initializeP: Promise<void> | undefined;
|
|
57
|
+
|
|
58
|
+
public get id(): string {
|
|
59
|
+
return this.runtime.id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* {@inheritDoc @fluidframework/core-interfaces#IProvideFluidLoadable.IFluidLoadable}
|
|
64
|
+
*/
|
|
65
|
+
public get IFluidLoadable(): this {
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* {@inheritDoc @fluidframework/core-interfaces#IProvideFluidHandle.IFluidHandle}
|
|
71
|
+
*/
|
|
72
|
+
public get IFluidHandle(): IFluidHandle<this> {
|
|
73
|
+
return this.handle;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Handle to a data store
|
|
78
|
+
*/
|
|
79
|
+
public get handle(): IFluidHandle<this> {
|
|
80
|
+
// PureDataObjectFactory already provides an entryPoint initialization function to the data store runtime,
|
|
81
|
+
// so this object should always have access to a non-null entryPoint. Need to cast because PureDataObject
|
|
82
|
+
// tried to be too smart with its typing for handles :).
|
|
83
|
+
assert(this.runtime.entryPoint !== undefined, 0x46b /* EntryPoint was undefined */);
|
|
84
|
+
return this.runtime.entryPoint as IFluidHandle<this>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public static async getDataObject(runtime: IFluidDataStoreRuntime): Promise<PureDataObject> {
|
|
88
|
+
const obj = await runtime.entryPoint.get();
|
|
89
|
+
return obj as PureDataObject;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public constructor(props: IDataObjectProps<I>) {
|
|
93
|
+
super();
|
|
94
|
+
this.runtime = props.runtime;
|
|
95
|
+
this.context = props.context;
|
|
96
|
+
this.providers = props.providers;
|
|
97
|
+
this.initProps = props.initProps;
|
|
98
|
+
|
|
99
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
100
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
101
|
+
assert(
|
|
102
|
+
(this.runtime as any)._dataObject === undefined,
|
|
103
|
+
0x0bd /* "Object runtime already has DataObject!" */,
|
|
104
|
+
);
|
|
105
|
+
(this.runtime as any)._dataObject = this;
|
|
106
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
107
|
+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Return this object if someone requests it directly
|
|
112
|
+
* We will return this object in two scenarios:
|
|
113
|
+
*
|
|
114
|
+
* 1. the request url is a "/"
|
|
115
|
+
*
|
|
116
|
+
* 2. the request url is empty
|
|
117
|
+
*/
|
|
118
|
+
public async request(req: IRequest): Promise<IResponse> {
|
|
119
|
+
return req.url === "" || req.url === "/" || req.url.startsWith("/?")
|
|
120
|
+
? { mimeType: "fluid/object", status: 200, value: this }
|
|
121
|
+
: create404Response(req);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Call this API to ensure PureDataObject is fully initialized.
|
|
126
|
+
* Initialization happens on demand, only on as-needed bases.
|
|
127
|
+
* In most cases you should allow factory/object to decide when to finish initialization.
|
|
128
|
+
* But if you are supplying your own implementation of DataStoreRuntime factory and overriding some methods
|
|
129
|
+
* and need a fully initialized object, then you can call this API to ensure object is fully initialized.
|
|
130
|
+
*/
|
|
131
|
+
public async finishInitialization(existing: boolean): Promise<void> {
|
|
132
|
+
if (this.initializeP !== undefined) {
|
|
133
|
+
return this.initializeP;
|
|
134
|
+
}
|
|
135
|
+
this.initializeP = this.initializeInternal(existing);
|
|
136
|
+
return this.initializeP;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Internal initialize implementation. Overwriting this will change the flow of the PureDataObject and should
|
|
141
|
+
* generally not be done.
|
|
142
|
+
*
|
|
143
|
+
* Calls initializingFirstTime, initializingFromExisting, and hasInitialized. Caller is
|
|
144
|
+
* responsible for ensuring this is only invoked once.
|
|
145
|
+
*/
|
|
146
|
+
public async initializeInternal(existing: boolean): Promise<void> {
|
|
147
|
+
await this.preInitialize();
|
|
148
|
+
if (existing) {
|
|
149
|
+
assert(
|
|
150
|
+
this.initProps === undefined,
|
|
151
|
+
0x0be /* "Trying to initialize from existing while initProps is set!" */,
|
|
152
|
+
);
|
|
153
|
+
await this.initializingFromExisting();
|
|
154
|
+
} else {
|
|
155
|
+
await this.initializingFirstTime(
|
|
156
|
+
(this.context.createProps as I["InitialState"]) ?? this.initProps,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
await this.hasInitialized();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Called every time the data store is initialized, before initializingFirstTime or
|
|
164
|
+
* initializingFromExisting is called.
|
|
165
|
+
*/
|
|
166
|
+
protected async preInitialize(): Promise<void> {}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Called the first time the data store is initialized (new creations with a new
|
|
170
|
+
* data store runtime)
|
|
171
|
+
*
|
|
172
|
+
* @param props - Optional props to be passed in on create
|
|
173
|
+
*/
|
|
174
|
+
protected async initializingFirstTime(props?: I["InitialState"]): Promise<void> {}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Called every time but the first time the data store is initialized (creations
|
|
178
|
+
* with an existing data store runtime)
|
|
179
|
+
*/
|
|
180
|
+
protected async initializingFromExisting(): Promise<void> {}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Called every time the data store is initialized after create or existing.
|
|
184
|
+
*/
|
|
185
|
+
protected async hasInitialized(): Promise<void> {}
|
|
186
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type FluidObject, type IEvent } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { type IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
|
|
8
|
+
import { type IFluidDataStoreContext } from "@fluidframework/runtime-definitions/internal";
|
|
9
|
+
import { type AsyncFluidObjectProvider } from "@fluidframework/synthesize/internal";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This type is used as the base generic input to DataObject and PureDataObject.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export interface DataObjectTypes {
|
|
16
|
+
/**
|
|
17
|
+
* Represents a type that will define optional providers that will be injected.
|
|
18
|
+
*/
|
|
19
|
+
OptionalProviders?: FluidObject;
|
|
20
|
+
/**
|
|
21
|
+
* The initial state type that the produced data object may take during creation.
|
|
22
|
+
*/
|
|
23
|
+
// TODO: Use a real type here.
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
InitialState?: any;
|
|
26
|
+
/**
|
|
27
|
+
* Represents events that will be available in the EventForwarder.
|
|
28
|
+
*/
|
|
29
|
+
Events?: IEvent;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @alpha
|
|
34
|
+
*/
|
|
35
|
+
export interface IDataObjectProps<I extends DataObjectTypes = DataObjectTypes> {
|
|
36
|
+
readonly runtime: IFluidDataStoreRuntime;
|
|
37
|
+
readonly context: IFluidDataStoreContext;
|
|
38
|
+
readonly providers: AsyncFluidObjectProvider<I["OptionalProviders"]>;
|
|
39
|
+
readonly initProps?: I["InitialState"];
|
|
40
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `aqueduct` package is a library for building Fluid objects and Fluid
|
|
8
|
+
* containers within the Fluid Framework. Its goal is to provide a thin base
|
|
9
|
+
* layer over the existing Fluid Framework interfaces that allows developers to
|
|
10
|
+
* get started quickly.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* About the library name: An "aqueduct" is a way to transport water from a source
|
|
14
|
+
* to another location. The library name was chosen because its purpose is to
|
|
15
|
+
* facilitate using lower level constructs and therefore handle 'fluid' items
|
|
16
|
+
* same as an aqueduct.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export { DataObjectFactory, PureDataObjectFactory } from "./data-object-factories/index.js";
|
|
22
|
+
export {
|
|
23
|
+
DataObject,
|
|
24
|
+
type DataObjectTypes,
|
|
25
|
+
type IDataObjectProps,
|
|
26
|
+
PureDataObject,
|
|
27
|
+
} from "./data-objects/index.js";
|
|
28
|
+
export {
|
|
29
|
+
BaseContainerRuntimeFactory,
|
|
30
|
+
type BaseContainerRuntimeFactoryProps,
|
|
31
|
+
ContainerRuntimeFactoryWithDefaultDataStore,
|
|
32
|
+
type ContainerRuntimeFactoryWithDefaultDataStoreProps,
|
|
33
|
+
} from "./container-runtime-factories/index.js";
|