@concord-consortium/object-storage 1.0.0-pre.6 → 1.0.0-pre.7
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/README.md +3 -1
- package/dist/demo-object-storage.d.ts +10 -8
- package/dist/demo-object-storage.js +13 -16
- package/dist/firebase-object-storage.d.ts +10 -8
- package/dist/firebase-object-storage.js +49 -18
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/stored-object.d.ts +74 -0
- package/dist/stored-object.js +101 -0
- package/dist/types.d.ts +14 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,9 @@ function YourComponent() {
|
|
|
39
39
|
|
|
40
40
|
// Use storage methods
|
|
41
41
|
const handleAdd = async () => {
|
|
42
|
-
const
|
|
42
|
+
const object = new StoredObject();
|
|
43
|
+
const result = await storage.add(object);
|
|
44
|
+
console.log('Added object with id:', result.id);
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
return <div>Your component</div>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { DemoObjectStorageConfig, IObjectStorage,
|
|
1
|
+
import { DemoObjectStorageConfig, IObjectStorage, MonitorCallback, DemonitorFunction, StoredObjectMetadataWithId } from './types';
|
|
2
|
+
import { StoredObject, StoredObjectMetadata, StoredObjectData } from './stored-object';
|
|
2
3
|
export declare class DemoObjectStorage implements IObjectStorage {
|
|
3
4
|
private config;
|
|
4
5
|
private objects;
|
|
@@ -8,7 +9,7 @@ export declare class DemoObjectStorage implements IObjectStorage {
|
|
|
8
9
|
/**
|
|
9
10
|
* Lists metadata documents for objects associated with specific question IDs
|
|
10
11
|
*/
|
|
11
|
-
list(questionId: string): Promise<
|
|
12
|
+
list(questionId: string): Promise<StoredObjectMetadataWithId[]>;
|
|
12
13
|
/**
|
|
13
14
|
* Monitors metadata documents for objects associated with specific question IDs
|
|
14
15
|
* Invokes callback at start and on any change
|
|
@@ -17,9 +18,9 @@ export declare class DemoObjectStorage implements IObjectStorage {
|
|
|
17
18
|
monitor(questionId: string, callback: MonitorCallback): DemonitorFunction;
|
|
18
19
|
/**
|
|
19
20
|
* Adds both metadata and data documents for a new object
|
|
20
|
-
* Returns the
|
|
21
|
+
* Returns the StoredObject that was added
|
|
21
22
|
*/
|
|
22
|
-
add(object: StoredObject
|
|
23
|
+
add(object: StoredObject): Promise<StoredObject>;
|
|
23
24
|
/**
|
|
24
25
|
* Reads both metadata and data documents for an object
|
|
25
26
|
* Returns undefined if the object is not found
|
|
@@ -29,16 +30,17 @@ export declare class DemoObjectStorage implements IObjectStorage {
|
|
|
29
30
|
* Reads only the metadata document for an object
|
|
30
31
|
* Returns undefined if the object is not found
|
|
31
32
|
*/
|
|
32
|
-
readMetadata(objectId: string): Promise<
|
|
33
|
+
readMetadata(objectId: string): Promise<StoredObjectMetadata | undefined>;
|
|
33
34
|
/**
|
|
34
35
|
* Reads only the data document for an object
|
|
35
36
|
* Returns undefined if the object is not found
|
|
36
37
|
*/
|
|
37
|
-
readData(objectId: string): Promise<
|
|
38
|
+
readData(objectId: string): Promise<StoredObjectData | undefined>;
|
|
38
39
|
/**
|
|
39
|
-
*
|
|
40
|
+
* Reads a single data item for an object
|
|
41
|
+
* Returns undefined if the object or item is not found
|
|
40
42
|
*/
|
|
41
|
-
|
|
43
|
+
readDataItem(objectId: string, itemId: string): Promise<any | undefined>;
|
|
42
44
|
/**
|
|
43
45
|
* Notifies all active monitors of changes
|
|
44
46
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DemoObjectStorage = void 0;
|
|
4
|
-
const nanoid_1 = require("nanoid");
|
|
5
4
|
class DemoObjectStorage {
|
|
6
5
|
constructor(config) {
|
|
7
6
|
if (config.version !== 1) {
|
|
@@ -48,28 +47,21 @@ class DemoObjectStorage {
|
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Adds both metadata and data documents for a new object
|
|
51
|
-
* Returns the
|
|
50
|
+
* Returns the StoredObject that was added
|
|
52
51
|
*/
|
|
53
|
-
async add(object
|
|
54
|
-
const id =
|
|
52
|
+
async add(object) {
|
|
53
|
+
const id = object.id;
|
|
55
54
|
this.objects.set(id, object);
|
|
56
55
|
// Notify all monitors
|
|
57
56
|
this.notifyMonitors();
|
|
58
|
-
return
|
|
57
|
+
return object;
|
|
59
58
|
}
|
|
60
59
|
/**
|
|
61
60
|
* Reads both metadata and data documents for an object
|
|
62
61
|
* Returns undefined if the object is not found
|
|
63
62
|
*/
|
|
64
63
|
async read(objectId) {
|
|
65
|
-
|
|
66
|
-
if (!obj) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
metadata: obj.metadata,
|
|
71
|
-
data: obj.data
|
|
72
|
-
};
|
|
64
|
+
return this.objects.get(objectId);
|
|
73
65
|
}
|
|
74
66
|
/**
|
|
75
67
|
* Reads only the metadata document for an object
|
|
@@ -94,10 +86,15 @@ class DemoObjectStorage {
|
|
|
94
86
|
return obj.data;
|
|
95
87
|
}
|
|
96
88
|
/**
|
|
97
|
-
*
|
|
89
|
+
* Reads a single data item for an object
|
|
90
|
+
* Returns undefined if the object or item is not found
|
|
98
91
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
async readDataItem(objectId, itemId) {
|
|
93
|
+
const obj = this.objects.get(objectId);
|
|
94
|
+
if (!obj) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
return obj.data[itemId];
|
|
101
98
|
}
|
|
102
99
|
/**
|
|
103
100
|
* Notifies all active monitors of changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "firebase/compat/auth";
|
|
2
2
|
import "firebase/compat/firestore";
|
|
3
|
-
import { FirebaseObjectStorageConfig, IObjectStorage,
|
|
3
|
+
import { FirebaseObjectStorageConfig, IObjectStorage, MonitorCallback, DemonitorFunction, StoredObjectMetadataWithId } from './types';
|
|
4
|
+
import { StoredObject, StoredObjectMetadata, StoredObjectData } from './stored-object';
|
|
4
5
|
export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
5
6
|
private config;
|
|
6
7
|
private initPromise;
|
|
@@ -12,6 +13,7 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
12
13
|
private createDocument;
|
|
13
14
|
private getPaths;
|
|
14
15
|
private getRefs;
|
|
16
|
+
private getItemDataPath;
|
|
15
17
|
private getMetadataQuery;
|
|
16
18
|
/**
|
|
17
19
|
* Ensures the provided ID is in question ID format as opposed to reference ID format
|
|
@@ -25,7 +27,7 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
25
27
|
/**
|
|
26
28
|
* Lists metadata documents for objects associated with specific question IDs
|
|
27
29
|
*/
|
|
28
|
-
list(questionOrRefId: string): Promise<
|
|
30
|
+
list(questionOrRefId: string): Promise<StoredObjectMetadataWithId[]>;
|
|
29
31
|
/**
|
|
30
32
|
* Monitors metadata documents for objects associated with specific question IDs
|
|
31
33
|
* Invokes callback at start and on any change
|
|
@@ -34,9 +36,9 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
34
36
|
monitor(questionOrRefId: string, callback: MonitorCallback): DemonitorFunction;
|
|
35
37
|
/**
|
|
36
38
|
* Adds both metadata and data documents for a new object
|
|
37
|
-
* Returns the
|
|
39
|
+
* Returns the StoredObject that was added
|
|
38
40
|
*/
|
|
39
|
-
add(object: StoredObject
|
|
41
|
+
add(object: StoredObject): Promise<StoredObject>;
|
|
40
42
|
/**
|
|
41
43
|
* Reads both metadata and data documents for an object
|
|
42
44
|
*/
|
|
@@ -44,13 +46,13 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
44
46
|
/**
|
|
45
47
|
* Reads only the metadata document for an object
|
|
46
48
|
*/
|
|
47
|
-
readMetadata(objectId: string): Promise<
|
|
49
|
+
readMetadata(objectId: string): Promise<StoredObjectMetadata | undefined>;
|
|
48
50
|
/**
|
|
49
51
|
* Reads only the data document for an object
|
|
50
52
|
*/
|
|
51
|
-
readData(objectId: string): Promise<
|
|
53
|
+
readData(objectId: string): Promise<StoredObjectData | undefined>;
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
55
|
+
* Reads a single data item for an object
|
|
54
56
|
*/
|
|
55
|
-
|
|
57
|
+
readDataItem(objectId: string, itemId: string): Promise<any | undefined>;
|
|
56
58
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FirebaseObjectStorage = void 0;
|
|
7
|
-
const nanoid_1 = require("nanoid");
|
|
8
7
|
const app_1 = __importDefault(require("firebase/compat/app"));
|
|
9
8
|
require("firebase/compat/auth");
|
|
10
9
|
require("firebase/compat/firestore");
|
|
10
|
+
const stored_object_1 = require("./stored-object");
|
|
11
11
|
class FirebaseObjectStorage {
|
|
12
12
|
constructor(config) {
|
|
13
13
|
this.initialized = false;
|
|
@@ -74,6 +74,9 @@ class FirebaseObjectStorage {
|
|
|
74
74
|
const dataRef = this.app.firestore().doc(dataPath);
|
|
75
75
|
return { metadataRef, dataRef };
|
|
76
76
|
}
|
|
77
|
+
getItemDataPath(objectId, itemId) {
|
|
78
|
+
return `${this.config.root}/object_store_data/${objectId}-${itemId}`;
|
|
79
|
+
}
|
|
77
80
|
getMetadataQuery(questionOrRefId) {
|
|
78
81
|
const questionId = this.ensureIdIsQuestionId(questionOrRefId);
|
|
79
82
|
const { metadataPath } = this.getPaths();
|
|
@@ -145,20 +148,29 @@ class FirebaseObjectStorage {
|
|
|
145
148
|
}
|
|
146
149
|
/**
|
|
147
150
|
* Adds both metadata and data documents for a new object
|
|
148
|
-
* Returns the
|
|
151
|
+
* Returns the StoredObject that was added
|
|
149
152
|
*/
|
|
150
|
-
async add(object
|
|
153
|
+
async add(object) {
|
|
151
154
|
await this.ensureInitialized();
|
|
152
|
-
const newObjectId =
|
|
153
|
-
const {
|
|
154
|
-
const { metadataRef
|
|
155
|
-
const dataDoc = this.createDocument({ data });
|
|
155
|
+
const newObjectId = object.id;
|
|
156
|
+
const { metadata } = object;
|
|
157
|
+
const { metadataRef } = this.getRefs(newObjectId);
|
|
156
158
|
const metadataDoc = this.createDocument({ metadata });
|
|
157
159
|
const batch = this.app.firestore().batch();
|
|
158
|
-
batch.set(dataRef, dataDoc);
|
|
159
160
|
batch.set(metadataRef, metadataDoc);
|
|
161
|
+
// Write each item as a separate document
|
|
162
|
+
for (const itemId in object.data) {
|
|
163
|
+
const itemPath = this.getItemDataPath(newObjectId, itemId);
|
|
164
|
+
const itemRef = this.app.firestore().doc(itemPath);
|
|
165
|
+
const itemDoc = this.createDocument({
|
|
166
|
+
objectId: newObjectId,
|
|
167
|
+
itemId: itemId,
|
|
168
|
+
itemData: JSON.stringify(object.data[itemId])
|
|
169
|
+
});
|
|
170
|
+
batch.set(itemRef, itemDoc);
|
|
171
|
+
}
|
|
160
172
|
await batch.commit();
|
|
161
|
-
return
|
|
173
|
+
return object;
|
|
162
174
|
}
|
|
163
175
|
/**
|
|
164
176
|
* Reads both metadata and data documents for an object
|
|
@@ -173,7 +185,7 @@ class FirebaseObjectStorage {
|
|
|
173
185
|
if (!data) {
|
|
174
186
|
return undefined;
|
|
175
187
|
}
|
|
176
|
-
return
|
|
188
|
+
return stored_object_1.StoredObject.FromParts(objectId, metadata, data);
|
|
177
189
|
}
|
|
178
190
|
/**
|
|
179
191
|
* Reads only the metadata document for an object
|
|
@@ -185,25 +197,44 @@ class FirebaseObjectStorage {
|
|
|
185
197
|
if (!metadataSnapshot.exists) {
|
|
186
198
|
return undefined;
|
|
187
199
|
}
|
|
188
|
-
return metadataSnapshot.data()?.metadata
|
|
200
|
+
return metadataSnapshot.data()?.metadata;
|
|
189
201
|
}
|
|
190
202
|
/**
|
|
191
203
|
* Reads only the data document for an object
|
|
192
204
|
*/
|
|
193
205
|
async readData(objectId) {
|
|
194
206
|
await this.ensureInitialized();
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
207
|
+
const dataPath = `${this.config.root}/object_store_data`;
|
|
208
|
+
const query = this.app.firestore().collection(dataPath)
|
|
209
|
+
.where("objectId", "==", objectId);
|
|
210
|
+
const querySnapshot = await query.get();
|
|
211
|
+
if (querySnapshot.empty) {
|
|
198
212
|
return undefined;
|
|
199
213
|
}
|
|
200
|
-
|
|
214
|
+
const data = {};
|
|
215
|
+
querySnapshot.forEach(doc => {
|
|
216
|
+
const docData = doc.data();
|
|
217
|
+
const itemId = docData.itemId;
|
|
218
|
+
const itemDataString = docData.itemData;
|
|
219
|
+
if (itemId && itemDataString) {
|
|
220
|
+
data[itemId] = JSON.parse(itemDataString);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return data;
|
|
201
224
|
}
|
|
202
225
|
/**
|
|
203
|
-
*
|
|
226
|
+
* Reads a single data item for an object
|
|
204
227
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
228
|
+
async readDataItem(objectId, itemId) {
|
|
229
|
+
await this.ensureInitialized();
|
|
230
|
+
const itemPath = this.getItemDataPath(objectId, itemId);
|
|
231
|
+
const itemRef = this.app.firestore().doc(itemPath);
|
|
232
|
+
const itemSnapshot = await itemRef.get();
|
|
233
|
+
if (!itemSnapshot.exists) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
const itemDataString = itemSnapshot.data()?.itemData;
|
|
237
|
+
return itemDataString ? JSON.parse(itemDataString) : undefined;
|
|
207
238
|
}
|
|
208
239
|
}
|
|
209
240
|
exports.FirebaseObjectStorage = FirebaseObjectStorage;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { DemoObjectStorage } from './demo-object-storage';
|
|
|
2
2
|
export { FirebaseObjectStorage } from './firebase-object-storage';
|
|
3
3
|
export { createObjectStorage } from './object-storage';
|
|
4
4
|
export { ObjectStorageProvider, useObjectStorage } from './object-storage-context';
|
|
5
|
-
export { IObjectStorage, ObjectStorageConfig, DemoObjectStorageConfig, FirebaseObjectStorageUser, FirebaseObjectStorageConfig,
|
|
6
|
-
export * from './
|
|
5
|
+
export { IObjectStorage, ObjectStorageConfig, DemoObjectStorageConfig, FirebaseObjectStorageUser, FirebaseObjectStorageConfig, StoredObjectWithId as ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
|
|
6
|
+
export * from './stored-object';
|
package/dist/index.js
CHANGED
|
@@ -24,4 +24,4 @@ Object.defineProperty(exports, "createObjectStorage", { enumerable: true, get: f
|
|
|
24
24
|
var object_storage_context_1 = require("./object-storage-context");
|
|
25
25
|
Object.defineProperty(exports, "ObjectStorageProvider", { enumerable: true, get: function () { return object_storage_context_1.ObjectStorageProvider; } });
|
|
26
26
|
Object.defineProperty(exports, "useObjectStorage", { enumerable: true, get: function () { return object_storage_context_1.useObjectStorage; } });
|
|
27
|
-
__exportStar(require("./
|
|
27
|
+
__exportStar(require("./stored-object"), exports);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type AddImageOptions = {
|
|
2
|
+
id?: string;
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
description?: string;
|
|
8
|
+
subType?: string;
|
|
9
|
+
};
|
|
10
|
+
export type AddDataTableOptions = {
|
|
11
|
+
id?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
cols: string[];
|
|
14
|
+
rows: any[][];
|
|
15
|
+
description?: string;
|
|
16
|
+
subType?: string;
|
|
17
|
+
};
|
|
18
|
+
export type AddTextOptions = {
|
|
19
|
+
id?: string;
|
|
20
|
+
name: string;
|
|
21
|
+
text: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
subType?: string;
|
|
24
|
+
};
|
|
25
|
+
export type AddStoredObjectOptions = {
|
|
26
|
+
id?: string;
|
|
27
|
+
name: string;
|
|
28
|
+
data: Record<string, any>;
|
|
29
|
+
description?: string;
|
|
30
|
+
subType?: string;
|
|
31
|
+
};
|
|
32
|
+
export type StoredImageMetadata = {
|
|
33
|
+
type: "image";
|
|
34
|
+
} & Omit<AddImageOptions, "id" | "url">;
|
|
35
|
+
export type StoredObjectDataTableMetadata = {
|
|
36
|
+
type: "dataTable";
|
|
37
|
+
} & Omit<AddDataTableOptions, "id" | "rows">;
|
|
38
|
+
export type StoredTextMetadata = {
|
|
39
|
+
type: "text";
|
|
40
|
+
} & Omit<AddTextOptions, "id" | "text">;
|
|
41
|
+
export type StoredObjectItemMetadata = {
|
|
42
|
+
type: "object";
|
|
43
|
+
keys: string[];
|
|
44
|
+
} & Omit<AddStoredObjectOptions, "id" | "data">;
|
|
45
|
+
export type StoredMetadataItem = StoredImageMetadata | StoredObjectDataTableMetadata | StoredTextMetadata | StoredObjectItemMetadata;
|
|
46
|
+
export type StoredMetadataItems = Record<string, StoredMetadataItem>;
|
|
47
|
+
export type StoredObjectType = "simulation-recording" | "untyped";
|
|
48
|
+
export type StoredObjectMetadata = {
|
|
49
|
+
version: 1;
|
|
50
|
+
type: StoredObjectType;
|
|
51
|
+
subType?: string;
|
|
52
|
+
items: StoredMetadataItems;
|
|
53
|
+
name?: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
};
|
|
56
|
+
export type StoredObjectData = Record<string, any>;
|
|
57
|
+
export type StoredObjectOptions = {
|
|
58
|
+
id?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
type?: StoredObjectType;
|
|
62
|
+
subType?: string;
|
|
63
|
+
};
|
|
64
|
+
export declare class StoredObject {
|
|
65
|
+
id: string;
|
|
66
|
+
metadata: StoredObjectMetadata;
|
|
67
|
+
data: StoredObjectData;
|
|
68
|
+
constructor(options?: StoredObjectOptions);
|
|
69
|
+
static FromParts(id: string, metadata: StoredObjectMetadata, data: StoredObjectData): StoredObject;
|
|
70
|
+
addImage(options: AddImageOptions): void;
|
|
71
|
+
addDataTable(options: AddDataTableOptions): void;
|
|
72
|
+
addText(options: AddTextOptions): void;
|
|
73
|
+
addObject(options: AddStoredObjectOptions): void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoredObject = void 0;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
5
|
+
class StoredObject {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.id = options?.id || (0, nanoid_1.nanoid)();
|
|
8
|
+
this.metadata = {
|
|
9
|
+
version: 1,
|
|
10
|
+
type: options?.type || "untyped",
|
|
11
|
+
items: {},
|
|
12
|
+
};
|
|
13
|
+
if (options?.name !== undefined) {
|
|
14
|
+
this.metadata.name = options.name;
|
|
15
|
+
}
|
|
16
|
+
if (options?.description !== undefined) {
|
|
17
|
+
this.metadata.description = options.description;
|
|
18
|
+
}
|
|
19
|
+
if (options?.subType !== undefined) {
|
|
20
|
+
this.metadata.subType = options.subType;
|
|
21
|
+
}
|
|
22
|
+
this.data = {};
|
|
23
|
+
}
|
|
24
|
+
static FromParts(id, metadata, data) {
|
|
25
|
+
const typedObject = new StoredObject({ id });
|
|
26
|
+
typedObject.metadata = metadata;
|
|
27
|
+
typedObject.data = data;
|
|
28
|
+
return typedObject;
|
|
29
|
+
}
|
|
30
|
+
addImage(options) {
|
|
31
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
32
|
+
this.metadata.items[id] = {
|
|
33
|
+
type: "image",
|
|
34
|
+
name: options.name
|
|
35
|
+
};
|
|
36
|
+
if (options.subType !== undefined) {
|
|
37
|
+
this.metadata.items[id].subType = options.subType;
|
|
38
|
+
}
|
|
39
|
+
if (options.width !== undefined) {
|
|
40
|
+
this.metadata.items[id].width = options.width;
|
|
41
|
+
}
|
|
42
|
+
if (options.height !== undefined) {
|
|
43
|
+
this.metadata.items[id].height = options.height;
|
|
44
|
+
}
|
|
45
|
+
if (options.description !== undefined) {
|
|
46
|
+
this.metadata.items[id].description = options.description;
|
|
47
|
+
}
|
|
48
|
+
this.data[id] = {
|
|
49
|
+
url: options.url
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
addDataTable(options) {
|
|
53
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
54
|
+
this.metadata.items[id] = {
|
|
55
|
+
type: "dataTable",
|
|
56
|
+
name: options.name,
|
|
57
|
+
cols: options.cols,
|
|
58
|
+
};
|
|
59
|
+
if (options.subType !== undefined) {
|
|
60
|
+
this.metadata.items[id].subType = options.subType;
|
|
61
|
+
}
|
|
62
|
+
if (options.description !== undefined) {
|
|
63
|
+
this.metadata.items[id].description = options.description;
|
|
64
|
+
}
|
|
65
|
+
this.data[id] = {
|
|
66
|
+
rows: options.rows
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
addText(options) {
|
|
70
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
71
|
+
this.metadata.items[id] = {
|
|
72
|
+
type: "text",
|
|
73
|
+
name: options.name,
|
|
74
|
+
};
|
|
75
|
+
if (options.subType !== undefined) {
|
|
76
|
+
this.metadata.items[id].subType = options.subType;
|
|
77
|
+
}
|
|
78
|
+
if (options.description !== undefined) {
|
|
79
|
+
this.metadata.items[id].description = options.description;
|
|
80
|
+
}
|
|
81
|
+
this.data[id] = {
|
|
82
|
+
text: options.text
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
addObject(options) {
|
|
86
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
87
|
+
this.metadata.items[id] = {
|
|
88
|
+
type: "object",
|
|
89
|
+
name: options.name,
|
|
90
|
+
keys: Object.keys(options.data),
|
|
91
|
+
};
|
|
92
|
+
if (options.subType !== undefined) {
|
|
93
|
+
this.metadata.items[id].subType = options.subType;
|
|
94
|
+
}
|
|
95
|
+
if (options.description !== undefined) {
|
|
96
|
+
this.metadata.items[id].description = options.description;
|
|
97
|
+
}
|
|
98
|
+
this.data[id] = options.data;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.StoredObject = StoredObject;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StoredObject, StoredObjectMetadata, StoredObjectData } from './stored-object';
|
|
1
2
|
export interface DemoObjectStorageConfig {
|
|
2
3
|
version: 1;
|
|
3
4
|
type: "demo";
|
|
@@ -24,40 +25,27 @@ export interface FirebaseObjectStorageConfig {
|
|
|
24
25
|
questionId: string;
|
|
25
26
|
}
|
|
26
27
|
export type ObjectStorageConfig = DemoObjectStorageConfig | FirebaseObjectStorageConfig;
|
|
27
|
-
export interface AddOptions {
|
|
28
|
-
id?: string;
|
|
29
|
-
}
|
|
30
28
|
export interface IObjectStorage {
|
|
31
|
-
list(questionOrRefId: string): Promise<
|
|
29
|
+
list(questionOrRefId: string): Promise<StoredObjectMetadataWithId[]>;
|
|
32
30
|
monitor(questionOrRefId: string, callback: MonitorCallback): DemonitorFunction;
|
|
33
|
-
add(object: StoredObject
|
|
31
|
+
add(object: StoredObject): Promise<StoredObject>;
|
|
34
32
|
read(objectId: string): Promise<StoredObject | undefined>;
|
|
35
|
-
readMetadata(objectId: string): Promise<
|
|
36
|
-
readData(objectId: string): Promise<
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
export interface ObjectMetadata {
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
}
|
|
42
|
-
export interface ObjectData {
|
|
43
|
-
[key: string]: any;
|
|
44
|
-
}
|
|
45
|
-
export interface StoredObject {
|
|
46
|
-
metadata: ObjectMetadata;
|
|
47
|
-
data: ObjectData;
|
|
33
|
+
readMetadata(objectId: string): Promise<StoredObjectMetadata | undefined>;
|
|
34
|
+
readData(objectId: string): Promise<StoredObjectData | undefined>;
|
|
35
|
+
readDataItem(objectId: string, itemId: string): Promise<any | undefined>;
|
|
48
36
|
}
|
|
49
|
-
export interface
|
|
37
|
+
export interface StoredObjectMetadataWithId {
|
|
50
38
|
id: string;
|
|
51
|
-
metadata:
|
|
39
|
+
metadata: StoredObjectMetadata;
|
|
52
40
|
}
|
|
53
|
-
export interface
|
|
41
|
+
export interface StoredObjectDataWithId {
|
|
54
42
|
id: string;
|
|
55
|
-
data:
|
|
43
|
+
data: StoredObjectData;
|
|
56
44
|
}
|
|
57
|
-
export interface
|
|
45
|
+
export interface StoredObjectWithId {
|
|
58
46
|
id: string;
|
|
59
|
-
metadata:
|
|
60
|
-
data:
|
|
47
|
+
metadata: StoredObjectMetadata;
|
|
48
|
+
data: StoredObjectData;
|
|
61
49
|
}
|
|
62
|
-
export type MonitorCallback = (objects:
|
|
50
|
+
export type MonitorCallback = (objects: StoredObjectMetadataWithId[]) => void;
|
|
63
51
|
export type DemonitorFunction = () => void;
|