@concord-consortium/object-storage 1.0.0-pre.1 → 1.0.0-pre.3
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/dist/demo-object-storage.d.ts +7 -3
- package/dist/demo-object-storage.js +9 -3
- package/dist/firebase-object-storage.d.ts +7 -3
- package/dist/firebase-object-storage.js +11 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/typed-object.d.ts +70 -0
- package/dist/typed-object.js +92 -0
- package/dist/types.d.ts +5 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DemoObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
|
|
1
|
+
import { DemoObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction, AddOptions } from './types';
|
|
2
2
|
export declare class DemoObjectStorage implements IObjectStorage {
|
|
3
3
|
private config;
|
|
4
4
|
private objects;
|
|
@@ -36,9 +36,9 @@ export declare class DemoObjectStorage implements IObjectStorage {
|
|
|
36
36
|
monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
|
|
37
37
|
/**
|
|
38
38
|
* Adds both metadata and data documents for a new object
|
|
39
|
-
* Returns the generated object ID (nanoid)
|
|
39
|
+
* Returns the generated object ID (nanoid) or the provided ID if specified in options
|
|
40
40
|
*/
|
|
41
|
-
add(object: StoredObject): Promise<string>;
|
|
41
|
+
add(object: StoredObject, options?: AddOptions): Promise<string>;
|
|
42
42
|
/**
|
|
43
43
|
* Reads both metadata and data documents for an object
|
|
44
44
|
* Returns undefined if the object is not found
|
|
@@ -54,6 +54,10 @@ export declare class DemoObjectStorage implements IObjectStorage {
|
|
|
54
54
|
* Returns undefined if the object is not found
|
|
55
55
|
*/
|
|
56
56
|
readData(objectId: string): Promise<ObjectData | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Generates a new unique ID using nanoid
|
|
59
|
+
*/
|
|
60
|
+
genId(): string;
|
|
57
61
|
/**
|
|
58
62
|
* Notifies all active monitors of changes
|
|
59
63
|
*/
|
|
@@ -91,10 +91,10 @@ class DemoObjectStorage {
|
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Adds both metadata and data documents for a new object
|
|
94
|
-
* Returns the generated object ID (nanoid)
|
|
94
|
+
* Returns the generated object ID (nanoid) or the provided ID if specified in options
|
|
95
95
|
*/
|
|
96
|
-
async add(object) {
|
|
97
|
-
const id = (0, nanoid_1.nanoid)();
|
|
96
|
+
async add(object, options) {
|
|
97
|
+
const id = options?.id ?? (0, nanoid_1.nanoid)();
|
|
98
98
|
const objectWithId = {
|
|
99
99
|
id,
|
|
100
100
|
metadata: object.metadata,
|
|
@@ -141,6 +141,12 @@ class DemoObjectStorage {
|
|
|
141
141
|
}
|
|
142
142
|
return obj.data;
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Generates a new unique ID using nanoid
|
|
146
|
+
*/
|
|
147
|
+
genId() {
|
|
148
|
+
return (0, nanoid_1.nanoid)();
|
|
149
|
+
}
|
|
144
150
|
/**
|
|
145
151
|
* Notifies all active monitors of changes
|
|
146
152
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FirebaseObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
|
|
1
|
+
import { FirebaseObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction, AddOptions } from './types';
|
|
2
2
|
export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
3
3
|
private config;
|
|
4
4
|
constructor(config: FirebaseObjectStorageConfig);
|
|
@@ -34,9 +34,9 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
34
34
|
monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
|
|
35
35
|
/**
|
|
36
36
|
* Adds both metadata and data documents for a new object
|
|
37
|
-
* Returns the generated object ID (nanoid)
|
|
37
|
+
* Returns the generated object ID (nanoid) or the provided ID if specified in options
|
|
38
38
|
*/
|
|
39
|
-
add(object: StoredObject): Promise<string>;
|
|
39
|
+
add(object: StoredObject, options?: AddOptions): Promise<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Reads both metadata and data documents for an object
|
|
42
42
|
*/
|
|
@@ -49,4 +49,8 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
|
|
|
49
49
|
* Reads only the data document for an object
|
|
50
50
|
*/
|
|
51
51
|
readData(objectId: string): Promise<ObjectData | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Generates a new unique ID using nanoid
|
|
54
|
+
*/
|
|
55
|
+
genId(): string;
|
|
52
56
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FirebaseObjectStorage = void 0;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
4
5
|
class FirebaseObjectStorage {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
if (config.version !== 1) {
|
|
@@ -67,13 +68,13 @@ class FirebaseObjectStorage {
|
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Adds both metadata and data documents for a new object
|
|
70
|
-
* Returns the generated object ID (nanoid)
|
|
71
|
+
* Returns the generated object ID (nanoid) or the provided ID if specified in options
|
|
71
72
|
*/
|
|
72
|
-
async add(object) {
|
|
73
|
-
// TODO: Generate nanoid
|
|
73
|
+
async add(object, options) {
|
|
74
|
+
// TODO: Generate nanoid if not provided in options
|
|
74
75
|
// TODO: Add metadata document to Firebase
|
|
75
76
|
// TODO: Add data document to Firebase
|
|
76
|
-
const newObjectId = 'placeholder-id';
|
|
77
|
+
const newObjectId = options?.id ?? 'placeholder-id';
|
|
77
78
|
return newObjectId;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
@@ -101,5 +102,11 @@ class FirebaseObjectStorage {
|
|
|
101
102
|
// TODO: Read data document from Firebase
|
|
102
103
|
return {};
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Generates a new unique ID using nanoid
|
|
107
|
+
*/
|
|
108
|
+
genId() {
|
|
109
|
+
return (0, nanoid_1.nanoid)();
|
|
110
|
+
}
|
|
104
111
|
}
|
|
105
112
|
exports.FirebaseObjectStorage = FirebaseObjectStorage;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { FirebaseObjectStorage } from './firebase-object-storage';
|
|
|
3
3
|
export { createObjectStorage } from './object-storage';
|
|
4
4
|
export { ObjectStorageProvider, useObjectStorage } from './object-storage-context';
|
|
5
5
|
export { IObjectStorage, ObjectStorageConfig, DemoObjectStorageConfig, FirebaseObjectStorageConfig, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
|
|
6
|
+
export * from './typed-object';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.useObjectStorage = exports.ObjectStorageProvider = exports.createObjectStorage = exports.FirebaseObjectStorage = exports.DemoObjectStorage = void 0;
|
|
4
18
|
var demo_object_storage_1 = require("./demo-object-storage");
|
|
@@ -10,3 +24,4 @@ Object.defineProperty(exports, "createObjectStorage", { enumerable: true, get: f
|
|
|
10
24
|
var object_storage_context_1 = require("./object-storage-context");
|
|
11
25
|
Object.defineProperty(exports, "ObjectStorageProvider", { enumerable: true, get: function () { return object_storage_context_1.ObjectStorageProvider; } });
|
|
12
26
|
Object.defineProperty(exports, "useObjectStorage", { enumerable: true, get: function () { return object_storage_context_1.useObjectStorage; } });
|
|
27
|
+
__exportStar(require("./typed-object"), exports);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { StoredObject } from "./types";
|
|
2
|
+
export type AddImageOptions = {
|
|
3
|
+
id?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
description?: string;
|
|
9
|
+
subType?: string;
|
|
10
|
+
};
|
|
11
|
+
export type AddDataTableOptions = {
|
|
12
|
+
id?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
cols: string[];
|
|
15
|
+
rows: any[][];
|
|
16
|
+
description?: string;
|
|
17
|
+
subType?: string;
|
|
18
|
+
};
|
|
19
|
+
export type AddTypedTextOptions = {
|
|
20
|
+
id?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
text: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
subType?: string;
|
|
25
|
+
};
|
|
26
|
+
export type AddTypedObjectOptions = {
|
|
27
|
+
id?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
data: Record<string, any>;
|
|
30
|
+
description?: string;
|
|
31
|
+
subType?: string;
|
|
32
|
+
};
|
|
33
|
+
export type TypedImageMetadata = {
|
|
34
|
+
type: "image";
|
|
35
|
+
} & Omit<AddImageOptions, "id" | "url">;
|
|
36
|
+
export type TypedDataTableMetadata = {
|
|
37
|
+
type: "dataTable";
|
|
38
|
+
} & Omit<AddDataTableOptions, "id" | "rows">;
|
|
39
|
+
export type TypedTextMetadata = {
|
|
40
|
+
type: "text";
|
|
41
|
+
} & Omit<AddTypedTextOptions, "id" | "text">;
|
|
42
|
+
export type TypedObjectMetadata = {
|
|
43
|
+
type: "object";
|
|
44
|
+
keys: string[];
|
|
45
|
+
} & Omit<AddTypedObjectOptions, "id" | "data">;
|
|
46
|
+
export type TypedMetadataItem = TypedImageMetadata | TypedDataTableMetadata | TypedTextMetadata | TypedObjectMetadata;
|
|
47
|
+
export type TypedMetadataItems = Record<string, TypedMetadataItem>;
|
|
48
|
+
export type TypedMetadata = {
|
|
49
|
+
version: 1;
|
|
50
|
+
type: "typed";
|
|
51
|
+
items: TypedMetadataItems;
|
|
52
|
+
name?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
};
|
|
55
|
+
export type TypedData = Record<string, any>;
|
|
56
|
+
export type TypedObjectOptions = {
|
|
57
|
+
id?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
};
|
|
61
|
+
export declare class TypedObject implements StoredObject {
|
|
62
|
+
id: string;
|
|
63
|
+
metadata: TypedMetadata;
|
|
64
|
+
data: TypedData;
|
|
65
|
+
constructor(options?: TypedObjectOptions);
|
|
66
|
+
addImage(options: AddImageOptions): void;
|
|
67
|
+
addDataTable(options: AddDataTableOptions): void;
|
|
68
|
+
addText(options: AddTypedTextOptions): void;
|
|
69
|
+
addObject(options: AddTypedObjectOptions): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedObject = void 0;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
5
|
+
class TypedObject {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.id = options?.id || (0, nanoid_1.nanoid)();
|
|
8
|
+
this.metadata = {
|
|
9
|
+
version: 1,
|
|
10
|
+
type: "typed",
|
|
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
|
+
this.data = {};
|
|
20
|
+
}
|
|
21
|
+
addImage(options) {
|
|
22
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
23
|
+
this.metadata.items[id] = {
|
|
24
|
+
type: "image",
|
|
25
|
+
name: options.name
|
|
26
|
+
};
|
|
27
|
+
if (options.subType !== undefined) {
|
|
28
|
+
this.metadata.items[id].subType = options.subType;
|
|
29
|
+
}
|
|
30
|
+
if (options.width !== undefined) {
|
|
31
|
+
this.metadata.items[id].width = options.width;
|
|
32
|
+
}
|
|
33
|
+
if (options.height !== undefined) {
|
|
34
|
+
this.metadata.items[id].height = options.height;
|
|
35
|
+
}
|
|
36
|
+
if (options.description !== undefined) {
|
|
37
|
+
this.metadata.items[id].description = options.description;
|
|
38
|
+
}
|
|
39
|
+
this.data[id] = {
|
|
40
|
+
url: options.url
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
addDataTable(options) {
|
|
44
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
45
|
+
this.metadata.items[id] = {
|
|
46
|
+
type: "dataTable",
|
|
47
|
+
name: options.name,
|
|
48
|
+
cols: options.cols,
|
|
49
|
+
};
|
|
50
|
+
if (options.subType !== undefined) {
|
|
51
|
+
this.metadata.items[id].subType = options.subType;
|
|
52
|
+
}
|
|
53
|
+
if (options.description !== undefined) {
|
|
54
|
+
this.metadata.items[id].description = options.description;
|
|
55
|
+
}
|
|
56
|
+
this.data[id] = {
|
|
57
|
+
rows: options.rows
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
addText(options) {
|
|
61
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
62
|
+
this.metadata.items[id] = {
|
|
63
|
+
type: "text",
|
|
64
|
+
name: options.name,
|
|
65
|
+
};
|
|
66
|
+
if (options.subType !== undefined) {
|
|
67
|
+
this.metadata.items[id].subType = options.subType;
|
|
68
|
+
}
|
|
69
|
+
if (options.description !== undefined) {
|
|
70
|
+
this.metadata.items[id].description = options.description;
|
|
71
|
+
}
|
|
72
|
+
this.data[id] = {
|
|
73
|
+
text: options.text
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
addObject(options) {
|
|
77
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
78
|
+
this.metadata.items[id] = {
|
|
79
|
+
type: "object",
|
|
80
|
+
name: options.name,
|
|
81
|
+
keys: Object.keys(options.data),
|
|
82
|
+
};
|
|
83
|
+
if (options.subType !== undefined) {
|
|
84
|
+
this.metadata.items[id].subType = options.subType;
|
|
85
|
+
}
|
|
86
|
+
if (options.description !== undefined) {
|
|
87
|
+
this.metadata.items[id].description = options.description;
|
|
88
|
+
}
|
|
89
|
+
this.data[id] = options.data;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.TypedObject = TypedObject;
|
package/dist/types.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface FirebaseObjectStorageConfig {
|
|
|
7
7
|
version: 1;
|
|
8
8
|
}
|
|
9
9
|
export type ObjectStorageConfig = DemoObjectStorageConfig | FirebaseObjectStorageConfig;
|
|
10
|
+
export interface AddOptions {
|
|
11
|
+
id?: string;
|
|
12
|
+
}
|
|
10
13
|
export interface IObjectStorage {
|
|
11
14
|
listMine(): Promise<ObjectWithId[]>;
|
|
12
15
|
listLinked(): Promise<ObjectWithId[]>;
|
|
@@ -14,10 +17,11 @@ export interface IObjectStorage {
|
|
|
14
17
|
monitorMine(callback: MonitorCallback): DemonitorFunction;
|
|
15
18
|
monitorLinked(callback: MonitorCallback): DemonitorFunction;
|
|
16
19
|
monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
|
|
17
|
-
add(object: StoredObject): Promise<string>;
|
|
20
|
+
add(object: StoredObject, options?: AddOptions): Promise<string>;
|
|
18
21
|
read(objectId: string): Promise<StoredObject | undefined>;
|
|
19
22
|
readMetadata(objectId: string): Promise<ObjectMetadata | undefined>;
|
|
20
23
|
readData(objectId: string): Promise<ObjectData | undefined>;
|
|
24
|
+
genId(): string;
|
|
21
25
|
}
|
|
22
26
|
export interface ObjectMetadata {
|
|
23
27
|
[key: string]: any;
|